gpt4 book ai didi

PayPal 智能支付按钮 - 请求数量

转载 作者:太空宇宙 更新时间:2023-11-03 16:12:32 25 4
gpt4 key购买 nike

我正在使用 PayPal 智能支付按钮在我的网站上销售单件商品,但我在任何文档中都找不到如何询问数量。

这甚至可以通过智能支付按钮 API 来实现吗?

我只想让客户能够更改他们希望购买的商品的数量。我不介意它是在表格中还是在 PayPal 的结帐阶段。

到目前为止,这是我的代码,它非常标准,因为我试图保持简单:

<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
style: {
size: 'responsive',
shape: 'pill',
label: 'checkout',
},
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '8.99'
}
}]
});
},

// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}


}).render('#paypal-button-container');
</script>

最佳答案

我已经这样做了,但没有打破账单。我将最终价格设为“金额”,即价格乘以数量,并且在我的数据库中保存了账单的所有详细信息。这是我使用的 javascript 代码:

 amount: {
value: "<?= $_SESSION['price'] * $_SESSION['quantity'] ?>" ,
currency_code: 'EUR'
},

您可以使用 Javascript 而不是像这样的服务器代码,

amount: {
value: document.getElementById("quantity").value * document.getElementById("price").value ,
currency_code: 'EUR'
},

在这两个代码中,应该在呈现按钮之前设置值,这意味着在加载页面之前。

关于PayPal 智能支付按钮 - 请求数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56633131/

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