{"openapi":"3.1.0","info":{"title":"Payment Service API","description":"Simulated card payments for orders: test cards, 3-D Secure, payment history. Uses the access tokens issued by the backend. Requests may carry X-Request-Id and a W3C traceparent; every response answers X-Request-Id.","version":"1.0"},"servers":[{"url":"https://awesome.byst.re","description":"Generated server url"}],"tags":[{"name":"Payments (admin)","description":"All payments"},{"name":"Payments","description":"Simulated card payments for orders"}],"paths":{"/api/v1/payments":{"post":{"tags":["Payments"],"summary":"Pay an order by card","description":"Charges the order's amount due (USD) to a test card. The outcome depends on the card number: 4242 4242 4242 4242 and 5555 5555 5555 4444 are captured, 4000 0000 0000 0002 is declined (CARD_DECLINED), 4000 0000 0000 9995 fails with INSUFFICIENT_FUNDS, 4000 0000 0000 3220 requires 3-D Secure (code 123456), 4000 0000 0000 0077 is PROCESSING and settles to CAPTURED, 4000 0000 0000 0119 is PROCESSING and fails with PROVIDER_TIMEOUT, 4000 0000 0000 0259 is captured and its result is delivered to the backend twice. Any other Luhn-valid number is captured. Repeating a request with the same Idempotency-Key and body returns the original payment with 200 and Idempotent-Replayed: true.","operationId":"create","parameters":[{"name":"Idempotency-Key","in":"header","description":"Unique per payment attempt, 8-64 characters of [A-Za-z0-9_-]","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreatePaymentDto"}}},"required":true},"responses":{"201":{"description":"Payment created (any status, including FAILED)","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PaymentDto"}}}},"200":{"description":"Idempotent replay of an earlier request","headers":{"Idempotent-Replayed":{"description":"true","style":"simple","schema":{"type":"string"}},"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PaymentDto"}}}},"400":{"description":"Invalid body, Idempotency-Key, card number (Luhn) or expired card","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"anyOf":[{"$ref":"#/components/schemas/ValidationErrorsDto"},{"$ref":"#/components/schemas/ErrorDto"}]}}}},"404":{"description":"Order not found","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"409":{"description":"Order not payable (not PENDING, already paid, or another payment in progress), \"Order reservation expired\" (the order's reservationExpiresAt has passed), or Idempotency-Key reused with a different body","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"503":{"description":"Backend unavailable","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"401":{"description":"Unauthorized","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"403":{"description":"Role not allowed, or paying another user's order","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}}},"security":[{"bearerAuth":[]}]}},"/api/v1/payments/{id}/3ds":{"post":{"tags":["Payments"],"summary":"Answer the 3-D Secure challenge","description":"Completes a REQUIRES_ACTION payment: code 123456 captures it, any other code fails it with THREE_DS_FAILED.","operationId":"threeDs","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ThreeDsDto"}}},"required":true},"responses":{"200":{"description":"Challenge answered","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PaymentDto"}}}},"400":{"description":"Missing code","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationErrorsDto"}}}},"404":{"description":"Payment not found (or another user's payment)","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"409":{"description":"Payment is not REQUIRES_ACTION","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"401":{"description":"Unauthorized","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"403":{"description":"Role not allowed, or paying another user's order","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}}},"security":[{"bearerAuth":[]}]}},"/api/v1/payments/{id}":{"get":{"tags":["Payments"],"summary":"Get a payment","description":"Returns one of the caller's payments; admins see any payment. Another user's payment is answered 404 like a missing one.","operationId":"get","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Payment found","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PaymentDto"}}}},"404":{"description":"Payment not found (or another user's payment)","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"401":{"description":"Unauthorized","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"403":{"description":"Role not allowed, or paying another user's order","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}}},"security":[{"bearerAuth":[]}]}},"/api/v1/orders/{orderId}/payments":{"get":{"tags":["Payments"],"summary":"List an order's payments","description":"Lists every payment attempt for the caller's order, newest first; admins see any order. Another user's order is answered 404 like a missing one.","operationId":"forOrder","parameters":[{"name":"orderId","in":"path","required":true,"schema":{"type":"integer","format":"int64"}}],"responses":{"200":{"description":"Payments listed","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/PaymentDto"}}}}},"404":{"description":"Order not found (or another user's order)","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"503":{"description":"Backend unavailable","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"401":{"description":"Unauthorized","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"403":{"description":"Role not allowed, or paying another user's order","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}}},"security":[{"bearerAuth":[]}]}},"/api/v1/admin/payments":{"get":{"tags":["Payments (admin)"],"summary":"List all payments","description":"Lists payments of every customer newest first, optionally filtered by status. Negative page is clamped to zero; size is clamped to 1-100.","operationId":"all","parameters":[{"name":"status","in":"query","description":"Only payments in this status","required":false,"schema":{"type":"string","enum":["REQUIRES_ACTION","PROCESSING","CAPTURED","FAILED","PARTIALLY_REFUNDED","REFUNDED","VOIDED"]}},{"name":"page","in":"query","description":"Zero-based page index","required":false,"schema":{"type":"integer","format":"int32","default":0}},{"name":"size","in":"query","description":"Page size, 1-100","required":false,"schema":{"type":"integer","format":"int32","default":20}}],"responses":{"200":{"description":"Payments listed","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PageDtoPaymentDto"}}}},"400":{"description":"Unknown status","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"401":{"description":"Unauthorized","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}},"403":{"description":"Admin role required","headers":{"X-Request-Id":{"$ref":"#/components/headers/X-Request-Id"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorDto"}}}}},"security":[{"bearerAuth":[]}]}}},"components":{"schemas":{"CardDto":{"type":"object","description":"Card details; only brand and last four digits are stored","properties":{"number":{"type":"string","description":"Card number, 12-19 digits; spaces and dashes are ignored","example":"4242 4242 4242 4242","minLength":1,"pattern":"^[0-9][0-9 -]{10,36}[0-9]$"},"expiryMonth":{"type":"integer","format":"int32","description":"Expiry month, 1-12","example":12,"maximum":12,"minimum":1},"expiryYear":{"type":"integer","format":"int32","description":"Four-digit expiry year","example":2030,"maximum":2099,"minimum":2000},"cvc":{"type":"string","description":"Card verification code, 3-4 digits","example":"123","minLength":1,"pattern":"^[0-9]{3,4}$"},"holderName":{"type":"string","description":"Name on the card","example":"Jan Kowalski","maxLength":100,"minLength":0}},"required":["cvc","expiryMonth","expiryYear","holderName","number"]},"CreatePaymentDto":{"type":"object","description":"Pays a PENDING order by card","properties":{"orderId":{"type":"integer","format":"int64","description":"Backend order id","example":42,"exclusiveMinimum":0},"card":{"$ref":"#/components/schemas/CardDto"}},"required":["card","orderId"]},"ValidationErrorsDto":{"type":"object","additionalProperties":{"type":"string","description":"Validation messages keyed by field name; invalid arguments use the error key","example":{"email":"Email should be valid"}},"description":"Validation messages keyed by field name; invalid arguments use the error key","example":{"email":"Email should be valid"},"properties":{"empty":{"type":"boolean"}}},"ErrorDto":{"type":"object","additionalProperties":false,"properties":{"message":{"type":"string","description":"Error message","example":"Error message"}},"required":["message"]},"NextActionDto":{"type":"object","description":"What the customer must do before the payment can complete","properties":{"type":{"type":"string","description":"Action type","example":"THREE_DS_CHALLENGE"},"hint":{"type":"string","description":"Hint for the simulated challenge","example":"Enter code 123456 to approve"}}},"PaymentDto":{"type":"object","description":"A card payment","properties":{"id":{"type":"string","format":"uuid"},"orderId":{"type":"integer","format":"int64"},"status":{"type":"string","enum":["REQUIRES_ACTION","PROCESSING","CAPTURED","FAILED","PARTIALLY_REFUNDED","REFUNDED","VOIDED"]},"amount":{"type":"number","example":126.0},"currency":{"type":"string","example":"USD"},"cardBrand":{"type":"string","enum":["VISA","MASTERCARD","AMEX","OTHER"]},"cardLast4":{"type":"string","example":"4242"},"failureCode":{"type":["string","null"],"description":"CARD_DECLINED, INSUFFICIENT_FUNDS, THREE_DS_FAILED, PROVIDER_TIMEOUT or ORDER_NOT_PAYABLE (voided); null otherwise"},"failureMessage":{"type":["string","null"]},"nextAction":{"type":"null","$ref":"#/components/schemas/NextActionDto","description":"Present while the payment is REQUIRES_ACTION"},"refundedAmount":{"type":"number","example":0.0},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}},"required":["amount","cardBrand","cardLast4","createdAt","currency","id","orderId","refundedAmount","status","updatedAt"]},"ThreeDsDto":{"type":"object","description":"3-D Secure challenge answer","properties":{"code":{"type":"string","description":"One-time code; 123456 approves, anything else fails","example":"123456","maxLength":32,"minLength":0}},"required":["code"]},"PageDtoPaymentDto":{"type":"object","properties":{"content":{"type":"array","items":{"$ref":"#/components/schemas/PaymentDto"}},"pageNumber":{"type":"integer","format":"int32"},"pageSize":{"type":"integer","format":"int32"},"totalElements":{"type":"integer","format":"int64"},"totalPages":{"type":"integer","format":"int32"}}}},"headers":{"X-Request-Id":{"description":"The request's correlation id: a valid incoming X-Request-Id (1-128 characters of [A-Za-z0-9._-]) or a generated one","schema":{"type":"string","maxLength":128}}},"securitySchemes":{"bearerAuth":{"type":"http","name":"bearerAuth","scheme":"bearer","bearerFormat":"JWT"}}}}