Skip to content

Commit

Permalink
fix(payments): [Payment links] Add fix for payment link redirection u…
Browse files Browse the repository at this point in the history
…rl (#7232)
  • Loading branch information
cookieg13 authored Feb 11, 2025
1 parent b616bd1 commit 1d607d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function initializeSDK() {
redirectionFlags: {
shouldRemoveBeforeUnloadEvents: true,
shouldUseTopRedirection: true,
}
},
});
// @ts-ignore
widgets = hyper.widgets({
Expand Down Expand Up @@ -86,9 +86,19 @@ function initializeSDK() {
function redirectToStatus() {
var paymentDetails = window.__PAYMENT_DETAILS;
var arr = window.location.pathname.split("/");
arr.splice(0, 2);
arr.unshift("status");
arr.unshift("payment_link");

// NOTE - This code preserves '/api' in url for integ and sbx
// e.g. url for integ/sbx - https://integ.hyperswitch.io/api/payment_link/merchant_1234/pay_1234?locale=en
// e.g. url for others - https://abc.dev.com/payment_link/merchant_1234/pay_1234?locale=en
var hasApiInPath = arr.includes("api");
if (hasApiInPath) {
arr.splice(0, 3);
arr.unshift("api", "payment_link", "status");
} else {
arr.splice(0, 2);
arr.unshift("payment_link", "status");
}

window.location.href =
window.location.origin +
"/" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (!isFramed) {
redirectionFlags: {
shouldRemoveBeforeUnloadEvents: true,
shouldUseTopRedirection: true,
}
},
});
// @ts-ignore
widgets = hyper.widgets({
Expand All @@ -63,7 +63,7 @@ if (!isFramed) {
});
var type =
paymentDetails.sdk_layout === "spaced_accordion" ||
paymentDetails.sdk_layout === "accordion"
paymentDetails.sdk_layout === "accordion"
? "accordion"
: paymentDetails.sdk_layout;

Expand Down Expand Up @@ -109,9 +109,19 @@ if (!isFramed) {
function redirectToStatus() {
var paymentDetails = window.__PAYMENT_DETAILS;
var arr = window.location.pathname.split("/");
arr.splice(0, 3);
arr.unshift("status");
arr.unshift("payment_link");

// NOTE - This code preserves '/api' in url for integ and sbx envs
// e.g. url for integ/sbx - https://integ.hyperswitch.io/api/payment_link/s/merchant_1234/pay_1234?locale=en
// e.g. url for others - https://abc.dev.com/payment_link/s/merchant_1234/pay_1234?locale=en
var hasApiInPath = arr.includes("api");
if (hasApiInPath) {
arr.splice(0, 4);
arr.unshift("api", "payment_link", "status");
} else {
arr.splice(0, 3);
arr.unshift("payment_link", "status");
}

let returnUrl =
window.location.origin +
"/" +
Expand All @@ -127,9 +137,10 @@ if (!isFramed) {
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",
message:
"CRITICAL ERROR - Failed to redirect top document. Falling back to redirecting using window.location",
reason: error.message,
}
};
var log = {
message,
url,
Expand Down

0 comments on commit 1d607d7

Please sign in to comment.