我正在尝试设置stripe结帐,我可以很好地启动并运行付款表格,但是只有在付款成功后我才需要将用户重定向到另一个页面。这是我用来显示表单并处理它的 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
属性。然后您可以使用服务器端代码来处理实际的收费请求。
如果您使用自定义集成,则需要向 token 函数添加代码以提交表单或重定向浏览器或执行其他操作。
希望有帮助, 拉里
PS 我在 Stripe 从事支持工作。
关于javascript - 如何使用简单的表单和js检查 strip 交易的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27033836/