Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)?

like image 902
Mike Marshall Avatar asked Jan 29 '14 20:01

Mike Marshall


3 Answers

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)
like image 63
ncubica Avatar answered Oct 04 '22 21:10

ncubica


Simplest way that I have found is just to set a submit variable that's tested.

    var submittedForm = false;

    var handler = StripeCheckout.configure({
        key: '{{ stripe.public_key }}',
        allowRememberMe: false,
        token: function(response, extradata) {
            var token = response.id;
            var card = response.card.id;
            submittedForm = true;
            $('#submit-text').html('Processing, stand by');
         //etc functionality to submit back to your own form
            }
    });



    //when actually triggering checkout.js
    handler.open({
                name: 'myCompanyName',
                amount: 1999,
     closed: function () {
                    if(submittedForm == false)
                        $('#submit-text').html('Start your Trial');
                }
           }
    });

This example changes the Submit button text when bringing up checkout.js. If it actually processes, so we get a token back, set submitted to true. The closed tests this. If it's false, it means they clicked X without submit, so we set the submit text back. If true, ignore so "Processing" remains while our own ajax post or whatever finishes.

like image 42
Kris White Avatar answered Oct 04 '22 22:10

Kris White


(I work on Stripe Checkout)

The 'closed' callback is only available in the custom integration.

like image 24
user3250670 Avatar answered Oct 04 '22 23:10

user3250670