> ## 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.

# Create a PIX refund

> Creates a PIX refund (devolução) against an executed transaction. Bacen makes the refund the RECIPIENT's operation, so the caller must be the party that RECEIVED the original payment: the requesting accountId's document has to equal the original payee's document. The original payer cannot refund a payment it sent — that is the MED/fraud path, not this one.

Identify the original with BOTH transactionId (the local UUID) and endToEndId, and it must still be EXECUTED. Partial refunds are allowed and they ACCUMULATE: the amount is checked against the original amount minus everything already refunded, under a row lock on the original, so two concurrent refunds cannot together exceed it. An on-us original is refunded as a synchronous ledger reversal from the refunder to the original payer; a payment received from another institution is submitted to JDPI first, and the refund's own end-to-end id comes back from JD. code is the return reason and is accepted only as BE08, FR01, MD06 or SL02.

⚠️ Send clientRequestId on an on-us refund. Without it a retry posts a SECOND reversal: each attempt mints a fresh refund end-to-end id, so nothing dedups them, and the money moves twice. With it, a retry replays the existing refund as a success. The cross-institution branch is already retry-safe on its own.

Refusals: 422 PIX-0036 when no EXECUTED transaction matches that (endToEndId, transactionId) pair; 400 PIX-0089 when the original is an outgoing payment (only the receiving institution can return what it received); 400 PIX-0087 when the caller is refunding its own outgoing payment; 400 PIX-0088 when the caller is not the original payee; 409 PIX-0032 when this amount plus the prior refunds would exceed the original; 422 PIX-0030 on a non-positive amount; 422 PIX-0108 when the requesting account is not bound to a ledger account; 400 PIX-0061 when accountId or endToEndId is empty, transactionId is not a UUID, or code is outside the four accepted values.



## OpenAPI

````yaml /en/openapi/v3-current/pix.yaml post /v1/refunds
openapi: 3.1.0
info:
  description: Brazilian PIX Direct (DICT + SPI) plugin API.
  title: plugin-br-pix-jd
  version: 1.0.0
servers: []
security:
  - BearerAuth: []
paths:
  /v1/refunds:
    post:
      tags:
        - Refunds
      summary: Create a PIX refund
      description: >-
        Creates a PIX refund (devolução) against an executed transaction. Bacen
        makes the refund the RECIPIENT's operation, so the caller must be the
        party that RECEIVED the original payment: the requesting accountId's
        document has to equal the original payee's document. The original payer
        cannot refund a payment it sent — that is the MED/fraud path, not this
        one.


        Identify the original with BOTH transactionId (the local UUID) and
        endToEndId, and it must still be EXECUTED. Partial refunds are allowed
        and they ACCUMULATE: the amount is checked against the original amount
        minus everything already refunded, under a row lock on the original, so
        two concurrent refunds cannot together exceed it. An on-us original is
        refunded as a synchronous ledger reversal from the refunder to the
        original payer; a payment received from another institution is submitted
        to JDPI first, and the refund's own end-to-end id comes back from JD.
        code is the return reason and is accepted only as BE08, FR01, MD06 or
        SL02.


        ⚠️ Send clientRequestId on an on-us refund. Without it a retry posts a
        SECOND reversal: each attempt mints a fresh refund end-to-end id, so
        nothing dedups them, and the money moves twice. With it, a retry replays
        the existing refund as a success. The cross-institution branch is
        already retry-safe on its own.


        Refusals: 422 PIX-0036 when no EXECUTED transaction matches that
        (endToEndId, transactionId) pair; 400 PIX-0089 when the original is an
        outgoing payment (only the receiving institution can return what it
        received); 400 PIX-0087 when the caller is refunding its own outgoing
        payment; 400 PIX-0088 when the caller is not the original payee; 409
        PIX-0032 when this amount plus the prior refunds would exceed the
        original; 422 PIX-0030 on a non-positive amount; 422 PIX-0108 when the
        requesting account is not bound to a ledger account; 400 PIX-0061 when
        accountId or endToEndId is empty, transactionId is not a UUID, or code
        is outside the four accepted values.
      operationId: createRefund
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RefundBody'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RefundResponse'
          description: Created
        '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
        default:
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Detail'
          description: Error
components:
  schemas:
    RefundBody:
      additionalProperties: false
      properties:
        accountId:
          description: The requesting account (the original payee).
          examples:
            - acc-123
          type: string
        amount:
          description: Refund amount in centavos (must be greater than zero).
          examples:
            - 5000
          format: int64
          type: integer
        clientRequestId:
          description: >-
            Optional client idempotency token. A retry carrying the same value
            replays the existing refund instead of creating a duplicate
            (intra-PSP double-refund protection); omit to opt out.
          examples:
            - req-2025-01-01-abc123
          type: string
        code:
          description: PIX return reason (BE08/FR01/MD06/SL02).
          examples:
            - MD06
          type: string
        description:
          description: Free-text refund description.
          examples:
            - Wrong amount
          type: string
        endToEndId:
          description: The original transaction's end-to-end id.
          examples:
            - E1234567890
          type: string
        transactionId:
          description: The original transaction id (UUID).
          examples:
            - d1f9c0a2-...
          type: string
      required:
        - endToEndId
        - accountId
        - transactionId
        - code
        - amount
      type: object
    RefundResponse:
      additionalProperties: false
      properties:
        accountId:
          description: The refunding account id.
          examples:
            - ext-acc-123
          type: string
        amount:
          description: Refund amount in centavos.
          examples:
            - 5000
          format: int64
          type: integer
        code:
          description: The PIX return reason.
          examples:
            - MD06
          type: string
        description:
          description: Refund description.
          examples:
            - Wrong amount
          type: string
        endToEndId:
          description: The original transaction's end-to-end id.
          examples:
            - E1234567890
          type: string
        endToEndRefundId:
          description: The refund's own end-to-end id.
          examples:
            - D1234567890
          type: string
        id:
          description: The created refund id.
          examples:
            - a2f9c0d1-...
          type: string
        status:
          description: eTransactionStatus name.
          examples:
            - EXECUTED
          type: string
      required:
        - id
        - accountId
        - code
        - endToEndId
        - endToEndRefundId
        - amount
        - status
      type: object
    Detail:
      additionalProperties: false
      properties:
        code:
          description: >-
            Stable, machine-readable domain error code scoped to the emitting
            service (format: <SERVICE>-NNNN).
          examples:
            - ERR-0001
          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

````