我正在使用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>发布于 2020-07-30 03:34:51
我已经做到了这一点,但没有打破账单。我将最终的价格“金额”作为价格乘以数量,并在我的数据库中,我保存了账单的所有细节。这是我使用的javascript代码:
amount: {
value: "<?= $_SESSION['price'] * $_SESSION['quantity'] ?>" ,
currency_code: 'EUR'
},你可以使用Javascript而不是像这样的服务器代码,
amount: {
value: document.getElementById("quantity").value * document.getElementById("price").value ,
currency_code: 'EUR'
},在这两个代码中,应该在呈现按钮之前设置这些值,这意味着在加载页面之前。
发布于 2019-07-30 15:25:29
在客户机上实现quantity字段。您必须细分amount字段,然后在采购单位中添加"item_total“和"items”字段。
供您参考:
createOrder: function(data, actions) {
console.log(data);
console.log(actions);
return actions.order.create({
purchase_units: [{
amount: {
value: (<HTMLInputElement>document.getElementById("number1")).value,
breakdown: {
item_total:{
"currency_code": "EUR",
value: (<HTMLInputElement>document.getElementById("number1")).value,
},
tax_total: {
"currency_code": "EUR",
"value": "00.00"
},
}
},
items: [
{
"name": "",
"description": ".......",
"sku": "sku01",
"unit_amount": {
"currency_code": "EUR",
"value": "20.00"
},
"quantity": (<HTMLInputElement>document.getElementById("number")).value,
}]
}],https://stackoverflow.com/questions/56633131
复制相似问题