【发布时间】:2019-04-16 16:22:23
【问题描述】:
我正在尝试集成 Stripe 的结帐功能。我正在使用https://checkout.stripe.com/checkout.js。
我在表单上有一个金额的输入框,我想将该输入框的值传递给 Stripe 的脚本。
<input id="amount" name="amount" type="text" class="form-control" placeholder="Enter amount" onKeyUp="calculate()" pattern="^[0-9]*$">
这是我的条纹脚本
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripedetails['publishable_key']; ?>"
data-amount="1000"//<-Amount here
data-name="KAEM Technologies USA, Inc"
data-email="<?php echo $email;?>"
data-currency="<?php echo $curr_code; ?>"
data-description="Widget"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto">
</script>
我尝试使用 COOKIES ,我尝试使用
var x = document.getElementById('amount').value;
<?php $amount = "<script>document.write(x)</script>";?>
那么如何在不提交表单的情况下将输入框的值传递给条带的脚本。
谢谢
@barmar 继承了我尝试过的代码:
<button type="submit" id="custombutton" class="btn btn-primary" ><i class="fa fa-cc-stripe"></i> Pay Via Card </button>
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
var handler = StripeCheckout.configure({
key: 'pk_test_DzL83GJnn9U4lMBuk311P1hK0026zJJrLW',
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.
}
});
document.getElementById('customButton').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'KAEM Technologies (USA), Inc.',
description: '2 widgets',
amount: 2000
});
e.preventDefault();
});
// Close Checkout on page navigation:
window.addEventListener('popstate', function() {
handler.close();
});
</script>
这样对吗?
【问题讨论】:
-
能否请您提供示例代码?
-
发送某种 http 请求。所以要么提交表单,要么提交 ajax,或者其他的东西。
标签: javascript php stripe-payments