gpt4 book ai didi

javascript - 在 Stripe/Checkout 中预填充电子邮件地址

转载 作者:行者123 更新时间:2023-11-30 07:56:43 25 4
gpt4 key购买 nike

我正在使用 Stripe/Checkout在网站上接受付款。 Stripe 以这种方式使用起来相当简单,因为他们提供了以下脚本来嵌入网页:

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

我想做的是使用我在 custom.js jQuery 脚本中的变量预填充电子邮件地址值 (data-email="email@example.com")。我精通 jQuery,但我可以用 jQuery 修改这个嵌入式脚本吗?

最佳答案

您需要使用 custom integration ,然后做这样的事情:

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

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

<script>
var email = "customer@example.com"; // or use jQuery to dynamically populate the variable

var handler = StripeCheckout.configure({
key: 'pk_test_...',
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.
}
});

$('#customButton').on('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'Stripe.com',
description: '2 widgets',
amount: 2000,
email: email
});
e.preventDefault();
});

// Close Checkout on page navigation:
$(window).on('popstate', function() {
handler.close();
});
</script>

关于javascript - 在 Stripe/Checkout 中预填充电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38079040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com