I am trying to integrate Paypal with my website and now am facing problem to actually handle different messages sent by paypal like success, failed, cancelled and all
I am pasting a small part of the paypal JS code where it handles the messages below
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");
}
Now what I want is, Whenever the payment is "completed" i want php to append to URL something like
order-placed.php?completed&invoice=$invoiceNumber
I tried placing PHP inside the JS code just above the Paypal alert messages but when i tried loading the page, It says "This page isn't working localhost redirected you too many times." Can anyone guide me on this please? Is there an alternative way in which i can handle different payment status messages? Thanks in advance
Don't use PHP header function inside the javascript code because that will not work.you can redirect your page via below code in javascript.
location.href = 'http://youdomain.com/order-placed.php?completed&invoice=<?php echo $invoiceNumber ?>';
Hope this helps you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.