[英]How can use PHP header() function inside PayPal Javascript code
我正在尝试将Paypal与我的网站集成,现在正面临实际处理Paypal发送的不同消息(例如成功,失败,已取消等)的问题
我将Paypal JS代码的一小部分粘贴到其中,用于处理以下消息
onAuthorize: function (data, actions) {
return actions.payment.execute()
.then(function (res2) {
// Show a confirmation message to the buyer
console.log(res2);
console.log(res2.transactions[0].related_resources[0].sale.state);
//state codes - completed, partially_refunded, pending, refunded, denied
if(res2.transactions[0].related_resources[0].sale.state == 'completed'){
// alert("Payment received for the invoice number" + res2.transactions[0].invoice_number);
}
});
},
onCancel: function (data, actions) {
// Show a cancel page or return to cart
alert("Payment cancelled");
},
onError: function (err) {
// Show an error page here, when an error occurs
alert("Payment error");
}
现在我想要的是,每当付款“完成”时,我都希望php将类似以下内容的内容附加到URL
order-placed.php?completed&invoice=$invoiceNumber
我尝试将PHP放在Paypal警报消息上方的JS代码中,但是当我尝试加载该页面时,它显示“此页面无法正常运行,localhost重定向了您太多次。” 有人可以指导我吗? 有没有其他方法可以处理不同的付款状态消息? 提前致谢
不要在javascript代码内使用PHP标头函数,因为这将无法正常工作。您可以通过以下javascript代码重定向页面。
location.href = 'http://youdomain.com/order-placed.php?completed&invoice=<?php echo $invoiceNumber ?>';
希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.