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

# 申请退款

> 对指定的支付交易申请全额退款。退款为异步处理——PSP 处理完成后，将通过 webhook `refund_completed` 送达确认。

**所需权限：** `REFUND:WRITE` 或 `FULL_ACCESS`



## OpenAPI

````yaml openapi.cn.json POST /transactions/{id}/refund
openapi: 3.0.0
info:
  title: Brazil Pix API
  description: Brazil Pix Payment API documentation
  version: '1.0'
  contact: {}
servers:
  - url: https://api.brazilpix.com/v2
security: []
paths:
  /transactions/{id}/refund:
    post:
      tags:
        - External API - Transactions
      summary: 申请交易退款
      description: |-
        对指定的支付交易申请全额退款。退款为异步处理——PSP 处理完成后，将通过 webhook `refund_completed` 送达确认。

        **所需权限：** `REFUND:WRITE` 或 `FULL_ACCESS`
      operationId: ExternalTransactionsController_requestRefund
      parameters:
        - name: id
          required: true
          in: path
          description: 待退款的支付交易 ID
          schema:
            type: string
            format: uuid
        - $ref: '#/components/parameters/SubAccount'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RequestRefundInput'
      responses:
        '201':
          description: 退款申请成功。在通过 webhook 确认之前，状态为 PENDING。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RequestRefundOutput'
        '400':
          description: Bad Request - 交易无法退款（已退款、已过期、状态无效等）
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestErrorResponse'
        '401':
          description: Unauthorized - Authentication required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorResponse'
        '404':
          description: Not Found - 未找到交易
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorResponse'
      security:
        - bearerAuth: []
components:
  parameters:
    SubAccount:
      name: X-Sub-Account
      in: header
      required: false
      description: >-
        执行操作的子账户的 reference。省略时，操作在主账户上执行；保留值 `principal` 同样解析为主账户，等同于省略该请求头。除
        `POST /auth` 和 `/sub-accounts` 自身的端点（始终在主账户上操作）外，所有端点均接受该请求头。


        可能的错误：`404 SUB_ACCOUNT_NOT_FOUND`、`403 SUB_ACCOUNT_FORBIDDEN`、`403
        SUB_ACCOUNT_SUSPENDED`。


        要求凭证已启用**子账户访问**（设置 → 集成 → API 凭证）。该项默认关闭，任何权限都无法替代，`FULL_ACCESS`
        也不例外：未启用时响应为 `403 SUB_ACCOUNT_FORBIDDEN`。
      schema:
        type: string
        pattern: ^[a-z0-9][a-z0-9_-]{1,31}$
        example: loja-centro
  schemas:
    RequestRefundInput:
      type: object
      properties:
        reason:
          type: string
          maxLength: 255
          description: 退款原因（可选，最多 255 个字符）
          example: Cliente solicitou cancelamento
    RequestRefundOutput:
      type: object
      properties:
        originalTransactionId:
          type: string
          format: uuid
          description: 被退款的原始交易 ID
        pspProvider:
          type: string
          description: 处理退款的 PSP
        pspRefundTransactionId:
          type: string
          description: PSP 侧的退款交易 ID
        status:
          type: string
          enum:
            - PENDING
            - CONFIRMED
            - ERROR
          description: PSP 返回的状态。PENDING 表示退款已受理但尚未确认——确认将通过 webhook `refund_completed` 送达。
          example: PENDING
      required:
        - originalTransactionId
        - pspProvider
        - pspRefundTransactionId
        - status
    BadRequestErrorResponse:
      type: object
      properties:
        statusCode:
          type: number
          example: 400
        error:
          type: string
          example: BadRequest
        message:
          type: string
          example: name must be longer than or equal to 2 characters
        details:
          type: object
        timestamp:
          type: string
          example: '2025-12-15T22:00:00.000Z'
        traceId:
          type: string
      required:
        - statusCode
        - error
        - message
        - timestamp
    UnauthorizedErrorResponse:
      type: object
      properties:
        statusCode:
          type: number
          example: 401
        error:
          type: string
          example: Unauthorized
        message:
          type: string
          example: Authentication token is required
        details:
          type: object
        timestamp:
          type: string
          example: '2025-12-15T22:00:00.000Z'
        traceId:
          type: string
      required:
        - statusCode
        - error
        - message
        - timestamp
    NotFoundErrorResponse:
      type: object
      properties:
        statusCode:
          type: number
          example: 404
        error:
          type: string
          example: NotFound
        message:
          type: string
          example: Resource with id 550e8400-e29b-41d4-a716-446655440000 not found
        details:
          type: object
          example:
            resource: Example
            id: 550e8400-e29b-41d4-a716-446655440000
        timestamp:
          type: string
          example: '2025-12-15T22:00:00.000Z'
        traceId:
          type: string
      required:
        - statusCode
        - error
        - message
        - timestamp
    InternalServerErrorResponse:
      type: object
      properties:
        statusCode:
          type: number
          example: 500
        error:
          type: string
          example: InternalError
        message:
          type: string
          example: An unexpected error occurred
        details:
          type: object
        timestamp:
          type: string
          example: '2025-12-15T22:00:00.000Z'
        traceId:
          type: string
          example: 2771463d58840c8e116dc6dda1e1e5d0
      required:
        - statusCode
        - error
        - message
        - timestamp
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 通过 POST /auth（client_id + client_secret）获取的访问令牌。有效期 300 秒。

````

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