Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

12 — API Mapping (Payments)

Exact endpoints from payments.controller.ts, mapped to screens. Wire contract from 00-shared/07 — note the pagination deviation below.

Base: /api/v1 · Auth: JwtAuthGuard (RBAC perms (planned)).

#MethodPathScreenNotes
E1POST/paymentsS3 recordbody ProcessPaymentDto; returns {payment, receipt}; emits PaymentProcessed
E2POST/payments/refundS4body RefundPaymentDto; 409 rules
E3PATCH/payments/:transactionRef/reconcileS5body {status:string}
E4GET/payments?page&limitS1returns {data, total} — no shared meta
E5GET/payments/:idS2404 if missing
E6GET/payments/invoice/:invoiceIdS8array (unpaginated)
E7GET/payments/receipts?page&limitS7{data, total}
E8GET/payments/receipts/:idS6404 if missing

E1 — Process payment (S3)

  • Request:
{ "amount": 250, "currency": "USD", "gateway": "cash",
  "gatewayTransactionId": "G-123", "invoiceId": "…", "payerName": "A. Kumar",
  "payerEmail": "a@x.com", "description": "Term 1 fee" }
  • Response (data): { payment: {transactionReference, amount, fee, refundedAmount, currency, gateway, status:"completed", invoiceId, payerName, payerEmail, createdAt}, receipt: {receiptNumber, paymentId, amount, fee, currency, paymentMethod, payerName, issuedAt} }
  • Loading: submit spinner → success screen. Caching: none (write).
  • Optimistic UI: none — server-confirmed only.
  • Errors: 400 validation (field details), 409 duplicates, 5xx.
  • Idempotency: transactionReference auto-generated server-side; no client Idempotency-Key (OQ-3).

E2 — Refund (S4)

  • Request: {paymentId, amount?, reason?}
  • Rules (service payments.service.ts): status must be completed (409); refund total ≤ amount (409); full → refunded, partial → partially_refunded.
  • Response: updated payment doc.

E3 — Reconcile (S5)

  • Request: PATCH /payments/{transactionRef}/reconcile body {status}"success" → completed, "failed" → failed, anything else → pending.
  • Response: updated payment.

E4/E7 — Lists (S1/S7)

  • Query: page (default 1), limit (default 20).
  • Response shape deviation: {data:[…], total} — the shared envelope adds meta only for {data, meta} payloads (response-envelope.interceptor.ts:25-32), so the client must derive pagination from data.length + total. Documented as OQ-2 (inconsistent with PaginationMeta elsewhere).
  • Sort: server-fixed createdAt/issuedAt desc; sort/q params not supported.

E5/E8 — Detail

  • Returns single doc; 404 → RESOURCE_NOT_FOUND.

Realtime

  • PaymentProcessed / PaymentRefunded events → WsBridge broadcasts to tenant:{tenantId} room (ws-bridge.service.ts) → client can live-append list / refresh invoice dues. Not routed to BullMQ (event-queue-map.ts has PaymentCompleted→emails dead entry; PaymentProcessed has no entry).

Caching & offline

  • Lists: client cache 5 min (stale-while-revalidate); detail 1 min.
  • Offline: read-only cached views + banner; writes blocked (no offline payment queue — money path never optimistic).