> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Reverse loan account transaction

> Creates an immutable compensating transaction and preserves reversal lineage. The reversal's effective date is DERIVED from the payment being reversed and is not accepted in the request; a body carrying `effectiveDate` is refused 422. Idempotency is enforced in the use case via the X-Request-ID header (X-Idempotency fallback): a reused request ID with different facts yields 409. A malformed UUID yields 422; an unknown transaction yields 404; a payment already reversed yields 409. A reversal is REFUSED 422 when the loan account carries a payment or a schedule version whose effective timestamp is strictly later than the reversed payment's. The problem document names which fact blocks, in `errors[0].message`: `REVERSAL_REFUSED_LATER_PAYMENT` (the borrower paid again — use the compensating-adjustment path), `REVERSAL_REFUSED_LATER_SCHEDULE_VERSION` (the schedule was re-agreed — the remedy is a new schedule version), or `REVERSAL_REFUSED_LATER_FACTS_EXIST` (both).



## OpenAPI

````yaml /es/openapi/v3-current/lender.yaml post /api/v1/loan-accounts/{id}/transactions/{transactionId}/reverse
openapi: 3.1.0
info:
  contact:
    email: contact@lerian.studio
    name: Lerian Studio
    url: https://lerian.studio
  description: >-
    Code-first OpenAPI 3.1 surface for the Lender service. Routes that move
    money are at-most-once per X-Idempotency: when one answers 5xx, the
    X-Idempotency-Fenced response header says whether that key is now refusing
    resends (true) or free to retry (false or absent). See
    docs/contracts/money-route-idempotency.md.
  license:
    name: Lerian Studio General License
  title: Lender API
  version: 1.0.0
servers:
  - url: https://lender.sandbox.lerian.net
security:
  - BearerAuth: []
tags:
  - description: >-
      Caller session projection: validated subject and effective permissions for
      the presented token.
    name: Session
  - description: >-
      Ledger accounting operations: journal entries and accrual postings for
      loan accounts.
    name: Accounting
  - description: >-
      Loan application intake and lifecycle: submission, decisioning, and
      status.
    name: LoanApplications
  - description: >-
      Loan product catalog: definition, versioning, and activation of lending
      products.
    name: LoanProducts
  - description: >-
      Loan account servicing operations: balances, schedules, and account-level
      actions.
    name: Loan Accounts
  - description: >-
      Portfolio dashboard read operations: aggregated portfolio and performance
      views.
    name: Dashboard
  - description: >-
      Jurisdiction registry: supported jurisdiction profiles and their
      capabilities.
    name: Jurisdictions
  - description: >-
      Jurisdiction-specific loan application operations (Brazil origination
      surface).
    name: Loan Applications
  - description: >-
      Tax computation operations for jurisdiction-specific lending (e.g. Brazil
      IOF).
    name: Tax
  - description: >-
      Brazil consignado privado operations: contract lifecycle, exclusion
      repair, and compensating adjustments.
    name: Consignado
  - description: >-
      Credit-instrument document template registry: versioned drafting and
      publication of CCB clausulado.
    name: DocumentTemplates
