[英]PayPal Smart Buttons won't acknowledge items list. Ideas?
我在使用 PayPal 智能按钮界面时遇到问题。 该文档非常适得其反。
沙箱中的电子邮件示例不会显示项目描述/详细信息。 它只显示总数。 在他们网站上的一份文档中, items
块位于purchase_units
块内。 失败将没有真正的错误消息。
paypal.Buttons({
createOrder: function (data, actions) {
// Busy indicator.
var spinner = document.getElementById("spinner");
var cart = document.getElementById("vysshopcart");
spinner.style.display = "block";
cart.style.display = "none";
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: "10",
"currency-code": "USD",
details: {
subtotal: "10",
shipping: "0",
tax: "0.00"
},
total: "10"
}
}],
links: [{
href: "http://192.168.249.20:81/virtual-yard-sale?invoice=2020092011397C1E",
rel: "approve"
}],
"items": [
{
"sku": "2",
"name": "Harry & David Snack Disk",
"price": "5.00",
"quantity": "1",
"category": "PHYSICAL_GOODS",
"currency": "USD"
}
, {
"sku": "10",
"name": "Raya Insulated Lunch Tote",
"price": "5.00",
"quantity": "1",
"category": "PHYSICAL_GOODS",
"currency": "USD"
}
]
});
},
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.replace("http://192.168.249.20:81/virtual-yard-sale?invoice=2020092011397C1E");
});
}
}).render('#paypal-button-container');
看起来你在别处找到了答案,一个 items 数组进入purchase_units
,但是还需要一个金额细目,例如
amount: {
currency_code: "EUR",
value: "200.00",
breakdown: {
item_total: {
currency_code: "EUR",
value: "200.00"
}
}
},
关于 onApprove 流程,如果可能,请考虑这样做并从您的服务器创建 createOrder。 这是一个演示: https : //developer.paypal.com/demo/checkout/#/pattern/server
您的服务器上需要两条路由来调用 /v2/checkout/orders API,一条用于“创建订单”,另一条用于捕获它, 记录在此处。
服务器集成更强大,假设您要确保客户端(浏览器)不会与总数混淆,并且您收到成功捕获的即时 API 响应,并且可以将订单标记为在您的服务器中支付,与操作相反.order.capture() 在客户端代码中,这可能会给您带来错误。
但是对于相对较少的交易量/简单的用例,更简单的仅客户端集成可能就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.