我有以下 JavaScript 在我的网站上加载 PayPal 按钮,我需要更改此代码,以便添加到购物车中的商品也出现在 PayPal 发票中:
<script src="cart.js"></script>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: countCartTotal()
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
window.location.href = "orderConfirmed.php"
clearCart()
});
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
</script>
它加载在我的网页底部,“cart.js”保存整个购物车的价值,例如,如果总金额为 20.00 美元,则用户将在 PayPal 窗口中被收取 20.00 美元。我已经在 PayPal 的沙盒环境中测试了这段代码,它可以工作。但它没有给我购物车中的物品。
我从这里的用户那里得到了以下代码:
"purchase_units": [{
"description": "Stuff",
"amount": {
"value": "20.00",
"currency_code": "USD",
"breakdown": {
"item_total": {
"currency_code": "USD",
"value": "20.00"
},
}
},
"items": [
{
"unit_amount": {
"currency_code": "USD",
"value": "10.00"
},
"quantity": "1",
"name": "Item 1",
},
{
"unit_amount": {
"currency_code": "USD",
"value": "10.00"
},
"quantity": "1",
"name": "Item 2",
},
],
}
]
另外,当我添加到countCartTotal()两个“值:”时它会停止工作吗?
给我答案的用户说这是直接的JS,但我的知识有限。
MMTTMM
相关分类