![](/img/trans.png)
[英]PayPal Checkout (javascript) with Smart Payment Buttons create order problem
[英]Paypal Smart Payment Buttons — how to create order server-side and pass order ID to Paypal Buttons setup?
我正在集成 Paypal Checkout 并在他们的文档中关注如何在此处设置客户端 SDK。
我不想在客户端设置订单项和总和,而是对步骤 4末尾提到的订单使用服务器端设置。 使用他们的 PHP SDK 我可以设法设置订单没有问题,但我努力让事情工作的地方是如何将这个创建的订单传递给客户端。 创建的订单的返回对象具有用于启动捕获它的 ID 和 URL,但跟随链接实际上提供了与单击 Paypal 按钮不同的 UX,因此我想仍然使用该按钮,但使用创建的订单。
使用他们的示例代码:
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: '0.01'
}
}]
});
},
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.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
本质上,我从我的服务器端调用有一个订单 ID,不需要使用“createOrder”调用,但是如何将我的订单 ID 传递给paypal.Buttons()
设置,以便当用户单击呈现的 Paypal 按钮时他们被发送以批准我创建的订单?
PS:我知道您之后验证并捕获订单,但是为什么有人想在他们的客户端 Javascript 中设置订单费用? 对我来说,这似乎是一个根本错误的想法。 我在这里错过了什么吗?
解决方案相当明显,但不知何故,我在早些时候查看时并没有偶然发现它。 createOrder
需要返回订单 ID,这可以按照文档进行:
method: 'post',
headers: {
'content-type': 'application/json'
}
}).then(function(res) {
return res.json();
}).then(function(data) {
return data.orderID; // Use the same key name for order ID on the client and server
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.