在 Stripe / Checkout 中预填充电子邮件地址
Pre-populating an email address in Stripe / Checkout
我正在网站上使用 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 [=18= 中的变量预填充电子邮件地址值 (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>
data-email="email@example.com"
正如问题中提到的,现在有效。
我正在网站上使用 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 [=18= 中的变量预填充电子邮件地址值 (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>
data-email="email@example.com"
正如问题中提到的,现在有效。