openapi: 3.0.3 info: title: Customer Payments API version: 0.1.0 contact: name: customer-payments maintainers url: https://github.com/IQVO/customer-payments description: >- 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/; 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. servers: - url: http://localhost:8080 tags: - name: Authorizations description: One PaymentAuthorization per checkout session, with allocations per shipment group. - name: Refunds description: Refunds for lost or returned packages, or manual (ops only). paths: /payment-authorizations: post: tags: [Authorizations] operationId: authorizePayment summary: Authorize the quote total of a checkout session description: >- 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 :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. parameters: - $ref: '#/components/parameters/IdempotencyKey' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/AuthorizeRequest' responses: '200': description: The live authorization the checkout session already holds (no new authorization was created). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/PaymentAuthorization' '201': description: The authorization this call created (AUTHORIZED or DECLINED). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/PaymentAuthorization' '400': $ref: '#/components/responses/IdempotencyKeyProblem' '409': description: duplicate-authorization (ErrDuplicateAuthorization, only when two concurrent authorizes for one checkout session race; a sequential repeat returns the existing authorization with 200) or concurrent-update; neither is stored, the key is released and the same Idempotency-Key runs again. Or idempotency-key-reused (the Idempotency-Key was already used with a different request). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' '422': description: validation-failed (not stored; the key is released), negative-amount or allocation-mismatch (ErrAllocationMismatch, also a groupNo that appears twice); both stored and replayed. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' '500': $ref: '#/components/responses/InternalError' '503': description: payment-provider unreachable or timed out (payment-provider-unavailable). Nothing is stored; retry with the same Idempotency-Key, provider keys are deterministic. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' get: tags: [Authorizations] operationId: listPaymentAuthorizations summary: List authorizations by order or checkout session description: >- ListAuthorizations. Exactly one of orderId or checkoutSessionId is required (none or both is 422 validation-failed). Keyset-paged, oldest first (createdAt, authorizationId): follow nextCursor until it is absent and repeat the filter on every page request. parameters: - name: orderId in: query required: false schema: type: string - name: checkoutSessionId in: query required: false schema: type: string - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' responses: '200': description: One page of the matching authorizations. content: application/json: schema: $ref: '#/components/schemas/PaymentAuthorizationPage' '400': $ref: '#/components/responses/InvalidPageRequest' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /payment-authorizations/{authorizationId}: get: tags: [Authorizations] operationId: getPaymentAuthorization summary: Get one authorization with its allocations description: GetAuthorization. parameters: - $ref: '#/components/parameters/AuthorizationId' responses: '200': description: The authorization. content: application/json: schema: $ref: '#/components/schemas/PaymentAuthorization' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /payment-authorizations/{authorizationId}/voids: post: tags: [Authorizations] operationId: voidPaymentAuthorization summary: Void an uncaptured authorization description: >- VoidAuthorization. checkout calls this with key :void, and only after a definitive rejection of the place-order step (never while the outcome is in doubt; that side is guarded by checkout's ErrPlacementInDoubt). VoidUnboundAuthorizations also voids an authorization that no CheckoutCompleted bound within 24 h. parameters: - $ref: '#/components/parameters/AuthorizationId' - $ref: '#/components/parameters/IdempotencyKey' responses: '200': description: The voided authorization. headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/PaymentAuthorization' '400': $ref: '#/components/responses/IdempotencyKeyProblem' '404': $ref: '#/components/responses/NotFound' '409': description: illegal-transition (already captured, voided or expired) or concurrent-update; neither is stored, the key is released and the same Idempotency-Key runs again. Or idempotency-key-reused (the Idempotency-Key was already used with a different request). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' '422': description: payment-declined (the provider refused the void). Not stored; the key is released and the same Idempotency-Key asks the provider again, which answers from its own record. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' '500': $ref: '#/components/responses/InternalError' '503': description: payment-provider unreachable or timed out (payment-provider-unavailable). Retry with the same Idempotency-Key. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' /refunds: post: tags: [Refunds] operationId: requestRefund summary: Request a manual refund (ops only) description: >- 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. parameters: - $ref: '#/components/parameters/IdempotencyKey' requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/RefundRequest' responses: '201': description: The requested refund (REQUESTED, SUCCEEDED or FAILED after the one provider attempt). headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/Refund' '400': $ref: '#/components/responses/IdempotencyKeyProblem' '404': $ref: '#/components/responses/NotFound' '409': description: over-refund (ErrOverRefund) or concurrent-update; neither is stored, the key is released and the same Idempotency-Key runs again. Or idempotency-key-reused (the Idempotency-Key was already used with a different request). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' '503': description: payment-provider unreachable or timed out (payment-provider-unavailable), or manual refunds disabled by configuration (refunds-disabled, REFUNDS_ENABLED=false; no retry until an operator re-enables them). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' get: tags: [Refunds] operationId: listRefunds summary: List refunds of an order description: >- ListRefunds. Keyset-paged, oldest first (createdAt, refundId): follow nextCursor until it is absent and repeat orderId on every page request. parameters: - name: orderId in: query required: true schema: type: string - $ref: '#/components/parameters/Limit' - $ref: '#/components/parameters/Cursor' responses: '200': description: One page of the matching refunds. content: application/json: schema: $ref: '#/components/schemas/RefundPage' '400': $ref: '#/components/responses/InvalidPageRequest' '422': $ref: '#/components/responses/Unprocessable' '500': $ref: '#/components/responses/InternalError' /refunds/{refundId}: get: tags: [Refunds] operationId: getRefund summary: Get one refund description: GetRefund. parameters: - $ref: '#/components/parameters/RefundId' responses: '200': description: The refund. content: application/json: schema: $ref: '#/components/schemas/Refund' '404': $ref: '#/components/responses/NotFound' '500': $ref: '#/components/responses/InternalError' /refunds/{refundId}/retries: post: tags: [Refunds] operationId: retryRefund summary: Retry a failed refund (ops only) description: >- RetryRefund, the ops route; no request body. Moves a FAILED refund back to REQUESTED and tries the provider once more, at most 5 attempts in all. The answer is 200 with the Refund as it stands after that attempt (SUCCEEDED, FAILED again with failureCode, or still REQUESTED when the provider is unreachable); it is never 503. A refund that is not FAILED, or whose attempts are used up, is 409 illegal-transition. parameters: - $ref: '#/components/parameters/RefundId' - $ref: '#/components/parameters/IdempotencyKey' responses: '200': description: The refund after the retry attempt. headers: Idempotency-Replayed: $ref: '#/components/headers/IdempotencyReplayed' content: application/json: schema: $ref: '#/components/schemas/Refund' '400': $ref: '#/components/responses/IdempotencyKeyProblem' '404': $ref: '#/components/responses/NotFound' '409': description: illegal-transition (the refund is not FAILED, or its 5 attempts are used) or concurrent-update; neither is stored, the key is released and the same Idempotency-Key runs again. Or idempotency-key-reused (the Idempotency-Key was already used with a different request). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' '500': $ref: '#/components/responses/InternalError' components: parameters: IdempotencyKey: name: Idempotency-Key in: header required: true description: >- Client-generated UUID per logical submit (1 to 128 printable ASCII characters); a retry reuses it. The same key with the same request (method, path, body) replays the stored answer with 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 not stored: the key is released and the same key runs the request again, and another request under a released key is a new request. The same key with another request while an answer is stored is 409 idempotency-key-reused. Missing is 400 idempotency-key-required, not 1 to 128 printable ASCII characters is 400 idempotency-key-invalid. schema: type: string minLength: 1 maxLength: 128 AuthorizationId: name: authorizationId in: path required: true schema: type: string RefundId: name: refundId in: path required: true schema: type: string Limit: name: limit in: query required: false description: Page size, 1 to 500 (default 100). Anything else (empty, repeated, not an integer) is 400 invalid-limit. schema: type: integer minimum: 1 maximum: 500 default: 100 Cursor: name: cursor in: query required: false description: Opaque token copied from the previous page's nextCursor; absent (or empty) on the first page. One that does not decode, or is repeated, is 400 invalid-cursor. schema: type: string headers: IdempotencyReplayed: description: '"true" when the answer is the stored response of an earlier request with the same Idempotency-Key; absent on the first execution.' schema: type: string enum: ['true'] responses: NotFound: description: not-found (no such resource, or an identifier longer than 128 characters); not stored on a write; the order of a refund may be bound a moment later, so the key is released and the same Idempotency-Key runs again. resource-not-found for a path that carries a NUL character. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' InternalError: description: internal-error (an unexpected failure; the detail never carries the internal message). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' Unprocessable: description: validation-failed (on a write it is not stored; the key is released and the same Idempotency-Key runs again). content: application/problem+json: schema: $ref: '#/components/schemas/Problem' IdempotencyKeyProblem: description: idempotency-key-required (no Idempotency-Key header), idempotency-key-invalid (not 1 to 128 printable ASCII characters) or malformed-request. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' InvalidPageRequest: description: invalid-limit (limit is not an integer from 1 to 500), invalid-cursor (cursor does not decode), unknown-query-parameter (a query parameter the collection does not declare, for example the retired after, offset or nextToken) or malformed-request. content: application/problem+json: schema: $ref: '#/components/schemas/Problem' schemas: Problem: type: object description: RFC 9457 problem details. required: [type, title, status] properties: type: type: string format: uri-reference description: Problem type slug, for example over-refund. title: type: string status: type: integer minimum: 400 maximum: 599 detail: type: string instance: type: string format: uri-reference Allocation: type: object required: [groupNo, amountMinor, state, trackingNumber, trackingNumbers] properties: groupNo: type: integer minimum: 1 maximum: 2147483647 amountMinor: type: integer format: int64 minimum: 0 maximum: 1000000000 state: type: string enum: [PENDING, CAPTURED, RELEASED] trackingNumber: type: string nullable: true description: Tracking number set at capture; null until then. trackingNumbers: type: array description: Tracking numbers of the group's packages; empty until captured. items: type: string AllocationInput: type: object required: [groupNo, amountMinor] properties: groupNo: type: integer minimum: 1 maximum: 2147483647 amountMinor: type: integer format: int64 minimum: 0 maximum: 1000000000 AuthorizeRequest: type: object required: [checkoutSessionId, paymentMethodToken, currency, totalMinor, allocations] properties: checkoutSessionId: type: string minLength: 1 maxLength: 64 pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]*$' paymentMethodToken: type: string minLength: 1 maxLength: 256 description: The PSP token; never a card number. currency: type: string pattern: '^[A-Z]{3}$' totalMinor: type: integer format: int64 minimum: 0 maximum: 1000000000 allocations: type: array minItems: 1 maxItems: 50 items: $ref: '#/components/schemas/AllocationInput' PaymentAuthorization: type: object required: [authorizationId, checkoutSessionId, orderId, state, currency, totalMinor, allocations, providerAuthorizationId] properties: authorizationId: type: string checkoutSessionId: type: string orderId: type: string nullable: true description: Bound on CheckoutCompleted (BindOrderOnCheckoutCompleted). state: type: string enum: [AUTHORIZED, PARTIALLY_CAPTURED, CAPTURED, RELEASED, VOIDED, EXPIRED, DECLINED] currency: type: string pattern: '^[A-Z]{3}$' totalMinor: type: integer format: int64 minimum: 0 allocations: type: array items: $ref: '#/components/schemas/Allocation' providerAuthorizationId: type: string nullable: true description: Null on a DECLINED authorization. expiresAt: type: string format: date-time description: Absent when the authorization has no expiry (DECLINED). declineReason: type: string description: The provider's decline code; present only on a DECLINED authorization. PaymentAuthorizationPage: type: object description: One page of authorizations. nextCursor is absent on the last page. required: [items] properties: items: type: array items: $ref: '#/components/schemas/PaymentAuthorization' nextCursor: type: string description: Opaque cursor of the next page; pass it back as the cursor query parameter. RefundRequest: type: object required: [orderId, amountMinor, reason] properties: orderId: type: string minLength: 1 maxLength: 64 pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]*$' groupNo: type: integer minimum: 0 maximum: 2147483647 description: Shipment group to refund; absent or 0 refunds at the order level. amountMinor: type: integer format: int64 minimum: 1 maximum: 1000000000 reason: type: string enum: [LOST, RETURNED_TO_SENDER, MANUAL] Refund: type: object required: [refundId, authorizationId, orderId, amountMinor, reason, state, attempts] properties: refundId: type: string authorizationId: type: string description: The authorization the money returns through. orderId: type: string groupNo: type: integer minimum: 1 description: Absent for an order-level refund. amountMinor: type: integer format: int64 minimum: 1 reason: type: string enum: [LOST, RETURNED_TO_SENDER, MANUAL] state: type: string enum: [REQUESTED, SUCCEEDED, FAILED] attempts: type: integer minimum: 0 maximum: 5 description: Provider attempts so far (a FAILED refund is retried up to 5). failureCode: type: string description: The provider's failure code; present on a FAILED refund. providerRefundId: type: string description: The provider's refund id; present on a SUCCEEDED refund. RefundPage: type: object description: One page of refunds. nextCursor is absent on the last page. required: [items] properties: items: type: array items: $ref: '#/components/schemas/Refund' nextCursor: type: string description: Opaque cursor of the next page; pass it back as the cursor query parameter.