在我的网站上使用Paypal成功付款后,浏览器仅显示警报:
// Execute the payment
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function () {
// Show a confirmation message to the buyer
window.alert('Compra realizada con éxito. Recibirá más detalles por email!');
});
}
我现在正在使用沙盒选项,但是我会知道如何为用户提供有关交易的更多详细信息。
我看到函数中有一个“数据”参数,有交易明细吗?如果是,我如何阅读它们以便稍后向用户显示?
最佳答案
操作的结果传递到回调函数,并可以通过以下方式访问:
.then( function(result) {
console.log(result); // Logs all the stuff that gets back from Paypal
});
根据the doc:
// Execute the payment:
// 1. Add an onAuthorize callback
onAuthorize: function(data, actions) {
// 2. Make a request to your server
return actions.request.post('/my-api/execute-payment/', {
paymentID: data.paymentID,
payerID: data.payerID
})
.then(function(res) {
// 3. Show the buyer a confirmation message.
});
}