{"openapi":"3.1.0","info":{"title":"POST /api/v1/credit/payments/preview","version":"1.0.0","description":"Preview a payment"},"servers":[{"url":"https://api.ondayzero.com","description":"Production"}],"paths":{"/api/v1/credit/payments/preview":{"post":{"tags":["credit"],"summary":"Preview a payment","description":"What a payment of `amount_cents` would retire if it were recorded on `as_of`: the interest, fee and principal it clears on each loan, what is left over, and the balances afterwards. It runs the same accrual and allocation as recording a payment and then discards the result, so nothing is written and no event is emitted. Pass `loan_id` to aim it at one loan; the per-loan minimum applies exactly as it does when recording.","operationId":"preview_payment","parameters":[{"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/PaymentPreviewRequest"}}}},"responses":{"201":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessEnvelope_PaymentPreviewResponse_"}}}},"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":"preview_payment_api_v1_credit_payments_preview_post"}}},"components":{"schemas":{"PaymentPreviewAllocation":{"properties":{"loan_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Loan Id","description":"Null under cycle_draw programs; see cycle_id."},"cycle_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Cycle Id","description":"Set under cycle_draw programs only."},"external_settlement_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"External Settlement Id"},"merchant_name":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Merchant Name"},"interest_cents":{"type":"integer","title":"Interest Cents"},"fee_cents":{"type":"integer","title":"Fee Cents"},"principal_cents":{"type":"integer","title":"Principal Cents"},"loan_paid_in_full":{"type":"boolean","title":"Loan Paid In Full","description":"True when nothing would remain owing on this loan or cycle."}},"type":"object","required":["interest_cents","fee_cents","principal_cents","loan_paid_in_full"],"title":"PaymentPreviewAllocation","description":"What the payment would retire on one loan (or one cycle)."},"PaymentPreviewBalances":{"properties":{"total_cents":{"type":"integer","title":"Total Cents"},"principal_cents":{"type":"integer","title":"Principal Cents"},"fee_cents":{"type":"integer","title":"Fee Cents"},"interest_cents":{"type":"integer","title":"Interest Cents"},"credit_balance_cents":{"type":"integer","title":"Credit Balance Cents","description":"Carried-forward credit, including any overpayment."}},"type":"object","required":["total_cents","principal_cents","fee_cents","interest_cents","credit_balance_cents"],"title":"PaymentPreviewBalances","description":"The line's balances as they would stand after the payment."},"PaymentPreviewRequest":{"properties":{"credit_line_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Credit Line Id"},"external_line_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"External Line Id"},"amount_cents":{"type":"integer","exclusiveMinimum":0.0,"title":"Amount Cents"},"as_of":{"anyOf":[{"type":"string","format":"date"},{"type":"null"}],"title":"As Of","description":"The date the payment would count from. Defaults to today (UTC). A date in the future is refused on a live business, exactly as when recording the payment."},"loan_id":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Loan Id","description":"Aim the payment at one loan (the per-row Pay action). Subject to the same per-loan minimum and open-loan rules as recording it."}},"additionalProperties":false,"type":"object","required":["amount_cents"],"title":"PaymentPreviewRequest","description":"A payment to rehearse. Nothing is recorded."},"PaymentPreviewResponse":{"properties":{"credit_line_id":{"type":"string","title":"Credit Line Id"},"as_of":{"type":"string","format":"date","title":"As Of"},"amount_cents":{"type":"integer","title":"Amount Cents"},"allocations":{"items":{"$ref":"#/components/schemas/PaymentPreviewAllocation"},"type":"array","title":"Allocations"},"unapplied_cents":{"type":"integer","title":"Unapplied Cents","description":"The part of the payment that exceeds everything owing."},"balances_after":{"$ref":"#/components/schemas/PaymentPreviewBalances"},"loans_remaining_open":{"type":"integer","title":"Loans Remaining Open","description":"Loans (cycles under cycle_draw) still owing afterwards."}},"type":"object","required":["credit_line_id","as_of","amount_cents","unapplied_cents","balances_after","loans_remaining_open"],"title":"PaymentPreviewResponse","description":"The allocation a payment would get, computed without recording it."},"SuccessEnvelope_PaymentPreviewResponse_":{"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/PaymentPreviewResponse"},{"type":"null"}]}},"additionalProperties":true,"type":"object","title":"SuccessEnvelope[PaymentPreviewResponse]"},"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":[]}]}