Is there any way to trigger an event when the Stripe Checkout modal is closed?
There is about 0.5-1 second delay between the time that Stripe's modal closes and their response is delivered. In that time, a user might click away from the page etc. To address the issue, we can do something like disable all links or put an overlay ("cover-all") over the page that is removed only when Stripe is done processing.
The problem is that there is no way to close that overlay if the person decides to close the Stripe modal (instead of trying to process a payment). You can't target the modal (e.g. $('.stripe-app')) because of the same origin policy.
Any alternative ideas?
My code is below, adapted from https://stripe.com/docs/checkout.
// custom Stripe checkout button with custom overlay to avoid UI confusion during payment processing
$('.btn-stripe').click(function(){
var token = function(res){
var $input = $('<input type=hidden name=stripeToken />').val(res.id);
$('.form-stripe').append($input).submit();
};
StripeCheckout.open({
key: STRIPE_KEY,
address: false,
amount: STRIPE_AMT,
currency: 'usd',
name: 'Purchase',
description: STRIPE_DESC,
panelLabel: 'Checkout',
token: token
});
$('.cover-all').show();
return false;
});