如何将订单ID传递给PayPal按钮?
我通过PHP SDK创建订单。
像这样
$result = json_decode((string) $response->getBody());
echo $result->id; // id of the created order
,现在我拥有此订单ID。但是...如何将订单ID传递给PayPal按钮? 像这样
`paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) { //I don't need create order,I have created an order
return actions.order.create({
purchase_units: [{
amount: {
value: '88.44'
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
// Replace the above to show a success message within this page, e.g.
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
I create an order by my php sdk.
like this
$result = json_decode((string) $response->getBody());
echo $result->id; // id of the created order
and now i have this order id. but ... How to pass order ID to Paypal Button?
like this
`paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) { //I don't need create order,I have created an order
return actions.order.create({
purchase_units: [{
amount: {
value: '88.44'
}
}]
});
},
// Finalize the transaction
onApprove: function(data, actions) {
return actions.order.capture().then(function(orderData) {
// Successful capture! For demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
// Replace the above to show a success message within this page, e.g.
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '';
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的服务器上创建两个路由,一个以创建订单(并返回结果JSON),而将订单ID作为参数并捕获它(并返回JSON结果)。
这两种路线都应返回/输出仅JSON(无html或文本)。
将这两条路线与此批准流配对: https://developer.paypal.com/demo/checkout/patern/pattern/server
Create two routes on your server, one to create an order (and return the resulting JSON), and one that takes an order id as a parameter and captures it (and returns the JSON result).
Both of these routes should return/output only JSON (no HTML or text).
Pair those two routes with this approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server