diff --git a/crates/router/src/core/generic_link/payout_link/status/script.js b/crates/router/src/core/generic_link/payout_link/status/script.js index 42b57903593..ffb554a6829 100644 --- a/crates/router/src/core/generic_link/payout_link/status/script.js +++ b/crates/router/src/core/generic_link/payout_link/status/script.js @@ -173,7 +173,17 @@ function redirectToEndUrl(returnUrl) { } if (secondsLeft === 0) { setTimeout(function () { - window.location.href = returnUrl.toString(); + try { + window.top.location.href = returnUrl.toString(); + } catch (error) { + console.error( + "CRITICAL ERROR", + "Failed to redirect top document. Error - ", + error + ); + console.info("Redirecting in current document"); + window.location.href = returnUrl.toString(); + } }, 1000); } }, i * 1000); diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html index b66242305b6..54e48a5241f 100644 --- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html +++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html @@ -325,10 +325,10 @@ {{ hyperloader_sdk_link }} diff --git a/crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js b/crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js index 777cfd8cadd..48974a564d5 100644 --- a/crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js +++ b/crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js @@ -57,7 +57,7 @@ if (!isFramed) { }); var type = paymentDetails.sdk_layout === "spaced_accordion" || - paymentDetails.sdk_layout === "accordion" + paymentDetails.sdk_layout === "accordion" ? "accordion" : paymentDetails.sdk_layout; @@ -103,6 +103,35 @@ if (!isFramed) { arr.splice(0, 3); arr.unshift("status"); arr.unshift("payment_link"); - window.location.href = window.location.origin + "/" + arr.join("/")+ "?locale=" + paymentDetails.locale; + let returnUrl = + window.location.origin + + "/" + + arr.join("/") + + "?locale=" + + paymentDetails.locale; + try { + window.top.location.href = returnUrl; + + // Push logs to logs endpoint + } catch (error) { + var url = window.location.href; + var { paymentId, merchantId, attemptId, connector } = parseRoute(url); + var urlToPost = getEnvRoute(url); + var message = { + message: "CRITICAL ERROR - Failed to redirect top document. Falling back to redirecting using window.location", + reason: error.message, + } + var log = { + message, + url, + paymentId, + merchantId, + attemptId, + connector, + }; + postLog(log, urlToPost); + + window.location.href = returnUrl; + } } } diff --git a/crates/router/src/core/payment_link/payment_link_status/status.html b/crates/router/src/core/payment_link/payment_link_status/status.html index fdc0c3012bb..c78a0bb556d 100644 --- a/crates/router/src/core/payment_link/payment_link_status/status.html +++ b/crates/router/src/core/payment_link/payment_link_status/status.html @@ -11,9 +11,9 @@ href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800" />