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’s PaymentOrderServiceTrait::refund_payment (service/paymentorder/paymentorder_svc_impl.rs:110-159)
  • Evidence: create_payment_order (paymentorder_svc_impl.rs:33-108) calls self.publish_audit_event_async(documentaudit, ...) immediately after a successful Razorpay call (:92-102), publishing the full request/response JSON to document-service’s audit sink. refund_payment (:110-159) has no equivalent call anywhere in its body — its method signature itself (:111-115) takes only input and razorpay, with no documentaudit: Arc<dyn DocumentAuditPublisherTrait> parameter at all, unlike create_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’s handle_webhook_event) and does not mention refund_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.processed webhook 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 to refund_payment (mirroring create_payment_order’s shape) and call the existing publish_audit_event_async helper with transaction_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’s RefundProcessedStrategy (service/razorpaywebhook/razorpaywebhook_strategies.rs); order-service’s RefundPayment-triggered saga compensation path (checkout_saga_workflow.go’s refundPayment helper)
  • Evidence: refund_payment (paymentorder_svc_impl.rs:110-159) returns a PaymentRefund to its caller as soon as Razorpay confirms the refund request (:149-153), but writes no payment_ledger row itself — the DEBIT/REFUNDED entry is written only later, by RefundProcessedStrategy, if and when Razorpay’s own refund.processed webhook is received (see ADR-00028). No scheduled sweep or synchronous status check anywhere in payment-service or order-service independently 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.processed webhook is never (re)delivered, a refund that order-service’s saga believes completed — it already recorded StepRefundPayment/StepStatusCompleted from the RPC’s own successful response — has no corresponding permanent ledger record in payment-service. This is a silent gap between the saga’s own compensation record and payment-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 a StepRefundPayment completion, so a missing ledger entry is caught independent of webhook delivery.
  • Related requirement: BRD-016 BR-01, BR-03; SR-017 FR-05