lip*_*nco 12 javascript jquery stripe-payments
我有设置自定义金额的问题,我想将数据量设置为输入id ="custom-donation-amount"中的任何用户,我应该怎么做.我的尝试不起作用.
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-image="images/button.png"
data-key="pk_test_FTZOOu9FL0iYJXXXXXX"
data-name="Fund"
data-label= "DONATE"
data-description="ysysys"
data-amount =
>
$('.donate-button').click(function(event){
var self = $(this);
var amount = 0;
amount = $('#custom-donation-amount').val();
if (amount === "") {
amount = 50;
}
amount = self.attr('data-amount');
amount = Math.abs(amount * 100);
});
</script>
<input type="number" id="custom-donation-amount" placeholder="50.00" min="0" step="10.00"/>
Run Code Online (Sandbox Code Playgroud)
met*_*ous 14
使用的特定方法(简单的嵌入形式)将不适用于所寻求的目的.您必须使用更灵活的自定义集成,如文档中所示.所提供的示例中唯一没有包含的是如何连接金额输入,这一点都不困难.
<input class="form-control"
type="number"
id="custom-donation-amount"
placeholder="50.00"
min="0"
step="10.00"/>
<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton ">Purchase</button>
<script>
var handler = StripeCheckout.configure({
key: 'pk_test_ppailxxxxxxxxxxxxxxxxxxx',
image: '/square-image.png',
token: function(token) {
// Use the token to create the charge with a server-side script.
// You can access the token ID with `token.id`
}
});
document.getElementById('customButton').addEventListener('click', function(e) {
// This line is the only real modification...
var amount = $("#custom-donation-amount").val() * 100;
handler.open({
name: 'Demo Site',
description: 'Some donation',
// ... aside from this line where we use the value.
amount: amount
});
e.preventDefault();
});
</script>
Run Code Online (Sandbox Code Playgroud)
请注意,您实际上必须填写token:传递给StripeCheckout.configure调用的函数.特别是,您需要提交表单或ajax请求,并在服务器上相应地处理.然后,您将在服务器上使用此信息以及密钥,向Stripe发送付款创建请求.条纹文件对需要什么样的信息发送到他们的API调用,因此,你需要沿着对API调用传递什么样的信息细节你的服务器.特别要注意的是,您可能需要在token函数中额外获取价格等.
为此,您需要另一个脚本标记,您不能在具有源的脚本标记中使用 javascript。
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-image="images/button.png" data-key="pk_test_FTZOOu9FL0iYJXXXXXX" data-name="Fund" data-label="DONATE" data-description="ysysys" data-amount="0"></script>
<script type="text/javascript">
$(function() {
$('.donate-button').click(function(event) {
var amount = $('#custom-donation-amount').val();
$('.stripe-button').attr('data-amount', amount)
});
});
</script>
<input type="number" id="custom-donation-amount" placeholder="50.00" min="0" step="10.00 " />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10797 次 |
| 最近记录: |