如何使用简单表单和JS检查条纹事务的响应


how to check response of stripe transaction using simple form and js

我正在尝试设置条纹结帐,我可以很好地启动并运行付款表单,但是只有在付款成功后,我才需要将用户重定向到另一个页面。这是我用来显示表单和处理表单的 javascript,但我需要知道如何以及在哪里可以添加重定向代码?

<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton" style="border: none" ><img src="/orange_pay_now.png" style="width: 265px;height: 66px;"></button>
<script>
    var handler = StripeCheckout.configure({
        key: 'pk_test_..............',
        image: '/orange_pay_now.png',
        token: function(token) {
            // Use the token to create the charge with a server-side script.
            // You can access the token ID with `token.id`
        }
    });
    document.getElementById('customButton').addEventListener('click', function(e) {
        // Open Checkout with further options
        handler.open({
            name: 'Name of Product',
            description: 'description goes here',
            amount: 800,
            currency: 'GBP'
        });
        e.preventDefault();
    });
    // Close Checkout on page navigation
    window.addEventListener('popstate', function() {
        handler.close();
    });
</script>

我将非常感谢任何帮助。

结帐应在该页面上另一个表单的上下文中创建(请参阅简单集成):

https://stripe.com/docs/checkout

当 Checkout 完成其操作时,它会自动将其他表单提交到您使用的任何action属性。然后,您可以使用服务器端代码来处理实际费用请求。

如果您使用的是自定义集成,则需要向令牌函数添加代码以提交表单或重定向浏览器或其他任何内容。

希望有帮助,拉里

PS 我在 Stripe 从事支持工作。