Reputation: 540
I have the following code on my website.
My problem is, the user hits "Pay with Google" button to trigger the code below. This shows the Google Pay popup (which is loaded from the loadPaymentData()).
If the user proceeds with the payment, then everything works great.
If the user clicks on the back button within the popup, then this is seen as an error and drops into the catch(function(err)) below. This paymentData or payload is not logged in the console. This is obviously not an error - the user just wants to select a different payment method.
How do I catch if the user has hit the back button within the popup?
paymentsClient.loadPaymentData(paymentDataRequest)
.then(function (paymentData) {
console.log("paymentData", paymentData);
// TODO
}).then(function (payload) {
console.log("payload", payload);
// Send result nonce to server
}).catch(function (err) {
console.log('pay error', err);
});
Upvotes: 2
Views: 939
Reputation: 7780
You can check to see if the payment sheet was cancelled by inspecting err.statusCode === 'CANCELED'
.
See documentation: https://developers.google.com/pay/api/web/reference/client#errors_1
Upvotes: 1