最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Pre-populating an email address in StripeCheckout - Stack Overflow

programmeradmin1浏览0评论

I am using Stripe / Checkout on a site in order to accept payments. Stripe is fairly simple to use this way, as they give the following script to embed in web pages:

<form id="monthly" action="/subscribe" method="POST">
  <script
    src=".js" class="stripe-button"
    data-key="pk_test_xxxxxxxxx"
    data-image=".png"
    data-name="My Website"
    data-description="Monthly Subscription"
    data-amount="6900"
    data-email="[email protected]"
    data-allow-remember-me=false
    data-label="Subscribe" >
  </script>
</form> 

What I would like to be able to do is pre-populate the email address value (data-email="[email protected]") with a variable that I have in my custom.js jQuery script. I am proficient with jQuery, but can I modify this embedded script with jQuery?

I am using Stripe / Checkout on a site in order to accept payments. Stripe is fairly simple to use this way, as they give the following script to embed in web pages:

<form id="monthly" action="/subscribe" method="POST">
  <script
    src="https://checkout.stripe./checkout.js" class="stripe-button"
    data-key="pk_test_xxxxxxxxx"
    data-image="http://mywebsite./assets/img/logo_raw.png"
    data-name="My Website"
    data-description="Monthly Subscription"
    data-amount="6900"
    data-email="[email protected]"
    data-allow-remember-me=false
    data-label="Subscribe" >
  </script>
</form> 

What I would like to be able to do is pre-populate the email address value (data-email="[email protected]") with a variable that I have in my custom.js jQuery script. I am proficient with jQuery, but can I modify this embedded script with jQuery?

Share Improve this question asked Jun 28, 2016 at 14:30 JoelJoel 1,6493 gold badges13 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You need to use the custom integration, and do something like this:

<script src="https://checkout.stripe./checkout.js"></script>

<button id="customButton">Purchase</button>

<script>
  var email = "[email protected]"; // or use jQuery to dynamically populate the variable

  var handler = StripeCheckout.configure({
    key: 'pk_test_...',
    image: 'https://stripe./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.',
      description: '2 widgets',
      amount: 2000,
      email: email
    });
    e.preventDefault();
  });

  // Close Checkout on page navigation:
  $(window).on('popstate', function() {
    handler.close();
  });
</script>
data-email="[email protected]"

as mentioned in the question, works nowadays.

发布评论

评论列表(0)

  1. 暂无评论