【问题标题】:Possible to update config options in Stripe with custom checkout?可以使用自定义结帐更新 Stripe 中的配置选项吗?
【发布时间】:2019-02-01 08:15:32
【问题描述】:

我正在使用 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

...或者我最好的选择是重新启动它的全部或部分?

虽然这段代码是在 vanilla JavaScript 中,但我已将其更改为 jQuery,因此首选 jQuery 解决方案。

【问题讨论】:

    标签: javascript jquery stripe-payments


    【解决方案1】:

    执行此操作的最简单方法是在变量中定义简单的金额,然后在您在页面上执行更改价格的操作时修改该变量的值。

    // 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/

    【讨论】:

    • 啊,好主意。 :) 另外,感谢您的示例链接 - 这真的很酷!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-28
    • 1970-01-01
    相关资源
    最近更新 更多