条纹自定义结帐 - 表单提交

问题描述 投票:1回答:3

我正在尝试Stripe API和功能,但我围绕这一个问题 - 如何在(测试)付款成功后提交表单?

这是我目前的代码:

<script>
    var handler = StripeCheckout.configure({
        key: 'pk_test_mykey',
        image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
        locale: 'sv',
        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) {
        stripe_spots = document.getElementById("spots").value;
        stripe_total = (stripe_spots) * 70;
        // Open Checkout with further options:
        handler.open({
            name: 'Revy!',
            description: stripe_spots + " platser",
            zipCode: true,
            currency: 'sek',
            amount: stripe_total * 100
        });

        e.preventDefault();
     });

     // Close Checkout on page navigation:
     window.addEventListener('popstate', function() {
         handler.close();
     });
 </script>

我应该在何时何地提交表格?

谢谢!

php html forms stripe-payments
3个回答
2
投票

您使用令牌回调函数提交表单更新您的句柄,如此

var handler = StripeCheckout.configure({
key: 'pk_test_mykey',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'sv',
token: function (token) {
    $.ajax({
        type: 'POST',
        url: '/checkout.php',
        data: {stripeToken: token.id, stripeEmail: token.email},
        success: function (data) {
            //handle success response here
        },
        error: function(data){
            //handle error response here
        }
    });
   }
});

0
投票

检索Stripe TOKEN后,您应该将数据发送到服务器,包括TOKEN以进行Stripe Charge或创建订阅

Here is an example tutorial to create Customer for Subscription


0
投票

编辑我之前的答案,因为我已经有了它,所以我可以共享代码片段。 (当我发现这个时,我正在努力解决同样的问题。)

这是我的解决方案。有用。这假设您的下一页名为“PaymentComplete.php”。相应地编辑。

token: function(token) {
// You can access the token ID with `token.id`.
// Get the token ID to your server-side code for use.
var form = document.createElement("form");
var tokenPassed = document.createElement("input");
form.method = "POST";
form.action = "PaymentComplete.php";
tokenPassed.value = token.id;
tokenPassed.name = "token";
form.appendChild(tokenPassed);
document.body.appendChild(form);
form.submit();
}

可能有更好的方法,但这对我有用。

资料来源:creating and submitting a form with javascript

© www.soinside.com 2019 - 2024. All rights reserved.