Javascript 付款后显示paypal交易详细信息
在我的网站上使用Paypal成功付款后,浏览器仅显示一个警报:Javascript 付款后显示paypal交易详细信息,javascript,ajax,paypal-sandbox,Javascript,Ajax,Paypal Sandbox,在我的网站上使用Paypal成功付款后,浏览器仅显示一个警报: // Execute the payment onAuthorize: function (data, actions) { return actions.payment.execute() .then(function () { // Show a confirmation message to the buyer window.alert('Compra realizad
// 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!');
});
}
我现在使用的是沙盒选项,但我知道如何向用户提供有关事务的更多详细信息
我看到函数中有一个“data”参数,是否有事务详细信息?如果是,我如何读取它们以在以后向用户显示它们?操作的结果将传递给回调函数,并通过以下方式进行访问:
.then( function(result) {
console.log(result); // Logs all the stuff that gets back from Paypal
});
根据:
一个成功的响应返回交易确认,带有批准状态和交易Id,或者您可以看到
我没有使用服务器端来支付费用,你是对的,但是在你回答的第二部分,有一个对服务器端的调用,这只是从文档中复制粘贴。当然,请根据您的代码进行调整data.payer.payer\u info.shipping\u地址不推荐使用/v1/payments端点。改用/v2/payments端点
// 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.
});
}
// Wait for the payment to be authorized by the customer
onAuthorize: function(data, actions) {
// Get the payment details
return actions.payment.get().then(function(data) {
// Display the payment details and a confirmation button
var shipping = data.payer.payer_info.shipping_address;
// Execute the payment
return actions.payment.execute().then(function() {
// Show a thank-you note
window.alert('Compra realizada con éxito. Recibirá más detalles por email!');
});
});
});
}