![](/img/trans.png)
[英]How to redirect user after to another page using PayPal smart buttons
[英]Paypal Smart Button: how to redirect to a PHP page after successfull payment?
我正在尝试将 paypal 付款集成到我的 web 网站中。
编辑:
成功付款后,我想重定向到 PHP 页面来操作付款数据,例如:保存到 db 交易和付款 id、付款人 email、发送 email 等。
所以这是我的“onApprove”function:
onApprove: function(data, actions) {
var EXECUTE_URL = 'https://www.mywebsite.com/actions/paymentsuccess.php';
return fetch(EXECUTE_URL, {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
paymentID: data.paymentID,
payerID: data.payerID,
payerEmail: data.payerEmail,
payerName: data.payerName,
payerPhone: data.payerPhone
})
});
},
如何调用 PHP 页面(可能带有 POST )并传递所有支付数据,并详细说明该页面(我不需要留在支付页面)?
谢谢
如果您需要做某事,您应该在服务器上的“EXECUTE_URL”中进行(或使用更多当前的集成,捕获 URL)这是任何重要业务任务应该完成的地方。
但是,如果您想将用户重定向到某个结果点(而不是“做某事”),这应该发生在提取之后,并且只有在提取成功时才会发生。 您需要自己添加一个 JS 重定向。
所以基本上,添加处理 fetch 响应的.then()
代码。
对于当前的集成(使用捕获,而不是执行),这是一个解析获取响应的示例实现: https://developer.paypal.com/demo/checkout/#/pattern/server
如果顺便说一句,您使用的是 paypal sdk 那么您应该真正遵循有关确认页面的文档,并在已经加载了贝宝的 sdk 对象的同一页面上显示您想要的用户信息
onApprove: function (data, actions) {
// Get the order details
return actions.order.get().then(function (orderDetails) {
// Show a confirmation using the details from orderDetails
// Then listen for a click on your confirm button
document.querySelector('#confirm-button')
.addEventListener('click', function () {
// Capture the transaction funds
return actions.order.capture().then(function () {
// Show a confirmation to the buyer
});
});
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.