Skip to content

A self-hosted UPI & COD payment gateway with zero per-transaction platform fees, universal JavaScript checkout integration, dynamic QR payments, WhatsApp OTP authentication, and automated payment verification.

JavaScript

rebase PR #80 onto main: merge returnUrl auto-redirect logic

rishabh6235e55223a7
diff --git a/apps/checkout-portal/public/js/checkout.js b/apps/checkout-portal/public/js/checkout.js
index 26251b1..c1c4c38 100644
--- a/apps/checkout-portal/public/js/checkout.js
+++ b/apps/checkout-portal/public/js/checkout.js
@@ -1915,13 +1915,24 @@
});
} catch (e) { }
+ const effectiveReturnUrl = data.returnUrl || state?.returnUrl || null;
const btnReturn = document.getElementById('btnReturnStore') || document.getElementById('btnReturnToStore');
- if (btnReturn && data.returnUrl) {
- btnReturn.hidden = false;
- btnReturn.href = data.returnUrl;
- if (window.parent === window) {
- const safeReturn = sanitizeRedirectUrl(data.returnUrl);
- setTimeout(() => { if (safeReturn) window.location.href = safeReturn; }, 2000);
+ if (effectiveReturnUrl) {
+ const safeReturn = sanitizeRedirectUrl(effectiveReturnUrl);
+ if (safeReturn) {
+ if (btnReturn) {
+ btnReturn.hidden = false;
+ btnReturn.href = safeReturn;
+ btnReturn.textContent = 'Return to Store (Redirecting in 2s...)';
+ }
+ if (descEl && !descEl.textContent.includes('Redirecting')) {
+ descEl.textContent += ' Redirecting to merchant store...';
+ }
+ if (window.parent === window) {
+ setTimeout(() => { window.location.href = safeReturn; }, 2000);
+ }
+ } else if (btnReturn) {
+ btnReturn.hidden = true;
}
} else if (btnReturn) {
btnReturn.hidden = true;
diff --git a/apps/checkout-portal/src/views/checkout.html b/apps/checkout-portal/src/views/checkout.html
index 85fcc2f..f29c4b5 100644
--- a/apps/checkout-portal/src/views/checkout.html
+++ b/apps/checkout-portal/src/views/checkout.html
@@ -2008,13 +2008,24 @@
});
} catch (e) { }
+ const effectiveReturnUrl = data.returnUrl || state?.returnUrl || null;
const btnReturn = document.getElementById('btnReturnStore') || document.getElementById('btnReturnToStore');
- const safeReturnUrl = sanitizeRedirectUrl(data.returnUrl);
- if (btnReturn && safeReturnUrl) {
- btnReturn.hidden = false;
- btnReturn.href = safeReturnUrl;
- if (window.parent === window) {
- setTimeout(() => { window.location.href = safeReturnUrl; }, 2000);
+ if (effectiveReturnUrl) {
+ const safeReturn = sanitizeRedirectUrl(effectiveReturnUrl);
+ if (safeReturn) {
+ if (btnReturn) {
+ btnReturn.hidden = false;
+ btnReturn.href = safeReturn;
+ btnReturn.textContent = 'Return to Store (Redirecting in 2s...)';
+ }
+ if (descEl && !descEl.textContent.includes('Redirecting')) {
+ descEl.textContent += ' Redirecting to merchant store...';
+ }
+ if (window.parent === window) {
+ setTimeout(() => { window.location.href = safeReturn; }, 2000);
+ }
+ } else if (btnReturn) {
+ btnReturn.hidden = true;
}
} else if (btnReturn) {
btnReturn.hidden = true;
diff --git a/apps/payment-api/src/routes/checkout.routes.js b/apps/payment-api/src/routes/checkout.routes.js
index eb0768a..760acc6 100644
--- a/apps/payment-api/src/routes/checkout.routes.js
+++ b/apps/payment-api/src/routes/checkout.routes.js
@@ -472,6 +472,9 @@ export function registerCheckoutRoutes(server, ctx) {
amountPaise: session.amountPaise.toString(),
currency: session.currency,
status: session.status,
+ method: session.method,
+ verificationTag: session.verificationTag || 'UNVERIFIED',
+ returnUrl: session.returnUrl || null,
timeRemainingSeconds: 0,
isTerminal: true,
// The return URL belongs to the terminal payload too. The checkout