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

fix(customer): resolve ReviewGround code review suggestions

ArunGupta15260fcded1589fd
diff --git a/apps/payment-api/src/routes/customer.routes.js b/apps/payment-api/src/routes/customer.routes.js
index a4f0d9a..69cb387 100644
--- a/apps/payment-api/src/routes/customer.routes.js
+++ b/apps/payment-api/src/routes/customer.routes.js
@@ -7,6 +7,21 @@ const OTP_MAX_ATTEMPTS = 5;
/** Minimum gap between OTP requests for the same mobile number. */
const OTP_RESEND_COOLDOWN_MS = 30 * 1000;
+/**
+ * Safely masks customer email address for public responses without leaking length or erroring on short strings.
+ * @param {string} email
+ * @returns {string | null}
+ */
+function maskEmail(email) {
+ if (!email || typeof email !== 'string') return null;
+ const atIndex = email.indexOf('@');
+ if (atIndex <= 0) return '***';
+ const user = email.slice(0, atIndex);
+ const domain = email.slice(atIndex + 1);
+ const visible = user.slice(0, Math.min(2, user.length));
+ return `${visible}***@${domain || '***'}`;
+}
+
/**
* Registers gateway-owned customer identity and session routes.
* @param {HttpServer} server
@@ -130,6 +145,9 @@ export function registerCustomerRoutes(server, ctx) {
const ip = req.socket?.remoteAddress || '127.0.0.1';
const now = Date.now();
+ if (checkUserRateMap.size > 10000) {
+ checkUserRateMap.clear();
+ }
const timestamps = checkUserRateMap.get(ip) || [];
const recent = timestamps.filter(t => now - t < 60000);
if (recent.length >= 60) {
@@ -148,7 +166,7 @@ export function registerCustomerRoutes(server, ctx) {
customer: existingUser ? {
id: existingUser.id,
name: existingUser.name,
- email: existingUser.email ? `${existingUser.email.slice(0, 2)}***@${existingUser.email.split('@')[1] || '***'}` : null,
+ email: maskEmail(existingUser.email),
mobileNumber: cleanMobile
} : null
});
diff --git a/packages/db/src/repositories/customer.repository.js b/packages/db/src/repositories/customer.repository.js
index aa5ac67..da41f54 100644
--- a/packages/db/src/repositories/customer.repository.js
+++ b/packages/db/src/repositories/customer.repository.js
@@ -115,8 +115,8 @@ export class CustomerRepository {
if (!normalized) return null;
const clean10 = normalized.slice(-10);
const row = this.db.queryOne(
- 'SELECT * FROM customers WHERE mobile_number IN (?, ?, ?)',
- [normalized, clean10, '+91' + clean10]
+ 'SELECT * FROM customers WHERE mobile_number = ? OR mobile_number = ? OR mobile_number = ? OR mobile_number LIKE ?',
+ [normalized, clean10, '+91' + clean10, '%' + clean10]
);
if (!row) return null;
return this.mapRow(row);