paths:
  /api/v1/loan-accounts/{id}/transactions/{transactionId}/reverse:
    post:
      tags:
        - Loan Accounts
      summary: Reverse loan account transaction
      description: >-
        Creates an immutable compensating transaction and preserves reversal
        lineage. The reversal's effective date is DERIVED from the payment being
        reversed and is not accepted in the request; a body carrying
        `effectiveDate` is refused 422. Idempotency is enforced in the use case
        via the X-Request-ID header (X-Idempotency fallback): a reused request
        ID with different facts yields 409. A malformed UUID yields 422; an
        unknown transaction yields 404; a payment already reversed yields 409. A
        reversal is REFUSED 422 when the loan account carries a payment or a
        schedule version whose effective timestamp is strictly later than the
        reversed payment's. The problem document names which fact blocks, in
        `errors[0].message`: `REVERSAL_REFUSED_LATER_PAYMENT` (the borrower paid
        again — use the compensating-adjustment path),
        `REVERSAL_REFUSED_LATER_SCHEDULE_VERSION` (the schedule was re-agreed —
        the remedy is a new schedule version), or
        `REVERSAL_REFUSED_LATER_FACTS_EXIST` (both).
      operationId: reverseLoanAccountTransaction
      parameters:
        - description: Loan account identifier (UUID).
          in: path
          name: id
          required: true
          schema:
            description: Loan account identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            format: uuid
            type: string
        - description: Original repayment transaction identifier (UUID).
          in: path
          name: transactionId
          required: true
          schema:
            description: Original repayment transaction identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440001
            format: uuid
            type: string
        - description: >-
            Canonical idempotency request ID. Falls back to X-Idempotency when
            absent.
          in: header
          name: X-Request-ID
          schema:
            description: >-
              Canonical idempotency request ID. Falls back to X-Idempotency when
              absent.
            examples:
              - 550e8400-e29b-41d4-a716-446655440010
            type: string
        - description: Fallback idempotency request ID used when X-Request-ID is absent.
          in: header
          name: X-Idempotency
          schema:
            description: Fallback idempotency request ID used when X-Request-ID is absent.
            examples:
              - 550e8400-e29b-41d4-a716-446655440011
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReverseRepaymentHumaRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReverseRepaymentHumaBody'
          description: OK
          headers:
            X-Idempotency-Replayed:
              schema:
                description: >-
                  Set to "true" when this response replays an earlier request
                  with the same idempotency key; absent on a first execution.
                type: string
        '401':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Unauthorized
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Forbidden
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Unprocessable Entity
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Internal Server Error
        '503':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Service Unavailable
        default:
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Error
components:
  schemas:
    ReverseRepaymentHumaRequest:
      additionalProperties: false
      properties:
        jurisdictionCode:
          description: Optional jurisdiction code.
          examples:
            - BR
          type: string
        profileVersion:
          description: Product profile version applied to the reversal.
          examples:
            - 1.0.0
          minLength: 1
          type: string
        reason:
          description: Operator-supplied reversal reason.
          minLength: 1
          type: string
      required:
        - reason
        - profileVersion
      type: object
    ReverseRepaymentHumaBody:
      additionalProperties: false
      properties:
        amount:
          description: Reversed amount (2 d.p. string).
          examples:
            - '125.00'
          type: string
        destination:
          description: >-
            Where the reversed money went: 'revived' (the debt returned to this
            contract, its schedule is back) or 'returned_payment_receivable'
            (the contract stayed discharged and the money opened a separate debt
            of the borrower, outside the credit operation and with no payroll
            deduction behind it).
          enum:
            - revived
            - returned_payment_receivable
          examples:
            - revived
          type: string
        effectiveDate:
          description: ISO-8601 effective date of the reversal.
          examples:
            - '2026-06-14'
          type: string
        jurisdictionCode:
          description: Jurisdiction code applied to the reversal.
          examples:
            - BR
          type: string
        loanAccountId:
          description: Loan account UUID.
          examples:
            - 550e8400-e29b-41d4-a716-446655440000
          type: string
        originalTransactionId:
          description: Reversed original transaction UUID.
          examples:
            - 550e8400-e29b-41d4-a716-446655440001
          type: string
        profileVersion:
          description: Product profile version applied to the reversal.
          examples:
            - 1.0.0
          type: string
        reason:
          description: Operator-supplied reversal reason.
          type: string
        requestId:
          description: Idempotency request ID echoed from the request.
          examples:
            - 550e8400-e29b-41d4-a716-446655440010
          type: string
        returnedPaymentReceivableId:
          description: >-
            Identifier of the returned-payment receivable this reversal opened.
            Present only when destination is 'returned_payment_receivable'.
          examples:
            - 550e8400-e29b-41d4-a716-446655440003
          format: uuid
          type: string
        transactionId:
          description: Compensating reversal transaction UUID.
          examples:
            - 550e8400-e29b-41d4-a716-446655440002
          type: string
      required:
        - transactionId
        - originalTransactionId
        - loanAccountId
        - reason
        - profileVersion
        - effectiveDate
        - amount
        - destination
      type: object
    Detail:
      additionalProperties: false
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          type: string
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: '#/components/schemas/ErrorDetail'
          type:
            - array
            - 'null'
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: >-
            A short, human-readable summary of the problem type. This value
            should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
        upstream:
          $ref: '#/components/schemas/Upstream'
          description: >-
            RFC 9457 extension member: the error a proxied third-party provider
            reported. Absent unless the emitting service explicitly surfaced
            one.
      type: object
    ErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: >-
            Where the error occurred, e.g. 'body.items[3].tags' or
            'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        value:
          description: The value at the given location
      type: object
    Upstream:
      additionalProperties: false
      properties:
        code:
          description: The upstream provider's own error code, verbatim.
          examples:
            - E4001
          type: string
        message:
          description: >-
            The upstream provider's own error message, verbatim (bounded, never
            its raw response body).
          examples:
            - account not found at provider
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: JWT bearer token issued by the identity provider.
      scheme: bearer
      type: http

````