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

Merge PR #136: fix(core) harden cross-channel deduplication

rishabhf64afea6550c
diff --cc packages/core/src/attribution-engine.js
index e83f785,6382476..c2602cd
--- a/packages/core/src/attribution-engine.js
+++ b/packages/core/src/attribution-engine.js
@@@ -298,38 -364,24 +364,42 @@@ export class AttributionEngine
let currentSession = null;
if (normalizedObs.rawPayload?.targetSessionId) {
currentSession = this.sessionRepo.findById(normalizedObs.rawPayload.targetSessionId);
+ if (currentSession && currentSession.status === PaymentStatus.MANUAL_REVIEW) {
+ this.obsRepo.markAmbiguous(savedObs.id);
+ return {
+ attributed: false,
+ duplicate: false,
+ lateMatch: false,
+ ambiguous: true,
+ paymentSessionId: currentSession.id,
+ observationId: savedObs.id,
+ outcomeStatus: PaymentStatus.MANUAL_REVIEW,
+ reason: 'SESSION_HELD_IN_MANUAL_REVIEW'
+ };
+ }
}
+ if (currentSession?.method === 'MANUAL_UPI') {
+ if (this.auditRepo) this.auditRepo.log({
+ merchantId: currentSession.merchantId,
+ entityType: 'PAYMENT_SESSION',
+ entityId: currentSession.id,
+ action: 'AUTOMATIC_OBSERVATION_IGNORED_FOR_MANUAL_UPI',
+ actorType: 'OBSERVER',
+ details: { observationId: savedObs.id, source: normalizedObs.source }
+ });
+ return {
+ attributed: false,
+ duplicate: false,
+ lateMatch: false,
+ observationId: savedObs.id,
+ outcomeStatus: ObservationAttributionStatus.UNATTRIBUTED,
+ reason: 'MANUAL_UPI_REQUIRES_ADMIN_BANK_VERIFICATION'
+ };
+ }
if (!currentSession || (currentSession.amountPaise !== normalizedObs.amountPaise)) {
- currentSession = this.sessionRepo.findCurrentActiveOrProcessing(normalizedObs.receivingAccountId);
- }
- if (currentSession?.method === 'MANUAL_UPI') {
- if (this.auditRepo) this.auditRepo.log({ merchantId: currentSession.merchantId, entityType: 'PAYMENT_SESSION', entityId: currentSession.id,
- action: 'AUTOMATIC_OBSERVATION_IGNORED_FOR_MANUAL_UPI', actorType: 'OBSERVER', details: { observationId: savedObs.id, source: normalizedObs.source } });
- return { attributed: false, duplicate: false, lateMatch: false, observationId: savedObs.id,
- outcomeStatus: ObservationAttributionStatus.UNATTRIBUTED, reason: 'MANUAL_UPI_REQUIRES_ADMIN_BANK_VERIFICATION' };
- }
- if (currentSession && currentSession.amountPaise !== normalizedObs.amountPaise) {
const matchRows = this.sessionRepo.db.query(`
SELECT * FROM payment_sessions
- WHERE receiving_account_id = ? AND status IN ('ACTIVE', 'PROCESSING') AND amount_paise = ?
+ WHERE receiving_account_id = ? AND status IN ('ACTIVE', 'PROCESSING') AND method <> 'MANUAL_UPI' AND amount_paise = ?
`, [normalizedObs.receivingAccountId, Number(normalizedObs.amountPaise)]);
if (matchRows.length > 1) {
return this.holdAmbiguous(