Refund Recovery
Refund authority lives in refund_attempts (migration 019). An attempt record is written before any PG call — unrecorded external refunds cannot exist (REFUND-1). Committed cap authority is SUM(amount_krw) over non-failed attempts.
Attempt lifecycle
attempted → confirmed (PG cancel confirmed + provider_ref) → succeeded (internal effects applied)
→ needs_review (uncertain/unattributed — resolve via recheck, never guess)
→ failed (terminal — key/attempt reusable)1
2
3
2
3
idempotency_key(client) — same key + same request hash replays the recorded outcome; different hash →409 IDEMPOTENCY_CONFLICT.provider_ref(PG transaction key) — UNIQUE per attempt; used to attribute provider cancels during reconcile.- A non-terminal attempt (
attempted/confirmed/needs_review) blocks new attempts on the same order (409 REFUND_IN_PROGRESS) — double-refund defense.
Recovery paths
| Situation | Action |
|---|---|
attempted stuck >5min (non-toss) | expire_stale_internal_attempts fails it automatically on next refund/reconcile — no external call existed |
attempted/needs_review (toss) | RECHECK_PROVIDER_REFUND op — GET /v1/payments/{key} only; re-attributes by transactionKey amount match; unattributed stays needs_review |
confirmed without internal effects | APPLY_CONFIRMED_REFUND_INTERNAL op — re-runs apply_refund_effects (ledger idem_key refund-{oid}-{attempt} makes double-apply impossible) |
| Webhook cancel ahead of refund | apply_provider_cancel records a confirmed attempt then applies internally |
Never retry a refund after a timeout without checking refund_attempts + PG state — the PG cancel may already have succeeded (double refund).
Evidence
refund.attempt, refund.apply, and (full refunds) license.revoke evidence records are chain-sealed per event — see audit-evidence.
S1 hardening notes (main, 85f113b / 45ffde5 — after 45e270c)
- Provider status recheck — a payment-status read failure is now HTTP 500, never handled as a mock/successful outcome (
85f113b).RECHECK_PROVIDER_REFUNDstays GET-only; a failed read leaves the attemptneeds_review-bound, not guessed. - License-revoke ordering — on a full refund the license-revoke step aborts before the internal-effects batch writes, so a revoke failure cannot commit a partially compensated state (
85f113b). - Webhook attribution — a
order_lookupfailure during webhook handling marks the inbox eventfailedinstead of being silently ignored (85f113b); failed inbox events are recoverable through the normal inbox/replay path, not lost. - Suite status —
refund-safety.test.mjs32/32 locally at45ffde5(loopback). Real PG sandbox remainsNOT_VERIFIED— all executed evidence is mock/TEST-stub only.
S2 hardening notes (main c5cffd7 / e6a05cf / 940fd75)
- Mid-pipeline FI probes (s2-03
c5cffd7). New injected-failure pointsrefund.attempt_insert,refund.confirm_write, andrefund.committed— armable per-request viax-fi-probes(sameDEV_AUTH+ non-prodPAYMENT_MODEgate). The fault-injection suite (77 legs) asserts: attempt-insert failure → 500 with zero PG calls; cancel-transport failure →502 TOSS_UPSTREAM+needs_review, recovery is GET-recheck not re-cancel; confirm-write failure →needs_review, recheck attributes + applies effects with no second cancel. refund_consistencycheck legs (s2-02e6a05cf). recon now cross-checks attemptamount_krwvs the ledgerpayment_refundeddebit and flags attempts exceeding the order amount cap —needs_reviewfindings, same triage path.- Webhook freshness (s2-10
1daf526). Signed webhooks older than ±600 s (transmission-time) are rejected401 WEBHOOK_STALEwhenTOSS_WEBHOOK_SECRETis configured — replayed signedPARTIAL_CANCELED/DONEevents are bounded by freshness, not just inbox dedup. - Real PG sandbox remains
NOT_VERIFIED— every leg above is loopback stub only.