Skip to content

Commit 1bb8f5e

Browse files
refactor: handle redirections for iframed content (#5591)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
1 parent a96e9f3 commit 1bb8f5e

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

crates/router/src/core/generic_link/payout_link/status/script.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,17 @@ function redirectToEndUrl(returnUrl) {
173173
}
174174
if (secondsLeft === 0) {
175175
setTimeout(function () {
176-
window.location.href = returnUrl.toString();
176+
try {
177+
window.top.location.href = returnUrl.toString();
178+
} catch (error) {
179+
console.error(
180+
"CRITICAL ERROR",
181+
"Failed to redirect top document. Error - ",
182+
error
183+
);
184+
console.info("Redirecting in current document");
185+
window.location.href = returnUrl.toString();
186+
}
177187
}, 1000);
178188
}
179189
}, i * 1000);

crates/router/src/core/payment_link/payment_link_initiate/payment_link.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@
325325
</svg>
326326
</div>
327327
<script>
328+
{{logging_template}}
328329
{{locale_template}}
329330
{{rendered_js}}
330331
{{payment_link_initiator}}
331-
{{logging_template}}
332332
</script>
333333
{{ hyperloader_sdk_link }}
334334
</body>

crates/router/src/core/payment_link/payment_link_initiate/secure_payment_link_initiator.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if (!isFramed) {
5757
});
5858
var type =
5959
paymentDetails.sdk_layout === "spaced_accordion" ||
60-
paymentDetails.sdk_layout === "accordion"
60+
paymentDetails.sdk_layout === "accordion"
6161
? "accordion"
6262
: paymentDetails.sdk_layout;
6363

@@ -103,6 +103,35 @@ if (!isFramed) {
103103
arr.splice(0, 3);
104104
arr.unshift("status");
105105
arr.unshift("payment_link");
106-
window.location.href = window.location.origin + "/" + arr.join("/")+ "?locale=" + paymentDetails.locale;
106+
let returnUrl =
107+
window.location.origin +
108+
"/" +
109+
arr.join("/") +
110+
"?locale=" +
111+
paymentDetails.locale;
112+
try {
113+
window.top.location.href = returnUrl;
114+
115+
// Push logs to logs endpoint
116+
} catch (error) {
117+
var url = window.location.href;
118+
var { paymentId, merchantId, attemptId, connector } = parseRoute(url);
119+
var urlToPost = getEnvRoute(url);
120+
var message = {
121+
message: "CRITICAL ERROR - Failed to redirect top document. Falling back to redirecting using window.location",
122+
reason: error.message,
123+
}
124+
var log = {
125+
message,
126+
url,
127+
paymentId,
128+
merchantId,
129+
attemptId,
130+
connector,
131+
};
132+
postLog(log, urlToPost);
133+
134+
window.location.href = returnUrl;
135+
}
107136
}
108137
}

crates/router/src/core/payment_link/payment_link_status/status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800"
1212
/>
1313
<script>
14+
{{logging_template}}
1415
{{locale_template}}
1516
{{ rendered_js }}
16-
{{logging_template}}
1717
</script>
1818
</head>
1919
<body onload="boot()">

0 commit comments

Comments
 (0)