简体   繁体   中英

stripe checkout, custom integration: how to detect abort?

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:
在此处输入图片说明

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.

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM