Customer Returns API
This is the shopper-facing returns API of the customer-returns bounded context (retail network, commerce tier): the front door through which the storefront
authorizes a customer order group's return, links reverse labels and cancels.
A return authorization covers ONE order group (orderId + groupNo) and its lines. The context decides the disposition itself, from its own read models:
KEEP (returnless) when the method is not PICKUP, every unit price is known and the total is within the returnless threshold; else NEAREST_RETURNS_CENTER when the
group's destination region has an ACTIVE returns centre; else ORIGIN_NODE when the sourcing facts named the fulfilling node; else the authorization is refused
(no-return-destination) and the shopper retries later with the same Idempotency-Key.
Rules of the contract:
- The group must be SHIPPED or DELIVERED. The OrderGroupView is fed by customer-ordering's
CustomerOrderPlacedand the terminalShopperNoticeDecidedfamilies; a group that is still PROMISED (or unknown to the view, which may lag) answers422 group-not-shipped-- retry later, same key, same body. - Prices are the storefront's facts.
unitPriceCentsper line is caller-declared and NEVER leaves this context (no event, no tool answer carries it). With a price absent,KEEPcan never be chosen and the authorization is returned withpricesAbsent: true. reasonis an enum (DEFECTIVE,NOT_AS_DESCRIBED,WRONG_ITEM,NOT_NEEDED,OTHER) -- never free text: no event, table or log of this context carries an address, a person's name, a phone number or free text. The ship-to stays in the shipping context, which issues the reverse label.- Labels.
POST /return-authorizations/{id}/labelsasks the shipping context'sPOST /return-labelsroute (the one in-org call this context makes) for the shopper's reverse label, links the tracking number and publishesReturnLabelIssued. While that route is not configured the call answers422 label-unavailable: a tolerant failure, never a 500. At most five packages per authorization (packageNo1..5). - Method.
DROP_OFF(default) orPICKUP. PICKUP requires a window inside[authorizedAt, expiresAt]and is never KEEP. The pickup leg of last-mile is a later wave: the window is recorded, the state machine already knowsPICKUP_FAILED. - Expiry. An authorization expires 30 days after it was authorized; expiry is checked lazily by the next command that touches it, never by a read
(ADR 0002 A4 as amended by A11): a label request cancels it and answers
422 authorization-expired, a cancellation cancels it and answers200, and a graded outcome cancels it before recording the outcome as a fact; the event saysEXPIREDin every case. There is no sweeper. - No authentication (consistent with the fleet): the storefront is the only caller and names the order in the body.
- Every
POSTtakesIdempotency-Key(1 to 128 printable ASCII characters; missing is400 idempotency-key-required, malformed400 idempotency-key-invalid); a repeat replays the first response with the headerIdempotency-Replayedset totruewhen that response is final for the request: a success, and422 authorization-expired(the lazy expiry was committed with it). A refusal that depends on state that can change is NOT stored and its key is released:group-not-shipped,no-return-destination,label-unavailable,concurrent-update,illegal-transition,not-foundandvalidation-failed(so "retry later, same key" is true: the retry executes again, and a different body under the released key is a new request). A 5xx is never stored. The same key on a different method, path or body is409 idempotency-key-reused. - A NUL character (U+0000) is refused before anything else runs: in a path it is
404 not-found; in a query string or a JSON body it is422 validation-failed, and theIdempotency-Keyof such a request is not recorded. Request bodies are decoded strictly: an unknown field, malformed JSON, trailing data or a body over 4 MiB is422 validation-failed. - Errors are RFC 9457
application/problem+json; the shared problem types arenot-found404,illegal-transition409,concurrent-update409,validation-failed422, plus one slug per modelErr...name. - Reports (ADR 0012).
GET /reports/returns-performanceandGET /reports/freshnessare read-only GETs served by the separatecmd/reportsbinary (port 8092, behind the/api/customer-returns/reportsGateway route whenanalytics.enabled), from a projection of this context's own events topic. They are unauthenticated like every route here, and every error isapplication/problem+json. - Events (AsyncAPI
apis/asyncapi.yaml):ReturnAuthorized,ReturnLabelIssued,ReturnCompleted,ReturnCancelledon the events topic.GET /return-authorizations/\{id\}/eventsis deliberately NOT built: the audit trail IS the event stream.
Contact customer-returns maintainers:
License