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

标签 javascript jquery stripe-payments

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

相关文章:

javascript - 基于评级的搜索过滤器

jquery - jqPlot 日期轴 - 在错误的日期绘制条形图?

python - Django-stripe 集成在付款后给出 403 Forbidden

javascript - 删除浏览器页面底部链接的目标 URL

javascript - 具有恢复支持的 Node.js 请求流

javascript - 在 D3.js 树布局中为每个节点单独指定 nodeSize

javascript - 双击获取id

javascript - jQuery如何计算实际屏幕距离?

javascript - Stripe 自定义排版字体

ruby-on-rails - rails 应用程序中的 Stripe success_url 格式未创建正确的 URL