我在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');发布于 2020-09-21 03:40:30
看起来你在别的地方找到了答案,一个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的路由,一个用于“创建订单”,另一个用于捕获它,即documented here。
服务器集成更加健壮,假设您希望确保客户端(浏览器)不会篡改总数,并且您希望收到成功捕获的即时API响应,并且可以在您的服务器中将订单标记为已支付,这与客户端代码中的actions.order.capture()形成对比,后者可能会对您造成影响。
但对于相对较低的事务量/简单的用例,更简单的客户端集成可能就足够了。
https://stackoverflow.com/questions/63980919
复制相似问题