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
Merge PR #57: harden device binding and credential verification
rishabhca8193275bb5
diff --cc apps/payment-api/src/routes/payments.routes.jsindex 30bb597,aa15895..dfa0b41--- a/apps/payment-api/src/routes/payments.routes.js+++ b/apps/payment-api/src/routes/payments.routes.js@@@ -58,39 -58,25 +58,47 @@@ export function registerPaymentRoutes(sreturn;}+ // returnUrl is echoed back to the customer's browser as a redirect target after+ // payment, so only absolute http(s) URLs are ever stored. This is the write-side+ // complement to the checkout page's sanitizeRedirectUrl.+ if (body.returnUrl !== undefined && body.returnUrl !== null && body.returnUrl !== '') {+ if (typeof body.returnUrl !== 'string') {+ HttpServer.json(res, 400, { error: 'returnUrl must be a string.' });+ return;+ }+ let parsedReturnUrl;+ try {+ parsedReturnUrl = new URL(body.returnUrl.trim());+ } catch {+ HttpServer.json(res, 400, { error: 'returnUrl must be an absolute http(s) URL.' });+ return;+ }+ if (parsedReturnUrl.protocol !== 'http:' && parsedReturnUrl.protocol !== 'https:') {+ HttpServer.json(res, 400, { error: 'returnUrl must use the http or https scheme.' });+ return;+ }+ body.returnUrl = parsedReturnUrl.href;+ }+const deviceId = body.deviceId || req.headers['x-device-id'] || null;- if (deviceId && ctx.deviceRepo) {- let dev = ctx.deviceRepo.findById(deviceId);- if (!dev) {- try {- ctx.deviceRepo.create({- id: deviceId,- publicKey: `adhoc_${deviceId}`,- fingerprintHash: `fp_${deviceId}`- });- } catch {}+ const deviceToken = body.deviceToken || req.headers['x-device-token'] || null;+ const deviceSignature = body.deviceSignature || req.headers['x-device-signature'] || null;+ const signaturePayload = body.signaturePayload || req.headers['x-device-payload'] || null;++ if (deviceId) {+ const credCheck = verifyRegisteredDeviceCredentials({+ deviceId,+ deviceToken,+ deviceSignature,+ signaturePayload,+ deviceRepo: ctx.deviceRepo+ });+ if (!credCheck.valid) {+ HttpServer.json(res, 401, {+ error: credCheck.error || 'DEVICE_CREDENTIALS_INVALID',+ message: credCheck.message || 'A registered device and valid device credential are required.'+ });+ return;}}