Stripe 在表单完成时执行 Javascript [英] Stripe Execute Javascript On Form Complete

查看:27
本文介绍了Stripe 在表单完成时执行 Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我有一个用于 Stripe 的自定义"结帐按钮,我想知道如何在结帐过程成功后让它执行一段 JavaScript.我希望它将book-appointment-button"样式更改为block"而不是none"(我已经知道如何做到这一点).我只是在努力解决如何制作它,因此它会在结帐完成后触发所说的 JavaScript,如果有人可以帮忙,将不胜感激.提前致谢.

Here I have the "custom" checkout button for stripe, I was wondering how I make this execute a piece of JavaScript after the checkout process is successful. I would like it to change the "book-appointment-button" style to "block" instead of "none" (I already know how to do this). I am just struggling with how to make it so it triggers said JavaScript after the checkout has been completed if anyone can please help it would be greatly appreciated. Thanks in advance.

<!-- Start Of Stripe Payment -->
<script src="https://checkout.stripe.com/checkout.js"></script>

<button id="customButton">Purchase</button>

<script>
    var handler = StripeCheckout.configure({
        key: 'hidden',
        image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
        locale: 'auto',
        token: function(token) {
            // You can access the token ID with `token.id`.
            // Get the token ID to your server-side code for use.
        }
    });
    document.getElementById('customButton').addEventListener('click', function(e) {
        // Open Checkout with further options:
        handler.open({
            name: 'DenchCodeLTD',
            description: '2 widgets',
            zipCode: true,
            currency: 'gbp',
            amount: 2000
        });
        e.preventDefault();
    });
    // Close Checkout on page navigation:
    window.addEventListener('popstate', function() {
        handler.close();
    });
</script>

<!-- End Of Stripe Payment -->

<button id="book-appointment-submit" type="button" class="btn btn-success" style="display:none">
    <span class="glyphicon glyphicon-ok"></span>
    <?php echo (!$manage_mode) ? $this->lang->line('confirm') : $this->lang->line('update'); ?>
</button>

推荐答案

Stripe 将在结帐完成时运行 token 回调.

Stripe will run the token callback when the checkout is complete.

这在 Stripe 的 Checkout 中有记录,但它有点隐藏在配置选项中.无论如何,快乐编码:)

This is documented on Stripe's Checkout, but it is kinda hidden in the configuration options. Anyway, happy coding :)

这篇关于Stripe 在表单完成时执行 Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