12-Digit UTR Anti-Replay & Post-Order Timestamp Verification Architecture

Technical breakdown of how UPIGateway.dev prevents duplicate transaction claims, stale email replays, and concurrent checkout race conditions using PostgreSQL UTR locks and strict timestamp guards.

Threat Model: Why Naive UPI Verification Fails at Scale

Direct-to-bank UPI automation removes intermediary escrow delays and percentage aggregator fees, but naive merchant pollers fail against two real-world abuse patterns: UTR replay attacks (submitting an already-settled 12-digit NPCI bank reference to verify a second checkout session) and stale credit window leakage (matching an older incoming transfer received before the new checkout order existed).

Control 1: Strict Post-Order Timestamp Enforcement

When a merchant backend calls POST /api/create-order, UPIGateway.dev persists an immutable order creation timestamp (`create_date`). Across both merchant session pollers and automated Gmail IMAP verification listeners, incoming bank alerts are evaluated sequentially against the order creation boundary.

  • Any bank credit notification or merchant statement event timestamped before order `create_date` is discarded automatically.
  • Even if a merchant received an identical ₹499 transfer two minutes earlier from another shopper, that historical credit can never resolve a newly spawned checkout session.
  • Session expiry timers cap the active scan window, preventing indefinite matching on abandoned payment URLs.

Control 2: Atomic 12-Digit UTR Anti-Replay Registry

Once an incoming transfer passes amount and timestamp checks, the 12-digit Unique Transaction Reference (UTR) is checked against previously verified records in Supabase PostgreSQL before marking any order `SUCCESS`.

Verification StageCheck AppliedFailure Behavior
Stage 1: Session StateTarget order must currently hold status `PENDING`Already settled orders ignore duplicate capture triggers
Stage 2: Timestamp WindowBank/email alert timestamp >= `order.create_date`Historical credits excluded from matching candidate pool
Stage 3: Amount IntegritySettled amount >= expected checkout order amountPartial transfer triggers `FLAGGED_UNDERPAID` rejection
Stage 4: UTR Anti-Replay12-digit UTR must not exist on another `SUCCESS` orderDuplicate UTR claim blocked cleanly without credit

Recommended Merchant Backend Verification Pattern

Even though UPIGateway.dev enforces anti-replay checks centrally, production merchant backends should reinforce idempotency locally by indexing their own fulfilled orders table by unique `(order_id)` and `(utr)` keys, and always confirming status via `POST /api/check-order-status` before releasing digital licenses or wallet credits.