如何将订单 ID 传递给 Paypal Button?
How to pass order ID to Paypal Button?
我通过我的 php sdk 创建订单。
像这样
$result = json_decode((string) $response->getBody());
echo $result->id; // id of the created order
现在我有了这个订单号。但是...如何将订单 ID 传递给 Paypal Button?
像这样
`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');
在您的服务器上创建两个路由,一个用于创建订单(和 return 结果 JSON),另一个将订单 ID 作为参数并捕获它(和 return是 JSON 结果)。
这两条路线都应该 return/output 只有 JSON(没有 HTML 或文本)。
将这两条路线与此批准流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server
我通过我的 php sdk 创建订单。
像这样
$result = json_decode((string) $response->getBody());
echo $result->id; // id of the created order
现在我有了这个订单号。但是...如何将订单 ID 传递给 Paypal Button? 像这样
`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');
在您的服务器上创建两个路由,一个用于创建订单(和 return 结果 JSON),另一个将订单 ID 作为参数并捕获它(和 return是 JSON 结果)。
这两条路线都应该 return/output 只有 JSON(没有 HTML 或文本)。
将这两条路线与此批准流程配对:https://developer.paypal.com/demo/checkout/#/pattern/server