Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(payments): [Payment links] Add fix for payment link redirection url (#7232)

Debarati Ghatak1d607d7970ab
diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js b/crates/router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js
index bc851bbeb1..2d2b2c30ae 100644
--- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js
+++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link_initiator.js
@@ -32,7 +32,7 @@ function initializeSDK() {
redirectionFlags: {
shouldRemoveBeforeUnloadEvents: true,
shouldUseTopRedirection: true,
- }
+ },
});
// @ts-ignore
widgets = hyper.widgets({
@@ -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 +
"/" +
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 290df7d120..9ae64ec313 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
@@ -53,7 +53,7 @@ if (!isFramed) {
redirectionFlags: {
shouldRemoveBeforeUnloadEvents: true,
shouldUseTopRedirection: true,
- }
+ },
});
// @ts-ignore
widgets = hyper.widgets({
@@ -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;
@@ -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 +
"/" +
@@ -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,