How to know if completed tokenized payment for Apple Pay was a success or failure after polling?

xanderbuck7
New Member
11 0 0

Question:

My question is how do I know if completing a tokenized payment for an Apple Pay payment was a success or failure after polling for payment.ready == true?

What I'm doing:

First I complete the checkout using the mutation checkoutCompleteWithTokenizedPaymentV3. To confirm this mutation was successful I check the following:

  1. Success block is fired
  2. checkoutUserErrors.count == 0
  3. Payment object is created and not nil (which signifies the async operation of payment has begun).

Second, I then poll on the payment object created for payment.ready == true.

From my understanding payment.ready == true doesn't signify a successful payment, it only signifies the async operation of the payment processing has finished.

From here how do I know if the payment was a success or failure once payment.ready == true?

Is it safe to do the following check to confirm if payment was successful or not?:

 

if payment.errorMessage == nil {
   //payment success
} else {
   /// payment failure
}

 

The sample app seems to fall short here and marks a success regardless of the error message given. The sample app has:

 

let retry = Graph.RetryHandler<Storefront.QueryRoot>(endurance: .finite(30)) { response, error -> Bool in
            error.debugPrint()
            
            if let payment = response?.node as? Storefront.Payment {
                print("Payment not ready yet, retrying...")
                return !payment.ready
            } else {
                return false
            }
        }
        
        let query = ClientQuery.queryForPayment(id)
        let task  = self.client.queryGraphWith(query, retryHandler: retry) { query, error in
            
            if let payment = query?.node as? Storefront.Payment {
                print("Payment error: \(payment.errorMessage ?? "none")")
                completion(payment.viewModel)
            } else {
                completion(nil)
            }
        }

 

 But what if there was an error? Why does it completely disregard the errorMessage?

0 Likes
xanderbuck7
New Member
11 0 0

Any thoughts on this @vix ?

0 Likes