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(core): validate the payment window config and derive the queue estimate from it
rishabh5e7d17ffbb9e
diff --git a/apps/payment-api/src/index.js b/apps/payment-api/src/index.jsindex 66942a8..62a4551 100644--- a/apps/payment-api/src/index.js+++ b/apps/payment-api/src/index.js@@ -74,12 +74,28 @@ export function createPaymentApp(customDb = null, options = {}) {const eventEmitter = new EventEmitter();+ // The active window and the processing window drive the slot expiry that is written to+ // the database, so a malformed value must not reach it: a negative value would expire+ // every session instantly and Infinity would throw a RangeError on toISOString().+ const parseWindowMs = (raw, fallback, label) => {+ if (raw === undefined || raw === null || String(raw).trim() === '') return fallback;+ const value = Number(raw);+ if (!Number.isFinite(value) || value <= 0 || value > 24 * 60 * 60 * 1000) {+ console.warn(`[config] Ignoring invalid ${label}=${raw}; using ${fallback}ms.`);+ return fallback;+ }+ return Math.floor(value);+ };+ const activeDurationMs = parseWindowMs(process.env.PAYMENT_ACTIVE_WINDOW_MS, 300000, 'PAYMENT_ACTIVE_WINDOW_MS');+ const processingDurationMs = parseWindowMs(process.env.PAYMENT_PROCESSING_WINDOW_MS, 30000, 'PAYMENT_PROCESSING_WINDOW_MS');+const queueEngine = new QueueEngine({sessionRepo,accountRepo,eventEmitter,auditRepo,- activeDurationMs: Number(process.env.PAYMENT_ACTIVE_WINDOW_MS || 300000)+ activeDurationMs,+ processingDurationMs});const timingEngine = new TimingEngine({@@ -87,8 +103,8 @@ export function createPaymentApp(customDb = null, options = {}) {queueEngine,eventEmitter,auditRepo,- activeDurationMs: Number(process.env.PAYMENT_ACTIVE_WINDOW_MS || 300000),- processingDurationMs: Number(process.env.PAYMENT_PROCESSING_WINDOW_MS || 30000)+ activeDurationMs,+ processingDurationMs});const attributionEngine = new AttributionEngine({diff --git a/packages/core/src/queue-engine.js b/packages/core/src/queue-engine.jsindex 74daf51..1c99117 100644--- a/packages/core/src/queue-engine.js+++ b/packages/core/src/queue-engine.js@@ -13,6 +13,8 @@ export class QueueEngine {constructor(options) {// Payment window used whenever a caller does not pass one (PAYMENT_ACTIVE_WINDOW_MS).this.activeDurationMs = options.activeDurationMs || 300000;+ // Verification window for a session that reached PROCESSING (PAYMENT_PROCESSING_WINDOW_MS).+ this.processingDurationMs = options.processingDurationMs || 30000;this.sessionRepo = options.sessionRepo;this.accountRepo = options.accountRepo;this.eventEmitter = options.eventEmitter || { emit: () => {} };@@ -141,8 +143,9 @@ export class QueueEngine {}}- // Average per queued cycle: 5-minute active window + 30-sec processing window- const CYCLE_DURATION_SECONDS = 330;+ // Average per queued cycle: the configured active window plus the processing window.+ // Deriving it keeps the estimate correct when PAYMENT_ACTIVE_WINDOW_MS is changed.+ const CYCLE_DURATION_SECONDS = Math.round((this.activeDurationMs + this.processingDurationMs) / 1000);const precedingQueuedWait = (queuePosition - 1) * CYCLE_DURATION_SECONDS;return currentSlotRemaining + precedingQueuedWait;