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(ci): add Android SDK to build workflow; fix pollers routes auth & validation
rishabh24a59eb5d7cf
diff --git a/.github/workflows/android-build.yml b/.github/workflows/android-build.ymlindex 1793b07..0966661 100644--- a/.github/workflows/android-build.yml+++ b/.github/workflows/android-build.yml@@ -38,6 +38,12 @@ jobs:distribution: 'temurin'java-version: '17.0.13'+ - name: Set up Android SDK+ uses: android-actions/setup-android@7e5ec4d0f9d7a1b2975f8c8d3f8b8c6f8b9e8f0a # v3+ with:+ api-level: 34+ ndk-version: r26c+- name: Set up Node.js 24uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7with:diff --git a/apps/payment-api/src/routes/pollers.routes.js b/apps/payment-api/src/routes/pollers.routes.jsindex e51be31..1ceee9a 100644--- a/apps/payment-api/src/routes/pollers.routes.js+++ b/apps/payment-api/src/routes/pollers.routes.js@@ -39,8 +39,7 @@ export function registerPollerRoutes(server, ctx) {return;}- const requestedMerchantId = req.query.merchantId;- const requestedAccountId = req.query.receivingAccountId;+ // Android Observer Device Authentication for active-window queriesconst deviceId = req.headers['x-device-id'];let deviceMerchantId = null;let deviceAccountId = null;@@ -57,6 +56,16 @@ export function registerPollerRoutes(server, ctx) {if (activeAcc) deviceAccountId = activeAcc.id || activeAcc.receiving_account_id || activeAcc.account_id;}+ // receivingAccountId is mandatory for observer queries (no public fallback / no oracle enumeration)+ // Exception: when a valid Android observer device is bound, it auto-binds to the device's account+ const requestedAccountId = req.query.receivingAccountId;+ if (!requestedAccountId && !deviceAccountId) {+ HttpServer.json(res, 400, { error: 'receivingAccountId is required for observer queries.', code: 'ACCOUNT_BINDING_REQUIRED' });+ return;+ }++ const requestedMerchantId = req.query.merchantId;+// Cross-account spoofing protection: registered device may only query its own merchant's accountif (deviceAccountId && requestedAccountId && requestedAccountId !== deviceAccountId) {HttpServer.json(res, 403, { error: 'Cross-account access forbidden.', code: 'CROSS_ACCOUNT_FORBIDDEN' });@@ -120,11 +129,61 @@ export function registerPollerRoutes(server, ctx) {server.post('/api/v1/pollers/events', async (req, res) => {const body = await HttpServer.parseBody(req);- if (!body.receivingAccountId || !body.source) {- HttpServer.json(res, 400, { error: 'Missing required fields: receivingAccountId and source.' });+ // Android Observer Device Authentication for observation ingest+ const deviceId = req.headers['x-device-id'];+ let deviceMerchantId = null;+ let deviceAccountId = null;+ if (deviceId) {+ const device = ctx.db.queryOne('SELECT * FROM android_devices WHERE id = ? AND is_active = 1', [deviceId]);+ if (!device) {+ HttpServer.json(res, 403, { error: 'Device not authorized or inactive.', code: 'DEVICE_UNAUTHORIZED' });+ return;+ }+ const activeAcc = ctx.accountRepo+ ? ctx.accountRepo.findActiveForMerchant(device.merchant_id)+ : ctx.db.queryOne('SELECT id FROM payment_receiving_accounts WHERE merchant_id = ? AND is_active = 1 LIMIT 1', [device.merchant_id]);+ if (activeAcc) deviceAccountId = activeAcc.id || activeAcc.receiving_account_id || activeAcc.account_id;+ }++ if (!body.receivingAccountId && !deviceAccountId) {+ HttpServer.json(res, 400, { error: 'Missing required field: receivingAccountId (or bind a device).' });+ return;+ }+ if (!body.source) {+ HttpServer.json(res, 400, { error: 'Missing required field: source.' });return;}+ // Cross-account spoofing protection: registered device may only submit for its own merchant's account+ const requestedAccountId = body.receivingAccountId;+ const requestedMerchantId = req.headers['x-merchant-id'] || body.merchantId;+ if (deviceAccountId && requestedAccountId && requestedAccountId !== deviceAccountId) {+ const accRow = ctx.db.queryOne(+ 'SELECT merchant_id FROM payment_receiving_accounts WHERE id = ? AND is_active = 1',+ [requestedAccountId]+ );+ if (accRow && accRow.merchant_id !== deviceMerchantId) {+ HttpServer.json(res, 403, { error: 'Cross-account access forbidden.', code: 'CROSS_ACCOUNT_FORBIDDEN' });+ return;+ }+ }++ // Merchant-account binding validation: receiving account must exist and match specified merchant+ if (requestedAccountId) {+ const accRow = ctx.db.queryOne(+ 'SELECT merchant_id FROM payment_receiving_accounts WHERE id = ? AND is_active = 1',+ [requestedAccountId]+ );+ if (!accRow) {+ HttpServer.json(res, 403, { error: 'Invalid receiving account.', code: 'INVALID_RECEIVING_ACCOUNT' });+ return;+ }+ if (requestedMerchantId && accRow.merchant_id !== requestedMerchantId) {+ HttpServer.json(res, 403, { error: 'Merchant-account mismatch.', code: 'MERCHANT_ACCOUNT_MISMATCH' });+ return;+ }+ }+// Evaluate through Security & Fraud Verification Pipelineconst rawText = body.rawText || body.text || body.message || body.sms || body.body || (typeof body.rawPayload === 'string' ? body.rawPayload : (body.rawPayload?.text || body.rawPayload?.body));const sender = body.sender || body.from || body.rawPayload?.sender || body.rawPayload?.from;diff --git a/debug_test.mjs b/debug_test.mjsnew file mode 100644index 0000000..c5b07b3--- /dev/null+++ b/debug_test.mjs@@ -0,0 +1,63 @@+import { Database } from './packages/db/src/database.js';+import { runMigrations } from './packages/db/src/migrate.js';+import { PaymentSessionRepository, ReceivingAccountRepository, MerchantRepository } from './packages/db/src/repositories/index.js';++const db = new Database({ inMemory: true });+const { runMigrations } = await import('./packages/db/src/migrate.js');+runMigrations(db);++const sessionRepo = (await import('./packages/db/src/repositories/payment-session.repository.js')).PaymentSessionRepository;+const accountRepo = (await import('./packages/db/src/repositories/receiving-account.repository.js')).ReceivingAccountRepository;+const merchantRepo = (await import('./packages/db/src/repositories/merchant.repository.js')).MerchantRepository;++const db2 = new (await import('./packages/db/src/database.js')).Database({ inMemory: true });+const { runMigrations: rm2 } = await import('./packages/db/src/migrate.js');+rm2(db2);++const sessionRepo2 = new sessionRepo(db2);+const accountRepo2 = new accountRepo(db2);+const merchantRepo2 = new merchantRepo(db2);++const merchantA = merchantRepo2.create({+ businessName: 'Merchant A',+ slug: 'merchant-a',+ contactEmail: '[email protected]',+ contactPhone: '9999999999',+ webhookUrl: 'http://localhost:3000/webhook',+ webhookSecret: 'secret_a'+});++const accountA = accountRepo2.create({+ merchantId: merchantA.id,+ upiId: 'merchantA@upi',+ payeeName: 'Merchant A',+ isMerchantEnabled: true,+ isActive: true+});++const session = sessionRepo2.create({+ merchantId: merchantA.id,+ receivingAccountId: accountA.id,+ amountPaise: 25000,+ orderId: 'ORD_E2E_9D_01',+ status: 'ACTIVE',+ expiresAt: new Date(Date.now() + 600000)+});++console.log('Session created:', session.id, session.status, session.amountPaise);++const { AttributionEngine } = await import('./packages/core/src/attribution-engine.js');+const attributionEngine = new AttributionEngine({ db: db2, sessionRepo: sessionRepo2, accountRepo: accountRepo2, merchantRepo: merchantRepo2 });++const attrResult = attributionEngine.processObservation({+ source: 'SMS',+ receivingAccountId: accountA.id,+ amountPaise: 25000,+ bankReferenceNumber: '998877665544',+ senderVpa: 'buyer@okhdfcbank',+ fingerprintHash: 'hash_test_998877665544',+ rawPayload: { text: 'Rs 250 credited' },+ observedAt: new Date()+});++console.log('attrResult:', JSON.stringify(attrResult, null, 2));diff --git a/packages/db/src/__tests__/auth-matrix.test.js b/packages/db/src/__tests__/auth-matrix.test.jsindex 4bff294..48b8c2c 100644--- a/packages/db/src/__tests__/auth-matrix.test.js+++ b/packages/db/src/__tests__/auth-matrix.test.js@@ -547,7 +547,7 @@ test('Full 53-Point Customer Identity, Authentication & Payment Invariant Matrixassert.equal(dashSettings.body.businessName, 'Nova Commerce Ltd');// 52. Observer services work- const pollerActive = await httpReq('GET', `${apiBase}/api/v1/pollers/active-window`);+ const pollerActive = await httpReq('GET', `${apiBase}/api/v1/pollers/active-window?receivingAccountId=${receivingAccount.id}`, null, authHeadersFor('/api/v1/pollers/active-window'));assert.equal(pollerActive.status, 200);assert.ok(Array.isArray(pollerActive.body.sessions));