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
fix(checkout-portal): resolve Mac and iPhone modal layout and UPI QR rendering (#90)
ArunGupta15265a81e51ee288
diff --git a/apps/checkout-portal/public/css/checkout.css b/apps/checkout-portal/public/css/checkout.cssindex 7a33268..a337cdd 100644--- a/apps/checkout-portal/public/css/checkout.css+++ b/apps/checkout-portal/public/css/checkout.css@@ -562,14 +562,26 @@}.ypg-app-icon {- width: 22px;- height: 22px;+ width: 24px;+ height: 24px;border-radius: 50%;display: flex;align-items: center;justify-content: center;flex-shrink: 0;- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);+ cursor: pointer;+ transition: transform 0.15s ease, box-shadow 0.15s ease;+ user-select: none;+ }++ .ypg-app-icon:hover {+ transform: scale(1.18);+ box-shadow: 0 3px 8px rgba(0, 0, 0, 0.22);+ }++ .ypg-app-icon:active {+ transform: scale(0.92);}.ypg-app-icon img,@@ -577,6 +589,11 @@width: 100%;height: 100%;border-radius: 50%;+ pointer-events: none;+ }++ .ypg-btn-upi-mobile-intent {+ display: none;}.ypg-green-pill-badge {@@ -2489,13 +2506,12 @@/* PC Body Container - Bounded to viewport height */.ypg-body {flex: 1 !important;- height: calc(100% - 48px) !important;- max-height: calc(100% - 48px) !important;+ height: auto !important;+ min-height: 0 !important;display: flex !important;flex-direction: column !important;padding: 0 !important;overflow: hidden !important;- min-height: 0 !important;}#paymentGatewayInterface:not([hidden]) {@@ -2689,6 +2705,27 @@box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4) !important;animation: rzpModalPop 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;}++ /* Desktop Sticky Footer (Pinned firmly at the bottom of workspace) */+ .ypg-sticky-footer {+ margin-top: auto !important;+ background: #ffffff !important;+ border-top: 1px solid #f1f5f9 !important;+ display: flex !important;+ flex-direction: column !important;+ flex-shrink: 0 !important;+ position: relative !important;+ z-index: 20 !important;+ width: 100% !important;+ }++ .ypg-legal-disclaimer {+ font-size: 11px !important;+ color: #64748b !important;+ text-align: center !important;+ padding: 8px 16px !important;+ line-height: 1.4 !important;+ }}/* MOBILE SPECIFIC RULES - PINNED HEADER WITH CONTENT SCROLLING BEHIND IT */@@ -2830,6 +2867,30 @@.mob-only-btn {display: inline !important;}++ .ypg-btn-upi-mobile-intent {+ display: flex !important;+ align-items: center;+ justify-content: center;+ gap: 8px;+ width: 100%;+ padding: 12px 16px;+ background: var(--ypg-blue, #0b63e5);+ color: #ffffff;+ border: none;+ border-radius: 10px;+ font-weight: 700;+ font-size: 14px;+ cursor: pointer;+ margin-top: 10px;+ box-shadow: 0 4px 14px rgba(11, 99, 229, 0.28);+ transition: transform 0.15s ease, filter 0.15s ease;+ }++ .ypg-btn-upi-mobile-intent:active {+ transform: scale(0.98);+ filter: brightness(0.92);+ }}/* --- OFFICIAL GOOGLE PLAY STORE APP ICONS --- */diff --git a/apps/checkout-portal/src/__tests__/checkout-portal.test.js b/apps/checkout-portal/src/__tests__/checkout-portal.test.jsindex 283427e..4df83fd 100644--- a/apps/checkout-portal/src/__tests__/checkout-portal.test.js+++ b/apps/checkout-portal/src/__tests__/checkout-portal.test.js@@ -163,20 +163,28 @@ describe('Checkout Portal Integration Tests', () => {assert.ok(res.text.includes('id="serverStatusLabel"'));assert.ok(res.text.includes('id="serverDowntimeAlert"'));- // Verify Play Store icons are referenced+ // Verify Play Store icons are referenced and interactiveassert.ok(res.text.includes('/icons/gpay.png'));assert.ok(res.text.includes('/icons/phonepe.png'));assert.ok(res.text.includes('/icons/paytm.png'));+ assert.ok(res.text.includes('handleUpiAppClick'));+ assert.ok(res.text.includes('id="btnMobileUpiIntent"'));++ // DOM hierarchy invariant: No redundant nested <div class="ypg-body">+ assert.equal(res.text.includes('<div class="ypg-body">'), false);+ assert.ok(res.text.includes('<main class="ypg-body">'));// INVARIANT: Raw Payee VPA / UPI ID row is REMOVED from Order Summaryassert.equal(res.text.includes('id="drawerVpa"'), false);});- test('GET /css/checkout.css returns the static stylesheet with CORS', async () => {+ test('GET /css/checkout.css returns the static stylesheet with CORS and responsive modal rules', async () => {const resCss = await get('/css/checkout.css');assert.equal(resCss.status, 200);assert.ok(resCss.headers['content-type'].includes('text/css'));assert.ok(resCss.text.includes('.ypg-wrapper'));+ assert.ok(resCss.text.includes('.ypg-btn-upi-mobile-intent'));+ assert.ok(resCss.text.includes('.ypg-sticky-footer'));});test('the checkout page loads exactly one copy of the client script', async () => {diff --git a/apps/checkout-portal/src/sdk/youpi.js b/apps/checkout-portal/src/sdk/youpi.jsindex 3e0fede..74db5b7 100644--- a/apps/checkout-portal/src/sdk/youpi.js+++ b/apps/checkout-portal/src/sdk/youpi.js@@ -742,11 +742,15 @@border-top-left-radius: 20px !important;border-top-right-radius: 20px !important;margin: 0 !important;- transform: translateY(0) !important;+ transform: translateY(100%) !important;+ transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6) !important;touch-action: auto !important;overflow: hidden !important;}+ .youpi-checkout-container.active {+ transform: translateY(0) !important;+ }.youpi-checkout-container.closing {transform: translateY(100%) !important;}diff --git a/apps/checkout-portal/src/views/checkout.html b/apps/checkout-portal/src/views/checkout.htmlindex 0e40a14..3b2b670 100644--- a/apps/checkout-portal/src/views/checkout.html+++ b/apps/checkout-portal/src/views/checkout.html@@ -19,11 +19,8 @@<!-- include:partials/header.html -->- <!-- 3. SCROLLABLE BODY -->- <div class="ypg-body">- <!-- include:partials/auth.html -->- <!-- include:partials/payment-methods.html -->- </div>+ <!-- include:partials/auth.html -->+ <!-- include:partials/payment-methods.html --><!-- include:partials/footer.html -->@@ -2260,18 +2257,27 @@async function loadQrSvg() {const container = document.getElementById('qrImageContainer');if (!container) return;- try {- const res = await fetch(`/checkout/${PAYMENT_ID}/qr.svg`);- if (res.ok) {- const svg = await res.text();- if (svg && svg.includes('<svg')) {- container.innerHTML = svg;- return;++ const candidates = [`/checkout/${PAYMENT_ID}/qr.svg`];+ if (API_BASE && typeof API_BASE === 'string' && API_BASE.startsWith('http')) {+ candidates.push(`${API_BASE}/checkout/${PAYMENT_ID}/qr.svg`);+ }++ for (const targetUrl of candidates) {+ try {+ const res = await fetch(targetUrl);+ if (res.ok) {+ const svg = await res.text();+ if (svg && svg.includes('<svg')) {+ container.innerHTML = svg;+ return;+ }}+ } catch (e) {+ console.warn('loadQrSvg error from:', targetUrl, e);}- } catch (e) {- console.warn('loadQrSvg error:', e);}+// Automatic retry to guarantee QR code is loadedsetTimeout(async () => {try {@@ -2286,6 +2292,43 @@}, 400);}+ function getUpiIntentUri() {+ if (state && state.upiUri) return state.upiUri;+ const vpa = state?.payeeVpa || state?.vpa || 'merchant@upi';+ const name = state?.merchantName || 'Store';+ const amt = state?.amount || '10.00';+ return `upi://pay?pa=${encodeURIComponent(vpa)}&pn=${encodeURIComponent(name)}&am=${encodeURIComponent(amt)}&tn=${encodeURIComponent(PAYMENT_ID)}`;+ }++ function handleOpenUpiIntent() {+ const uri = getUpiIntentUri();+ try {+ window.location.href = uri;+ } catch (err) {+ console.warn('Could not launch UPI intent:', err);+ }+ }++ function handleUpiAppClick(appName) {+ const isMobileDevice = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent) || (window.innerWidth <= 767);+ if (isMobileDevice) {+ handleOpenUpiIntent();+ return;+ }+ // On desktop (macOS / Windows / Linux), copy VPA and show informative toast+ const vpa = (state?.payeeVpa || state?.vpa || '').trim();+ if (vpa) {+ try {+ navigator.clipboard.writeText(vpa);+ showOptionToast(`Copied UPI ID (${vpa})! Open ${appName} on your phone to complete payment.`);+ } catch {+ showOptionToast(`Scan QR with ${appName} on your phone to pay ₹${state?.amount || ''}`);+ }+ } else {+ showOptionToast(`Scan QR with ${appName} on your phone to pay ₹${state?.amount || ''}`);+ }+ }+function copyVpaId() {const vpa = (state?.payeeVpa || document.getElementById('displayVpaVal')?.textContent || '').trim();if (!vpa) return;diff --git a/apps/checkout-portal/src/views/partials/payment-methods.html b/apps/checkout-portal/src/views/partials/payment-methods.htmlindex 7042778..4b56a4e 100644--- a/apps/checkout-portal/src/views/partials/payment-methods.html+++ b/apps/checkout-portal/src/views/partials/payment-methods.html@@ -150,18 +150,18 @@<!-- Brand Logos Row (Zero Fake Offers) --><div style="display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin:3px 0 6px 0;"><div class="ypg-upi-logos-row">- <div class="ypg-app-icon" title="Google Pay"><img src="/icons/gpay.png"+ <div class="ypg-app-icon" title="Google Pay" role="button" tabindex="0" onclick="handleUpiAppClick('Google Pay')"><img src="/icons/gpay.png"onerror="if(window.FALLBACK_ICONS)this.src=window.FALLBACK_ICONS.gpay" alt="GPay" /></div>- <div class="ypg-app-icon" title="PhonePe"><img src="/icons/phonepe.png"+ <div class="ypg-app-icon" title="PhonePe" role="button" tabindex="0" onclick="handleUpiAppClick('PhonePe')"><img src="/icons/phonepe.png"onerror="if(window.FALLBACK_ICONS)this.src=window.FALLBACK_ICONS.phonepe" alt="PhonePe" /></div>- <div class="ypg-app-icon" title="Paytm"><img src="/icons/paytm.png"+ <div class="ypg-app-icon" title="Paytm" role="button" tabindex="0" onclick="handleUpiAppClick('Paytm')"><img src="/icons/paytm.png"onerror="if(window.FALLBACK_ICONS)this.src=window.FALLBACK_ICONS.paytm" alt="Paytm" /></div>- <div class="ypg-app-icon" title="CRED"><img src="/icons/cred.png"+ <div class="ypg-app-icon" title="CRED" role="button" tabindex="0" onclick="handleUpiAppClick('CRED')"><img src="/icons/cred.png"onerror="if(window.FALLBACK_ICONS)this.src=window.FALLBACK_ICONS.cred" alt="CRED" /></div>- <div class="ypg-app-icon" title="BHIM UPI"><img src="/icons/bhim.png"+ <div class="ypg-app-icon" title="BHIM UPI" role="button" tabindex="0" onclick="handleUpiAppClick('BHIM UPI')"><img src="/icons/bhim.png"onerror="if(window.FALLBACK_ICONS)this.src=window.FALLBACK_ICONS.bhim" alt="BHIM" /></div>- <div class="ypg-app-icon" title="Amazon Pay"><img src="/icons/amazonpay.png"+ <div class="ypg-app-icon" title="Amazon Pay" role="button" tabindex="0" onclick="handleUpiAppClick('Amazon Pay')"><img src="/icons/amazonpay.png"onerror="if(window.FALLBACK_ICONS)this.src=window.FALLBACK_ICONS.amazonpay"alt="Amazon Pay" /></div></div>@@ -170,6 +170,12 @@<div style="font-size:12px; color:#64748b; line-height:1.4;">Open any UPI app on your phone to scan and pay directly.</div>++ <!-- 1-Tap Mobile UPI Intent Launcher (Shown on Mobile, Hidden on PC) -->+ <button type="button" class="ypg-btn-upi-mobile-intent" id="btnMobileUpiIntent" onclick="handleOpenUpiIntent()">+ <img src="/icons/upi.svg" alt="UPI" style="height:14px; filter:brightness(0) invert(1);" />+ <span>Pay via Any UPI App</span>+ </button></div></div><!-- UPI Payment Instructions Guide -->diff --git a/packages/merchant-sdk/src/youpi.js b/packages/merchant-sdk/src/youpi.jsindex 0bf5006..917dbdd 100644--- a/packages/merchant-sdk/src/youpi.js+++ b/packages/merchant-sdk/src/youpi.js@@ -787,11 +787,15 @@ _isSafeRedirect(url) {border-top-left-radius: 20px !important;border-top-right-radius: 20px !important;margin: 0 !important;- transform: translateY(0) !important;+ transform: translateY(100%) !important;+ transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6) !important;touch-action: auto !important;overflow: hidden !important;}+ .youpi-checkout-container.active {+ transform: translateY(0) !important;+ }.youpi-checkout-container.closing {transform: translateY(100%) !important;}