Skip to main content

Refunds

Refunds for lost or returned packages, or manual (ops only).

📄️Introduction

REST contract of the customer-payments bounded context of the digital storefront, as the service serves it. Customer Payments moves money with the shipment facts: authorize at checkout, capture each shipment group's allocation when it ships (FulfillmentShipped), release on cancellation (FulfillmentCancelled), refund on lost or returned packages (PackageLost, PackageReturned), and re-authorize uncaptured allocations before the provider's authorization validity expires. The provider is reached through an ACL port (Authorize, Capture, Void, Refund, Reauthorize) with deterministic idempotency keys per (operation, authorizationId, groupNo); the storefront never sees a card number, only PSP tokens. This surface is called by checkout (authorize, void) and by storefront ops (refunds, reads); captures, releases and re-authorizations arrive as Kafka events or policies, never as REST writes. Errors are RFC 9457 problem details (application/problem+json) whose type is /problems/<slug>; shared types are not-found (404), illegal-transition (409), concurrent-update (409) and validation-failed (422), plus one kebab-case slug per Err of the model, and the idempotency problems idempotency-key-required and idempotency-key-invalid (400) and idempotency-key-reused (409). Every write (each POST) takes an Idempotency-Key header: a retry with the same key and the same request (method, path, body) replays the first answer (Idempotency-Replayed: true). A 2xx is stored for 24 hours, and so is a refusal that is final for the request (malformed-request, allocation-mismatch, negative-amount); a refusal that depends on state that can change (not-found, concurrent-update, illegal-transition, over-refund, payment-declined, validation-failed) and a 5xx are never stored: the key is released, the same Idempotency-Key runs the request again, and another request under it is a new request, not idempotency-key-reused. Otherwise the same key with another request is 409 idempotency-key-reused. A body that is not one JSON object of the declared fields (unknown field, trailing data, over 64 KiB, a NUL character) is 400 malformed-request; a NUL character in a path is 404 resource-not-found. Any operation can answer 500 internal-error. The two collection reads are keyset-paged ({items, nextCursor}; invalid-limit, invalid-cursor and unknown-query-parameter are 400). No authentication.

📄️Authorize the quote total of a checkout session

AuthorizePayment. One authorization per checkout session (ErrDuplicateAuthorization; a replay with the same Idempotency-Key returns the existing one; so does a new key while the session holds a live authorization, answered 200 instead of 201). checkout calls this with key <sessionId>:auth and one allocation per shipment group (1 to 50, distinct groupNo); allocations must sum to the authorized total (ErrAllocationMismatch). On a provider decline the record is DECLINED (terminal, 201 with declineReason) and the checkout session stays open for another token.

📄️Request a manual refund (ops only)

RequestRefund, the ops route. Automatic refunds come from the RefundOnLostPackage and RefundOnReturnToSender policies. The order must have an authorization (else 404). groupNo is optional: absent or 0 refunds at the order level. Refunds of an order (and of a group) never exceed the captured total (ErrOverRefund); FAILED refunds do not count. The provider is tried once in the same call: the answer is 201 with the refund SUCCEEDED, FAILED (provider decline, failureCode set) or still REQUESTED (provider unreachable; a policy retries it), never 503.