繁体   English   中英

可以使用自定义结帐更新Stripe中的配置选项吗?

[英]Possible to update config options in Stripe with custom checkout?

我正在使用Stripe并根据该页面创建了一个自定义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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM