Stripe "Simple" Checkout - detect if close button is clicked

Mike Marshall picture Mike Marshall · Jan 29, 2014 · Viewed 11.4k times · Source

I've integrated Stripe Checkout into my site and everything works great except for one aspect. I use the 'Simple' checkout mode where Stripe renders my checkout button for me. But I see no way in the docs to detect if the user clicks the close button (effectively cancelling the transaction - see image).

enter image description here

Is there a way to detect this in 'Simple' mode (as opposed to Custom)?

Answer

ncubica picture ncubica · Oct 11, 2014

Well you cannot have a callback, but what about if you create your own callback when stripe remove the iframe from your DOM.

$(document).on("DOMNodeRemoved",".stripe_checkout_app", close);

function close(){
  alert("close stripe");
}

so while its true that the 'closed'callback its not available this little hack can help you.

//this example its with JQuery.

--- EDIT ---

As @artfulhacker commented another way to do it would be to use the a setInterval timer and check if the class .stripe_checkout_app is visible or not, could be something like:

setInterval(function(){
    if(!$('.stripe_checkout_app').is(":visible")){
       alert("Stripe modal is hidden");
    }
},1000)