如何从一开始就禁用条带按钮并在检查协议后启用它?

时间:2016-05-01 19:04:33

标签: stripe-payments

我想从头开始禁用条带检出按钮。然后当一个人检查协议复选框时,它将被启用。如果他撤消了他的检查,它将再次被禁用。我怎么能这样做?

<script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="pk_test_6pRNASCoBOKtIshFeQd4XMUh"
    data-amount="2000"
    data-name="Stripe.com"
    data-description="2 widgets"
    data-image="/img/documentation/checkout/marketplace.png"
    data-locale="auto">
</script>

我的代码与上面的代码非常相似。只有价值不同。

1 个答案:

答案 0 :(得分:1)

您可以使用自定义按钮代替自动嵌入结帐按钮。以下是the docs.

的修改示例

$('#agree').click(function() {
    $("#customButton").toggle(this.checked);
});

 var handler = StripeCheckout.configure({
    key: 'pk_test_6pRNASCoBOKtIshFeQd4XMUh',
    image: '/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.
    }
  });
  $('#customButton').on('click', function(e) {
    // Open Checkout with further options:
    handler.open({
      name: 'Stripe.com',
      description: '2 widgets',
      amount: 2000
    });
    e.preventDefault();
  });

  // Close Checkout on page navigation:
  $(window).on('popstate', function() {
    handler.close();
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://checkout.stripe.com/checkout.js"></script>

<input type="checkbox" id="agree"> agree
<button id="customButton" style="display:none">Purchase</button>