我正在使用 Stripe 并创建了一个 custom checkout ,根据该页面:
var handler = StripeCheckout.configure({
key: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
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: 'some name',
description: '2 widgets',
currency: 'aud',
amount: 2000
});
e.preventDefault();
});
// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});
但是我想知道是否有任何方法可以更新传递给 open
的配置选项,因为当用户进行更改时我需要更新amount
。
...或者我最好的选择只是重新启动全部或部分?
虽然此代码是用普通 JavaScript 编写的,但我已将其更改为 jQuery,因此首选 jQuery 解决方案。
最佳答案
最简单的方法是在变量中定义简单的金额,然后当您在页面上执行更改价格的操作时修改该变量的值。
// define an amount, you could always modify this later
var myAmount = 2000;
// when the submit button is clicked
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'some name',
description: '2 widgets',
currency: 'aud',
amount: myAmount
});
e.preventDefault();
});
您可能会觉得有趣的一个例子,http://jsfiddle.net/ns2fezag/
关于javascript - 可以使用自定义结帐更新 Stripe 中的配置选项吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52028338/