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

# Refund a Payin

This endpoint allows you to fully refund a previously authorized Payin transaction.

**Refund Requirements**:

* The refund amount must match the original Payin amount.
* The refund must be sent to the same beneficiary and account used for the original Payin.


## OpenAPI

````yaml openapi/localpayment.json PATCH /api/payin/{externalId}/refund
openapi: 3.1.0
info:
  version: '1.0'
  title: Localpayment
  contact:
    name: Support
    url: mailto:support@localpayment.com
servers:
  - url: https://api.stage.localpayment.com
    description: Stage
security:
  - token: []
paths:
  /api/payin/{externalId}/refund:
    patch:
      summary: Refund a Payin
      operationId: refund-a-payin
      parameters:
        - name: Authorization
          in: header
          description: >-
            Bearer access token for authentication. This token is obtained from
            the [Get Access Token](/reference/get-token) or [Refresh Access
            Token](/reference/refresh-token) endpoints.
          required: true
          schema:
            type: string
        - name: externalId
          in: path
          description: >-
            ID generated on your side for transaction traceability. It must be
            unique and only accepts alphanumeric characters and hyphens (UUID4
            for example).
          required: true
          schema:
            type: string
            pattern: '[a-zA-Z0-9\- ]+'
            examples:
              - 53025bf4-4c87-4b4f-8fea-b47004440f37
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                externalId:
                  type: string
                  description: >-
                    A unique identifier generated by your system to track the
                    transaction (alphanumeric and hyphens). We recommend using
                    UUID4 to ensure uniqueness. **Required only for Pix (Brazil)
                    and cash refunds.**
                beneficiary:
                  type: object
                  description: >-
                    Object containing details about the beneficiary of the
                    refund.  **Required only for Pix (Brazil) and cash
                    refunds.**
                  properties:
                    type:
                      type: string
                      enum:
                        - COMPANY
                        - INDIVIDUAL
                      description: Type of beneficiary (e.g., `INDIVIDUAL`, `COMPANY`).
                    name:
                      type: string
                      description: >-
                        The beneficiary's name. Allowed characters depend on the
                        `type` field: for `individual`, letters (including
                        accented characters), spaces, and dots (`.`); for
                        `company`, the same set plus digits, underscore (`_`),
                        and hyphen (`-`).
                      minLength: 2
                      maxLength: 255
                    lastname:
                      type: string
                      description: >-
                        The beneficiary's last name. Required when `type` is
                        `individual` and ignored when `type` is `company`.
                        Allowed characters depend on `type`: for `individual`,
                        letters (including accented characters), spaces, and
                        dots (`.`); for `company`, the same set plus digits,
                        underscore (`_`), and hyphen (`-`).
                      minLength: 2
                      maxLength: 255
                    document:
                      type: object
                      properties:
                        type:
                          type: string
                          description: >-
                            The type of [identity document
                            types](/reference/identity-document-types), such as
                            a National Identity Number, Social Security Number,
                            or Driver's License, depending on the country of
                            issuance.
                        id:
                          type: string
                          description: >-
                            Identity document number (usually a number). This
                            must be a valid number according to the rules for
                            the specific document type.
                    bank:
                      type: object
                      description: Beneficiary's bank details.
                      properties:
                        name:
                          type: string
                          description: Bank name.
                        code:
                          type: string
                          description: 'Bank code. '
                        account:
                          type: object
                          description: 'Beneficiary''s bank account details. '
                          properties:
                            type:
                              type: string
                              description: 'Type of bank account (e.g., `C`, `S`). '
                            number:
                              type: string
                              description: Bank account number.
                          required:
                            - type
                            - number
                        branch:
                          type: object
                          description: '**Only Brazil.** '
                          properties:
                            code:
                              type: string
                              description: Branch code (1 to 5 digits).
                            name:
                              type: string
                              description: 'Branch name. '
                      required:
                        - name
                        - code
                        - account
                  required:
                    - type
                    - name
                    - bank
                comment:
                  type: string
                  description: >-
                    Comment or note providing additional information about the
                    refund transaction.
              required:
                - externalId
                - beneficiary
              x-examples:
                Example 1:
                  comment: Refund API VA
                  beneficiary:
                    type: Type
                    name: Name
                    lastname: LastName
                    document:
                      type: DocumentType
                      id: DocumentId
                    bank:
                      name: BankName
                      code: Code
                      account:
                        type: BankAccountType
                        number: AccountNumber
            examples:
              Pix (Brazil) Refund:
                value:
                  comment: Pix refund
                  beneficiary:
                    type: INDIVIDUAL
                    name: John
                    lastname: Doe
                    document:
                      type: DocumentType
                      id: DocumentId
                    bank:
                      name: BankName
                      code: Code
                      account:
                        type: BankAccountType
                        number: AccountNumber
              902 - The payin was refunded:
                value:
                  externalId: e9407459-1ecc-4e18-800b-4bbae006afe2
                  internalId: 3e90d58c-8d3a-4c75-916e-a6d0add4f3b3
                  status:
                    code: '902'
                    description: REFUNDED
                    detail: The payin was refunded
              Cash refund:
                value:
                  comment: Cash refund
                  beneficiary:
                    type: INDIVIDUAL
                    name: John
                    lastname: Doe
                    document:
                      type: DocumentType
                      id: DocumentId
                    bank:
                      name: BankName
                      code: Code
                      account:
                        type: BankAccountType
                        number: AccountNumber
              Capture refund:
                value:
                  comment: Credit Card refund
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  externalId:
                    type: string
                    description: >-
                      A unique identifier generated by your system to track the
                      transaction (alphanumeric and hyphens). We recommend using
                      UUID4 to ensure uniqueness.
                  internalId:
                    type: string
                    description: Localpayment transaction identifier.
                  status:
                    type: object
                    title: status
                    description: Operation status.
                    properties:
                      code:
                        type: string
                        description: >-
                          [Status
                          code](/reference/transaction-status-error-codes).
                        examples:
                          - '902'
                      description:
                        type: string
                        description: >-
                          [Status
                          description](/reference/transaction-status-error-codes).
                        examples:
                          - REFUNDED
                      detail:
                        type: string
                        description: Additional status information.
                        examples:
                          - The payin was refunded
                x-examples:
                  Example 1:
                    externalId: '{{ExternalId}}'
                    internalId: '{{InternalId}}'
                    status:
                      code: '902'
                      description: REFUNDED
                      detail: The payin was refunded
              examples:
                902 - The payin was refunded.:
                  value:
                    externalId: e36ef929-c2d4-fcf0-b30c-99dc51798f4b
                    internalId: c09095fb-6a0e-47af-9f43-3d9452b0f290
                    status:
                      code: '902'
                      description: REFUNDED
                      detail: The payin was refunded
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    description: Operation status.
                    properties:
                      code:
                        type: string
                        description: >-
                          [Status
                          code](/reference/transaction-status-error-codes).
                      description:
                        type: string
                        description: Status description.
                      detail:
                        type: string
                        description: Additional status information.
                x-examples:
                  Example 1:
                    status:
                      code: '400'
                      description: ERROR
                      detail: Invalid operation
              examples:
                400 - Invalid operation:
                  value:
                    status:
                      code: '400'
                      description: ERROR
                      detail: Invalid operation
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    description: Additional information of the response.
                  code:
                    type: string
                    description: Status code.
                  messages:
                    type: array
                    description: Message list.
                    items:
                      type: object
                      properties:
                        token_class:
                          type: string
                          description: Token class.
                        token_type:
                          type: string
                          description: Token type.
                        message:
                          type: string
                          description: Message with additional information.
                x-examples:
                  Example 1:
                    detail: Given token not valid for any token type
                    code: token_not_valid
                    messages:
                      - token_class: AccessToken
                        token_type: access
                        message: Token is invalid or expired
              examples:
                401 - Token is invalid or expired:
                  value:
                    detail: Given token not valid for any token type
                    code: token_not_valid
                    messages:
                      - token_class: AccessToken
                        token_type: access
                        message: Token is invalid or expired
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: object
                    title: status
                    description: Operation status.
                    properties:
                      code:
                        type: string
                        description: >-
                          [Status
                          code](/reference/transaction-status-error-codes).
                      description:
                        type: string
                        description: Status description.
                      detail:
                        type: string
                        description: Additional status information.
                x-examples:
                  Example 1:
                    status:
                      code: '404'
                      description: ERROR
                      detail: Payin not found
              examples:
                404 - Payin not found.:
                  value:
                    status:
                      code: '404'
                      description: ERROR
                      detail: Payin not found
      security:
        - token: []
      servers:
        - url: https://api.stage.localpayment.com
          description: Stage
components:
  securitySchemes:
    token:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.