Headless commerce and custom storefronts with Shopify APIs and SDKs
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:
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?
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By