1

A followup to @mjmarsh's stripe question:

How can I detect if the stripe checkout payment process was aborted by the user (close button was clicked in the checkout widget)?

@mjmarsh telling screenshot:
enter image description here

As commented in the answer, the close callback is called no matter whether it was cancelled or successful.

There is the token callback, but I don't know how that info could be perused inside the close function, and how reliable that would be.

Community
  • 1
  • 1
Swiss Mister
  • 3,260
  • 2
  • 20
  • 42
  • There is no guaranteed order as far as I know and it seems to depend on browsers. What I usually do is add a setTimeout in the `close` callback and if `token` hasn't fired after a second I assume it was closed by the user. – koopajah Mar 30 '15 at 14:58

2 Answers2

0

Just in case, here's what I do at the moment:

  1. I declare a ok = false variable in the appropriate scope.
  2. I set it to true first thing inside the token callback.
  3. I check for the ok variable inside the close callback.

It seems to work - but I don't know if it will always work. It would be useful to get stripe to tell us if the one callback is always called after the other.

Swiss Mister
  • 3,260
  • 2
  • 20
  • 42
0

Here's what's to do, in pseudocode

  1. I declare a ok = false variable in the appropriate scope.
  2. I set it to true first thing inside the token callback.
  3. I check for the ok variable inside the close callback.

And here's some real code to copy and paste:

<script type='text/javascript'>
    var handler = StripeCheckout.configure({
        key: 'pk_xxxxxxx',
        isTokenGenerate: false,
        token: function (token) {
            handler.isTokenGenerate = true;

            //Add the stuff if required
        }
    });

    window.addEvent('domready', function () { 

        handler.open({
            name: 'Add Name',
            description: 'Add Description',
            amount: '1000',
            currency: 'USD',
            opened: function () {

            },
            closed: function () {
                if (!handler.isTokenGenerate) {

                }
            },
        });
    });
</script>
Swiss Mister
  • 3,260
  • 2
  • 20
  • 42