我在网站上使用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 =&#34; email@example.com")脚本。我精通jQuery,但是我可以用jQuery修改这个嵌入式脚本吗?
答案 0 :(得分:6)
您需要使用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>
答案 1 :(得分:0)