gpt4 book ai didi

javascript - 使用自定义数量设置 strip

转载 作者:可可西里 更新时间:2023-11-01 02:04:16 24 4
gpt4 key购买 nike

我在设置自定义金额时遇到问题,我想将数据金额设置为用户在输入 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"/>

最佳答案

正在使用的特定方法(简单的嵌入式形式)不会达到所寻求的结果。您必须改用更灵活的自定义集成,如 in the docs 所示.提供的示例中唯一没有包括的是如何连接输入的金额,这一点也不难。

<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>

请注意,您实际上必须填写传递给 StripeCheckout.configure 调用的 token: 函数。特别是,您需要提交表单或 ajax 请求并在您的服务器上进行相应处理。然后,您将在服务器上使用此信息以及 key ,向 Stripe 发送付款创建请求。 Stripe 文档详细说明了需要将哪些信息发送到他们的 API 调用,以及您需要将哪些信息传递给服务器上的 API 调用。特别要注意的是,您可能需要在 token 函数中额外获取价格等。

关于javascript - 使用自定义数量设置 strip ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21086362/

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