We are using PayPal Checkout Server-side PHP (Orders v2 REST API with PayPal JavaScript SDK). For a long time, we have been suffering a problem, with almost 2-5 % of our orders not successfully redirecting to the success page. Once the payment is successful (on our custom build e-commerce) the redirect happens from JavaScript:
onApprove: function(data, actions) {
return fetch(
'/paypal_checkout/get_order_details',{ method: 'GET'}
).then(function(res) {
return res.json();
}).then(function(res) {
if (res.data.status == "APPROVED") {
// capture order
return fetch(
'/paypal_checkout/capture_order',{method:'POST'})
.then(function(resData) {
return resData.json();
}).then(function(resData) {
let errorDetail = resData.data.hasOwnProperty('details') && Array.isArray(resData.data.details) && resData.data.details[0];
if (errorDetail && errorDetail.issue === 'INSTRUMENT_DECLINED') {
showErrorWithText(errTxt);
}
let captureStatus = resData.data.purchase_units[0].payments.captures[0].status;
if (resData.ack && captureStatus == 'COMPLETED') {
window.location.href = 'kasse.html?schritt=3';
}
}
Can we do this redirect from the server side?