{"openapi":"3.1.0","info":{"title":"POST /api/v1/credit/historical-payments/{payment_id}/reversal","version":"1.0.0","description":"Mark a historical payment returned"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/credit/historical-payments/{payment_id}/reversal":{"post":{"tags":["credit"],"summary":"Mark a historical payment returned","description":"Corrects the record of a payment made before cut-over: it reads `reversed` with the date and reason. No balance moves, nothing is posted and no event is appended; a correction to the loans' figures is an adjustment of its own. The bank-feed matcher never reverses a historical payment. Open to any token on a sandbox business; on a live business an operator action (an API token receives `403`).","operationId":"credit_reverse_historical_payment","parameters":[{"name":"payment_id","in":"path","required":true,"schema":{"type":"string","description":"The historical payment.","title":"Payment Id"},"description":"The historical payment."},{"name":"authorization","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Authorization"}},{"name":"x-business-id","in":"header","required":false,"schema":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"X-Business-Id"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HistoricalPaymentReversalRequest"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_HistoricalPaymentResponse_"}}}},"400":{"description":"Bad Request - Invalid input","content":{"application/json":{"example":{"error":"validation_error","message":"Validation failed: due_date: Input should be a valid date","errors":{"due_date":"Input should be a valid date"},"code":"GEN_002","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"},"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"401":{"description":"Unauthorized - Missing or expired token, an MCP OAuth token used against the REST API, or no access to this business","content":{"application/json":{"example":{"error":"unauthorized","message":"Authentication required","code":"AUTH_001","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"},"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden - Insufficient permissions","content":{"application/json":{"example":{"error":"forbidden","message":"You don't have permission to access this resource","code":"AUTH_002","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"},"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Not Found - Resource does not exist","content":{"application/json":{"example":{"error":"not_found","message":"Resource not found","code":"NOT_FOUND_001","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"},"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"},"example":{"error":"validation_error","message":"Validation failed: amount: Input should be a valid integer","errors":{"amount":"Input should be a valid integer"},"code":"GEN_002","request_id":"3f0e7c2a-9b4d-4e1a-8c6f-2d5b7a1e9c30"}}}}},"x-fastapi-operation-id":"credit_reverse_historical_payment_api_v1_credit_historical_payments__payment_id__reversal_post"}}},"components":{"schemas":{"HistoricalPaymentAllocationResponse":{"properties":{"loan_id":{"type":"string","title":"Loan Id","description":"The loan."},"external_settlement_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"External Settlement Id","description":"The loan's original issuer transaction id."},"principal_cents":{"type":"integer","title":"Principal Cents","description":"To principal."},"fee_cents":{"type":"integer","title":"Fee Cents","description":"To the disbursement fee."},"interest_cents":{"type":"integer","title":"Interest Cents","description":"To interest."}},"type":"object","required":["loan_id","principal_cents","fee_cents","interest_cents"],"title":"HistoricalPaymentAllocationResponse","description":"How much of a historical payment went to one loan."},"HistoricalPaymentResponse":{"properties":{"id":{"type":"string","title":"Id","description":"DayZero's id for the record."},"credit_line_id":{"type":"string","title":"Credit Line Id","description":"The line."},"source":{"type":"string","const":"partner_history","title":"Source","description":"Always `partner_history`: attached from the previous system.","default":"partner_history"},"external_payment_id":{"type":"string","title":"External Payment Id","description":"The partner's payment id."},"status":{"type":"string","enum":["settled","reversed"],"title":"Status","description":"`settled`, or `reversed` once an operator marked it returned."},"amount_cents":{"type":"integer","title":"Amount Cents","description":"The payment."},"paid_on":{"type":"string","format":"date","title":"Paid On","description":"When it landed, as the partner dated it."},"method":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Method","description":"How it was paid, if given."},"source_system":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Source System","description":"The previous system, as the file named it."},"allocation_source":{"type":"string","enum":["partner","derived"],"title":"Allocation Source","description":"`partner`: the split is the one the partner's ledger gave it. `derived`: the ledger held no split, so DayZero derived one."},"derivation":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Derivation","description":"How a derived split was worked out, in words."},"allocations":{"items":{"$ref":"#/components/schemas/HistoricalPaymentAllocationResponse"},"type":"array","title":"Allocations","description":"The split, loan by loan."},"reversed_on":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Reversed On","description":"When an operator marked it returned."},"reversal_reason":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Reversal Reason","description":"The reason the operator gave."},"import_batch_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Import Batch Id","description":"The payments file that attached it."},"attached_at":{"type":"string","format":"date-time","title":"Attached At","description":"When it was attached (UTC)."}},"type":"object","required":["id","credit_line_id","external_payment_id","status","amount_cents","paid_on","allocation_source","attached_at"],"title":"HistoricalPaymentResponse","description":"A payment made before cut-over, as the partner's ledger recorded it.\n\nA record, not money DayZero moved: the loans' paid amounts already\ncarried it in from the import, so it changes no balance, is on no\nDayZero statement and on no event."},"HistoricalPaymentReversalRequest":{"properties":{"reversed_on":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"Reversed On","description":"When it was returned. Defaults to today (UTC)."},"reason":{"type":"string","maxLength":500,"minLength":1,"title":"Reason","description":"Why it is marked returned."}},"additionalProperties":false,"type":"object","required":["reason"],"title":"HistoricalPaymentReversalRequest","description":"Mark a historical payment returned. No balance moves."},"SuccessEnvelope_HistoricalPaymentResponse_":{"properties":{"success":{"type":"boolean","title":"Success","default":true},"message":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Message"},"code":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Code"},"data":{"anyOf":[{"$ref":"#/components/schemas/HistoricalPaymentResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[HistoricalPaymentResponse]"},"ErrorResponse":{"title":"ErrorResponse","type":"object","description":"Envelope returned by every non-2xx response. Branch on `code` (stable) rather than `message` (human-readable, may change).","required":["error","message","code"],"properties":{"error":{"type":"string","description":"Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`."},"message":{"type":"string","description":"Human-readable explanation, safe to show to end users."},"code":{"type":"string","description":"Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`)."},"request_id":{"type":"string","description":"Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied."},"errors":{"type":"object","additionalProperties":{"type":"string"},"description":"Field-level validation messages keyed by field name. Present on 400/422 validation failures only."}}}},"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Token","description":"API token authentication. Format: `Bearer dz_...`"}}},"security":[{"BearerAuth":[]}]}