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

feat(checkout-portal): make checkout portal templates, partials, and hydration dynamically branded

ArunGupta15269b7d95cc1348
diff --git a/apps/checkout-portal/src/__tests__/checkout-portal.test.js b/apps/checkout-portal/src/__tests__/checkout-portal.test.js
index 283427e..94e46c9 100644
--- a/apps/checkout-portal/src/__tests__/checkout-portal.test.js
+++ b/apps/checkout-portal/src/__tests__/checkout-portal.test.js
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
import http from 'node:http';
import { startCheckoutServer } from '../index.js';
import { generateQrMatrix, generateQrSvg } from '@youpi/core';
-import { frameAncestorOrigins } from '../server.js';
+import { CheckoutServer, frameAncestorOrigins } from '../server.js';
describe('Checkout Portal Integration Tests', () => {
let serverInstance;
@@ -196,5 +196,24 @@ describe('Checkout Portal Integration Tests', () => {
assert.ok(res.text.includes('STORAGE_KEY_IDENTITY'));
assert.ok(res.text.includes('sanitizeRedirectUrl'));
});
+
+ test('renders dynamic branding when DEFAULT_APP_NAME or merchant branding is configured', async () => {
+ const origEnv = { ...process.env };
+ process.env.DEFAULT_APP_NAME = 'CustomPay Gateway';
+ process.env.DEFAULT_PRIMARY_COLOR = '#0ea5e9';
+
+ const portalServer = new CheckoutServer();
+ const html = portalServer.renderHtml('pay_123', {
+ merchantName: 'My Super Store',
+ amount: '299.00'
+ });
+
+ assert.ok(html.includes('CustomPay Gateway Checkout'));
+ assert.ok(html.includes('CustomPay Gateway Verified Business'));
+ assert.ok(html.includes('200+ orders verified this month by CustomPay Gateway'));
+ assert.ok(html.includes('CustomPay Gateway Help & Support'));
+
+ process.env = { ...origEnv };
+ });
});
});
diff --git a/apps/checkout-portal/src/server.js b/apps/checkout-portal/src/server.js
index dbcaec8..406d8c2 100644
--- a/apps/checkout-portal/src/server.js
+++ b/apps/checkout-portal/src/server.js
@@ -220,13 +220,15 @@ export class CheckoutServer {
renderHtml(paymentId, state) {
let html = this.loadTemplateWithPartials();
- const appName = state?.branding?.appName || 'YouPI PG';
- const primaryColor = state?.branding?.primaryColor || '#0b63e5';
+ const appName = state?.branding?.appName || (process.env.DEFAULT_APP_NAME || '').trim() || 'YouPI PG';
+ const primaryColor = state?.branding?.primaryColor || (process.env.DEFAULT_PRIMARY_COLOR || '').trim() || '#0b63e5';
const merchantName = state?.merchantName || 'Merchant Checkout';
const orderId = state?.orderId || '';
- const logoUrl = state?.branding?.logoUrl || '';
+ const logoUrl = state?.branding?.logoUrl || (process.env.DEFAULT_LOGO_URL || '').trim() || '';
const sidebarNotice = state?.branding?.sidebarNotice || 'Fast & Secure 256-Bit Encrypted Payments';
const counterInstructions = state?.branding?.counterInstructions || 'Please visit the billing counter and present this screen to the cashier.';
+ const footerGuarantee = state?.branding?.footerGuarantee || (process.env.DEFAULT_FOOTER_GUARANTEE || '').trim() || `Secured by ${appName} & 256-Bit Bank Encryption`;
+ const trustBadgeText = state?.branding?.trustBadgeText || (process.env.DEFAULT_TRUST_BADGE_TEXT || '').trim() || `${appName} Verified Business`;
const vpa = state?.payeeVpa || state?.vpa || 'merchant@upi';
// In production and localhost, use relative '' so browser requests hit the checkout portal /api proxy
@@ -262,6 +264,8 @@ export class CheckoutServer {
API_BASE_URL: clientApiBase,
APP_NAME: appName,
PRIMARY_COLOR: primaryColor,
+ FOOTER_GUARANTEE: footerGuarantee,
+ TRUST_BADGE_TEXT: trustBadgeText,
MERCHANT_NAME: merchantName,
ORDER_ID: orderId,
AMOUNT: state?.amount || '0.00',
diff --git a/apps/checkout-portal/src/views/checkout.html b/apps/checkout-portal/src/views/checkout.html
index 0e40a14..14f5b9a 100644
--- a/apps/checkout-portal/src/views/checkout.html
+++ b/apps/checkout-portal/src/views/checkout.html
@@ -1962,7 +1962,8 @@
}
} else {
if (titleEl) titleEl.textContent = 'Payment Successful!';
- if (descEl) descEl.textContent = 'Your payment was automatically verified by YouPI PG banking observers.';
+ const activeAppName = state?.branding?.appName || '{{APP_NAME}}' || 'YouPI PG';
+ if (descEl) descEl.textContent = `Your payment was automatically verified by ${activeAppName} banking observers.`;
if (codApiBox) codApiBox.style.display = 'none';
}
diff --git a/apps/checkout-portal/src/views/partials/auth.html b/apps/checkout-portal/src/views/partials/auth.html
index b16bbff..737bd67 100644
--- a/apps/checkout-portal/src/views/partials/auth.html
+++ b/apps/checkout-portal/src/views/partials/auth.html
@@ -50,7 +50,7 @@
</div>
<div style="font-size:12.5px; color:var(--ypg-text-dark); font-weight:600; margin-bottom:12px;">
- New to YOUPI PG? Please enter your name and email to proceed:
+ New to {{APP_NAME}}? Please enter your name and email to proceed:
</div>
<div class="ypg-input-group">
diff --git a/apps/checkout-portal/src/views/partials/footer.html b/apps/checkout-portal/src/views/partials/footer.html
index e9d103d..6159d62 100644
--- a/apps/checkout-portal/src/views/partials/footer.html
+++ b/apps/checkout-portal/src/views/partials/footer.html
@@ -3,7 +3,7 @@
<!-- Legal Disclaimer -->
<div class="ypg-legal-disclaimer" id="footerLegalDisclaimer">
- Secured by YouPI PG & 256-Bit Bank Encryption &bull; <span style="text-decoration:underline; cursor:pointer;"
+ {{FOOTER_GUARANTEE}} &bull; <span style="text-decoration:underline; cursor:pointer;"
onclick="openHelpModal()">Privacy Notice</span>
</div>
diff --git a/apps/checkout-portal/src/views/partials/header.html b/apps/checkout-portal/src/views/partials/header.html
index e25a327..8b29c9a 100644
--- a/apps/checkout-portal/src/views/partials/header.html
+++ b/apps/checkout-portal/src/views/partials/header.html
@@ -55,7 +55,7 @@
<path d="M8.5 12l2.5 2.5 5-5" stroke="#ffffff" stroke-width="2.2" stroke-linecap="round"
stroke-linejoin="round" />
</svg>
- <span id="headerTrustBadgeText">YouPI PG Verified Business</span>
+ <span id="headerTrustBadgeText">{{TRUST_BADGE_TEXT}}</span>
</div>
</div>
</div>
@@ -79,7 +79,7 @@
<circle cx="20" cy="21" r="1" />
<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6" />
</svg>
- <span id="subbannerText">200+ orders verified this month by YouPI PG</span>
+ <span id="subbannerText">200+ orders verified this month by {{APP_NAME}}</span>
</div>
<!-- Account Popover Menu -->
diff --git a/apps/checkout-portal/src/views/partials/modals.html b/apps/checkout-portal/src/views/partials/modals.html
index 14e0fcf..2013ccf 100644
--- a/apps/checkout-portal/src/views/partials/modals.html
+++ b/apps/checkout-portal/src/views/partials/modals.html
@@ -2,7 +2,7 @@
<div class="ypg-dialog-overlay" id="helpModal" hidden>
<div class="ypg-dialog-card">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:12px;">
- <strong style="font-size:15px;" id="helpModalTitle">YouPI PG Help &amp; Support</strong>
+ <strong style="font-size:15px;" id="helpModalTitle">{{APP_NAME}} Help &amp; Support</strong>
<button type="button" onclick="closeHelpModal()"
style="background:none; border:none; font-size:18px; cursor:pointer; color:#64748b;">✕</button>
</div>
diff --git a/apps/checkout-portal/src/views/partials/payment-methods.html b/apps/checkout-portal/src/views/partials/payment-methods.html
index 7042778..1c33f33 100644
--- a/apps/checkout-portal/src/views/partials/payment-methods.html
+++ b/apps/checkout-portal/src/views/partials/payment-methods.html
@@ -396,7 +396,7 @@
<div class="ypg-success-title" id="successTitleText">Payment Successful!</div>
<div class="ypg-success-amount" id="successAmountVal">₹{{AMOUNT}}</div>
<div style="font-size:12px; color:var(--ypg-text-muted); margin-bottom:14px;" id="successDescText">
- Your payment was automatically verified by YouPI PG banking observers.
+ Your payment was automatically verified by {{APP_NAME}} banking observers.
</div>
<div id="successCodDevApiBox"
style="display:none; font-size:11.5px; background:#f1f5f9; padding:10px 14px; border-radius:8px; margin-bottom:14px; text-align:left; border:1px solid #e2e8f0;">
diff --git a/apps/checkout-portal/src/views/partials/sidebar.html b/apps/checkout-portal/src/views/partials/sidebar.html
index be21df9..17e3fb6 100644
--- a/apps/checkout-portal/src/views/partials/sidebar.html
+++ b/apps/checkout-portal/src/views/partials/sidebar.html
@@ -15,7 +15,7 @@
<path d="M8.5 12l2.5 2.5 5-5" stroke="#ffffff" stroke-width="2.2" stroke-linecap="round"
stroke-linejoin="round" />
</svg>
- <span id="pcTrustBadgeText">YouPI PG Trusted Business</span>
+ <span id="pcTrustBadgeText">{{TRUST_BADGE_TEXT}}</span>
</div>
</div>
</div>
diff --git a/apps/checkout-portal/src/views/partials/splash.html b/apps/checkout-portal/src/views/partials/splash.html
index c61a8b6..abdb6fb 100644
--- a/apps/checkout-portal/src/views/partials/splash.html
+++ b/apps/checkout-portal/src/views/partials/splash.html
@@ -28,8 +28,7 @@
</div>
<div class="ypg-splash-footer" id="splashFooterWrap">
<span>Secured By</span>
- <strong id="splashSecuredByText" style="color:var(--ypg-blue); font-size:15px; letter-spacing:-0.2px;">YouPI
- PG</strong>
+ <strong id="splashSecuredByText" style="color:var(--ypg-blue); font-size:15px; letter-spacing:-0.2px;">{{APP_NAME}}</strong>
</div>
</div>