Technical Debt — Payment Transaction Ledger & Refund Audit Gaps
By Engineering Team•October 5, 2026•4 min read
| Metadata | Details |
|---|---|
| System | Payment Transaction Ledger, Refund Compensation & Gateway Audit Trail |
| Document ID | TD-2026-PAY-002 |
| Author | Engineering Team |
| Status | Tracked |
SR-017 and ADR-00028 link here rather than restating these gaps inline; this is the one place they’re tracked.
TD-01 — No document-audit publish at the RefundPayment RPC call site
- Status: Open
- Severity: Medium
- Affected component:
payment-service’sPaymentOrderServiceTrait::refund_payment(service/paymentorder/paymentorder_svc_impl.rs:110-159) - Evidence:
create_payment_order(paymentorder_svc_impl.rs:33-108) callsself.publish_audit_event_async(documentaudit, ...)immediately after a successful Razorpay call (:92-102), publishing the full request/response JSON todocument-service’s audit sink.refund_payment(:110-159) has no equivalent call anywhere in its body — its method signature itself (:111-115) takes onlyinputandrazorpay, with nodocumentaudit: Arc<dyn DocumentAuditPublisherTrait>parameter at all, unlikecreate_payment_order’s four parameters.payment-service/CLAUDE.md’s own “Document audit trail” section lists exactly two instrumented call sites (create_payment_order, the webhook handler’shandle_webhook_event) and does not mentionrefund_payment. - Impact: A refund issued to Razorpay via this RPC has zero local, traceable record of what was sent to or received from the payment provider until (and unless) the later
refund.processedwebhook arrives and is processed by the webhook handler’s own audit publish. In the interim there is no retrievable record of this specific outbound call, contradicting BRD-016’s BR-04 guarantee for this one call site. - Remediation direction: Add
documentaudit: Arc<dyn DocumentAuditPublisherTrait>as a parameter torefund_payment(mirroringcreate_payment_order’s shape) and call the existingpublish_audit_event_asynchelper withtransaction_name: "refund_payment"immediately after a successful Razorpay refund call. - Related requirement: SR-017 FR-06
TD-02 — A refund’s ledger entry depends entirely on webhook delivery, with no reconciliation sweep
- Status: Open
- Severity: Medium
- Affected component:
payment-service’sRefundProcessedStrategy(service/razorpaywebhook/razorpaywebhook_strategies.rs);order-service’sRefundPayment-triggered saga compensation path (checkout_saga_workflow.go’srefundPaymenthelper) - Evidence:
refund_payment(paymentorder_svc_impl.rs:110-159) returns aPaymentRefundto its caller as soon as Razorpay confirms the refund request (:149-153), but writes nopayment_ledgerrow itself — theDEBIT/REFUNDEDentry is written only later, byRefundProcessedStrategy, if and when Razorpay’s ownrefund.processedwebhook is received (see ADR-00028). No scheduled sweep or synchronous status check anywhere inpayment-serviceororder-serviceindependently confirms a refund’s ledger entry was actually recorded if that webhook is lost outright — the same risk class already accepted and tracked for the capture side in TD-04 — Checkout Completion Payment Flow Gaps. - Impact: In the edge case where Razorpay’s
refund.processedwebhook is never (re)delivered, a refund thatorder-service’s saga believes completed — it already recordedStepRefundPayment/StepStatusCompletedfrom the RPC’s own successful response — has no corresponding permanent ledger record inpayment-service. This is a silent gap between the saga’s own compensation record andpayment-service’s own financial bookkeeping, undermining BRD-016’s BR-01 ledger-completeness guarantee specifically for refunds. - Remediation direction: Extend the periodic reconciliation sweep proposed in TD-04 to also cover refunds — or, at minimum, add a direct Razorpay refund-status lookup when
order-service’s saga records aStepRefundPaymentcompletion, so a missing ledger entry is caught independent of webhook delivery. - Related requirement: BRD-016 BR-01, BR-03; SR-017 FR-05
Related Documents
- BRD-016 — Payment Transaction Ledger, Refund Guarantee & Data Security
- SR-017 — Payment Transaction Ledger & Security System Requirements
- ADR-00028 — Append-Only, Webhook-Anchored Ledger vs. Synchronous or Mutable-Balance Alternatives for Payment Transaction Records
- Architecture — Payment Transaction Ledger, Refund Compensation & Gateway Audit Trail
- Technical Debt — Checkout Completion Payment Flow Gaps — TD-04, the capture-side precedent for this doc’s TD-02
- Microservices: payment-service, order-service