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

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# 通过交易取消或退款（两张卡）

> 如果双卡支付中的一张卡仅完成授权，则取消该卡；如果已扣款，则对其退款。

此请求使用来自 `payment_method.payment_methods[].transactions` 的该卡交易 `id`，对通过[创建支付（两张卡）](https://docs.y.uno/zh-hans/reference/payments/create-payment-v2.md)创建的支付中的一张卡执行操作：

* 如果该卡仅完成授权，则**取消**该卡。
* 如果该卡已扣款，则**退款**该卡。退款上限为该卡金额减去其已退款金额。

响应为 `201`，支付采用 v2 结构。

> [!WARNING]
>
> 当一张卡存在未结的拒付时，退款会被拒绝，并返回 `INVALID_STATUS`。

此请求需要 `X-Idempotency-Key`。详情请参阅[身份验证](https://docs.y.uno/zh-hans/reference/getting-started/authentication.md#idempotency)。


## OpenAPI

````yaml openapi/zh-hans/payments/cancel-or-refund-payment-with-transaction-v2.json POST /payments/{payment_id}/transactions/{transaction_id}/cancel-or-refund
openapi: 3.1.0
info:
  title: payments-v2
  version: 2.0.0
servers:
  - url: https://api-sandbox.y.uno/v2
    description: Sandbox
  - url: https://api.y.uno/v2
    description: Production (US)
security:
  - sec0: []
    sec1: []
paths:
  /payments/{payment_id}/transactions/{transaction_id}/cancel-or-refund:
    post:
      summary: 通过交易取消或退款（两张卡）
      description: 如果卡仅获得授权，则取消该卡；如果已扣款，则对其退款。
      operationId: cancel-or-refund-payment-with-transaction-v2
      parameters:
        - name: X-Idempotency-Key
          in: header
          required: true
          description: >-
            此请求的唯一键。每个 v2 支付请求都必须提供。结果不明确时，请使用相同的键重试。缺少该键时，请求会被拒绝并返回 `400
            INVALID_PARAMETERS`："The header 'x-idempotency-key' is required."
          schema:
            type: string
            format: uuid
        - name: payment_id
          in: path
          required: true
          description: '`POST /v2/payments` 返回的支付 `id`。'
          schema:
            type: string
            format: uuid
        - name: transaction_id
          in: path
          required: true
          description: 要操作的卡交易的 `id`，来自 `payment_method.payment_methods[].transactions[]`。
          schema:
            type: string
            format: uuid
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required: []
              properties:
                description:
                  type: string
                  description: 取消或退款的描述（MAX 255；MIN 3）。
                reason:
                  type: string
                  description: >-
                    操作原因。可能的值为 `DUPLICATE`、`FRAUDULENT` 和
                    `REQUESTED_BY_CUSTOMER`。
                  enum:
                    - DUPLICATE
                    - FRAUDULENT
                    - REQUESTED_BY_CUSTOMER
                merchant_reference:
                  type: string
                  description: >-
                    由商户定义的支付交易标识。如果未定义 merchant_reference，则该支付的
                    merchant_order_id 将与交易关联（MAX 255；MIN 3）。
                amount:
                  type: object
                  description: 可选。在该卡上退款的金额。
                  required:
                    - currency
                    - value
                  properties:
                    currency:
                      type: string
                      description: ISO 4217 货币代码（3 个字符）。
                      example: BRL
                    value:
                      type: number
                      description: 以主单位表示的金额（0.0001 的倍数）。
                      example: 300
                customer_payer:
                  type: object
                  description: 指定支付的客户对象。
                  properties:
                    first_name:
                      type: string
                      description: 客户的名（最大 255；最小 3）。
                    last_name:
                      type: string
                      description: 客户的姓（最大 255；最小 3）。
                    gender:
                      type: string
                      description: >-
                        客户的性别（MAX 2；MIN 1）。<br/>- M=男<br/>- F=女<br/>-
                        NB=非二元性别<br/>- NA=不适用<br/>- NK=未知<br/>- U=未定义。
                      enum:
                        - M
                        - F
                        - NB
                        - NA
                        - NK
                        - U
                    date_of_birth:
                      type: string
                      description: 客户的出生日期，格式为 `YYYY-MM-DD`（长度：10）。
                    email:
                      type: string
                      description: 客户的电子邮件（最大 255；最小 3）。
                    nationality:
                      type: string
                      description: >-
                        客户的国籍（MAX 2；MIN 2；[ISO
                        3166-1](/zh-hans/reference/country-reference)）。
                    document:
                      type: object
                      description: 指定客户的证件对象，包括证件号码和类型。
                      properties:
                        document_number:
                          type: string
                          description: 客户的证件号码（MAX 40；MIN 3）
                        document_type:
                          type: string
                          description: >-
                            客户的证件类型（MAX 6；MIN
                            2）。更多详情请访问[证件类型列表](/zh-hans/reference/country-reference)。
                          enum:
                            - DNI
                            - CI
                            - LC
                            - LE
                            - CUIT
                            - CUIL
                            - PAS
                            - CPF
                            - RG
                            - CNH
                            - CNPJ
                            - RUT
                            - RUN
                            - CC
                            - CE
                            - NIT
                            - DUI
                            - PIC
                            - DPI
                            - IFR
                            - INE
                            - CP
                            - RFC
                            - CURP
                            - CIP
                            - CIC
                            - CUI
                            - RUC
                    phone:
                      type: object
                      description: 指定客户的电话对象。
                      properties:
                        country_code:
                          type: string
                          description: 客户电话的国家/地区区号（MAX 3；MIN 1）。
                        number:
                          type: string
                          description: 客户的电话号码，不含国家/地区区号（最大 32；最小 1）。
                    billing_address:
                      type: object
                      description: 指定客户的账单地址对象。
                      properties:
                        address_line_1:
                          type: string
                          description: 客户的主要账单地址行（最大 255；最小 3）。
                        address_line_2:
                          type: string
                          description: 客户的次要账单地址行（MAX 255；MIN 3）。
                        city:
                          type: string
                          description: 账单地址所在的城市（最大 255；最小 3）。
                        country:
                          type: string
                          description: >-
                            账单地址所属的国家/地区（MAX 2；MIN 2；[ISO
                            3166-1](https://docs.y.uno/zh-hans/reference/customers/the-customer-object#country-code-list-iso-3166-1)）。
                          enum:
                            - AR
                            - BO
                            - BR
                            - CL
                            - CO
                            - CR
                            - EC
                            - SV
                            - GT
                            - HN
                            - MX
                            - NI
                            - PA
                            - PY
                            - PE
                            - US
                            - UY
                        state:
                          type: string
                          description: 账单地址所在的州（最大 255；最小 3）。
                        zip_code:
                          type: string
                          description: 账单地址的邮政编码（最大 10；最小 5）。
                    shipping_address:
                      type: object
                      description: 指定客户的收货地址对象。
                      properties:
                        address_line_1:
                          type: string
                          description: 客户的主要收货地址行（最大 255；最小 3）。
                        address_line_2:
                          type: string
                          description: 客户的次要收货地址行（MAX 255；MIN 3）。
                        city:
                          type: string
                          description: 收货地址所在的城市（最大 255；最小 3）。
                        country:
                          type: string
                          description: >-
                            收货地址所属的国家/地区（MAX 2；MIN 2；[ISO
                            3166-1](https://docs.y.uno/zh-hans/reference/customers/the-customer-object#country-code-list-iso-3166-1)）。
                          enum:
                            - AR
                            - BO
                            - BR
                            - CL
                            - CO
                            - CR
                            - EC
                            - SV
                            - GT
                            - HN
                            - MX
                            - NI
                            - PA
                            - PY
                            - PE
                            - US
                            - UY
                        state:
                          type: string
                          description: 收货地址所在的州（最大 255；最小 3）。
                        zip_code:
                          type: string
                          description: 收货地址的邮政编码（最大 10；最小 5）。
                payment_method:
                  type: object
                  description: 指定支付所用的支付方式对象。
                  properties:
                    detail:
                      type: object
                      description: 指定支付方式详情对象。
                      properties:
                        bank_transfer:
                          type: object
                          description: 指定银行转账支付方式的详细信息。
                          properties:
                            account_type:
                              type: string
                              description: 银行账户类型（MAX 255；MIN 3）
                              enum:
                                - CHECKINGS
                                - SAVINGS
                            bank_name:
                              type: string
                              description: 银行名称（MAX 255；MIN 3）
                            bank_id:
                              type: string
                              description: 银行 ID（MAX 255；MIN 3）
                            beneficiary_name:
                              type: string
                              description: 账户持有人姓名（MAX 255；MIN 3）
                            bank_account:
                              type: string
                              description: 银行账号（MAX 255；MIN 3）
                            beneficiary_document_type:
                              type: string
                              description: 账户持有人的证件类型（MAX 255；MIN 3）
                            beneficiary_document:
                              type: string
                              description: 账户持有人的证件号码（MAX 255；MIN 3）
                            reference:
                              type: string
                              description: 用户的参考代码（MAX 255；MIN 1）
                            bank_account_mask_number:
                              type: string
                              description: 与银行转账关联的掩码银行账号（例如 ****6789）。这是账户数据，不是授权书数据。
                            mandate:
                              type: object
                              description: 直接借记授权书详情，适用于使用授权书的银行转账方式（例如 ACH、SEPA、BACS、PAD）。
                              properties:
                                id:
                                  type: string
                                  description: 授权书标识符，由支付服务提供商提供。
                                info:
                                  type: string
                                  description: Free-text mandate information.
                                received_status:
                                  type: string
                                  description: 表示是否已收到授权书的服务提供商状态。按支付服务提供商提供的原样转发。
                                existing_status:
                                  type: string
                                  description: 现有授权书的服务提供商状态。按支付服务提供商提供的原样转发。
                                created_at:
                                  type: string
                                  format: date-time
                                  description: 授权书的创建日期和时间（ISO 8601）。
                                updated_at:
                                  type: string
                                  format: date-time
                                  description: 授权书的最后更新日期和时间（ISO 8601）。
      responses:
        '201':
          description: 操作后的支付，采用 v2 结构
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaymentV2'
              examples:
                One card refunded:
                  value:
                    id: 7c1b6e2a-5f3d-4a8e-9b21-3e4f5a6b7c8d
                    account_id: 493e9374-510a-4201-9e09-de669d75f256
                    description: Order paid with two cards
                    country: BR
                    status: SUCCEEDED
                    sub_status: PARTIALLY_REFUNDED
                    merchant_order_id: order-10045
                    created_at: '2026-10-27T14:02:11.120Z'
                    updated_at: '2026-10-27T14:02:12.300Z'
                    split_payment_methods: true
                    payment_methods_count: 2
                    sdk_action_required: false
                    amount:
                      currency: BRL
                      value: 300
                    checkout:
                      session: null
                    payment_method:
                      capture: true
                      account_updater: false
                      payment_methods:
                        - sequence: 1
                          type: CARD
                          amount:
                            currency: BRL
                            value: 200
                          transactions:
                            - id: d2a4f6b8-1c3e-4a5b-8d7f-9e0a1b2c3d4e
                              type: PURCHASE
                              status: SUCCEEDED
                              category: CARD
                              amount: 200
                              provider_id: YUNO_TEST_PAYMENT_GATEWAY
                              response_code: SUCCEEDED
                              response_message: Transaction successful
                              reason: null
                              description: null
                              merchant_reference: null
                              three_d_secure_action_required: false
                              created_at: '2026-10-27T14:02:11.402Z'
                              updated_at: '2026-10-27T14:02:12.118Z'
                            - id: b6e8d0f2-5a7c-4e9f-8b1d-3c4d5e6f7a8b
                              type: REFUND
                              status: SUCCEEDED
                              category: CARD
                              amount: 200
                              provider_id: YUNO_TEST_PAYMENT_GATEWAY
                              response_code: SUCCEEDED
                              response_message: Transaction successful
                              reason: null
                              description: null
                              merchant_reference: null
                              three_d_secure_action_required: false
                              created_at: '2026-10-27T14:02:11.402Z'
                              updated_at: '2026-10-27T14:02:12.118Z'
                        - sequence: 2
                          type: CARD
                          amount:
                            currency: BRL
                            value: 100
                          transactions:
                            - id: e3b5a7c9-2d4f-4b6c-9e8a-0f1b2c3d4e5f
                              type: PURCHASE
                              status: SUCCEEDED
                              category: CARD
                              amount: 100
                              provider_id: YUNO_TEST_PAYMENT_GATEWAY
                              response_code: SUCCEEDED
                              response_message: Transaction successful
                              reason: null
                              description: null
                              merchant_reference: null
                              three_d_secure_action_required: false
                              created_at: '2026-10-27T14:02:11.402Z'
                              updated_at: '2026-10-27T14:02:12.118Z'
                    customer_payer:
                      id: cfae0941-7234-427a-a739-ef4fce966c79
                      first_name: Ana
                      last_name: Souza
                      email: ana.souza@example.com
                    workflow: DIRECT
                    callback_url: https://merchant.example.com/checkout/return
                    metadata: []
        '400':
          description: >-
            无效请求。缺少幂等键或金额超过可操作的上限时返回 `INVALID_PARAMETERS`；卡无法执行该操作时返回
            `INVALID_STATUS`，例如卡有未结拒付时退款，或支付处于 `REFUND_RETRY_IN_PROCESS` 或
            `CANCEL_RETRY_IN_PROCESS` 时捕获或取消。
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
              examples:
                Missing idempotency key:
                  value:
                    code: INVALID_PARAMETERS
                    messages:
                      - The header 'x-idempotency-key' is required.
        '401':
          description: 凭证无效
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                  messages:
                    type: array
                    items:
                      type: string
              example:
                code: INVALID_CREDENTIALS
                messages:
                  - Invalid credentials
components:
  schemas:
    PaymentV2:
      type: object
      description: 由两张卡共同支付的支付。
      properties:
        id:
          type: string
          format: uuid
        account_id:
          type: string
          format: uuid
        description:
          type: string
        country:
          type: string
        status:
          type: string
          description: >-
            支付的汇总状态。参见[使用两张卡支付](/zh-hans/docs/payment-features/pay-with-two-cards#statuses)。
        sub_status:
          type: string
          description: >-
            汇总子状态，例如
            `APPROVED`、`AUTHORIZED`、`PARTIALLY_CAPTURED`、`PARTIALLY_REFUNDED`、`REFUND_RETRY_IN_PROCESS`
            或 `CANCEL_RETRY_IN_PROCESS`。
        merchant_order_id:
          type: string
        merchant_reference:
          type: string
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        split_payment_methods:
          type: boolean
          description: 由两张卡共同支付的支付为 `true`。
        payment_methods_count:
          type: integer
          description: 为该支付出资的卡数量：`2`。
        sdk_action_required:
          type: boolean
          description: 当 SDK 必须继续该支付时为 `true`，例如运行 3DS 验证。
        amount:
          type: object
          description: 支付总额。
          required:
            - currency
            - value
          properties:
            currency:
              type: string
              description: ISO 4217 货币代码（3 个字符）。
              example: BRL
            value:
              type: number
              description: 以主单位表示的金额（0.0001 的倍数）。
              example: 300
        checkout:
          type: object
          properties:
            session:
              type:
                - string
                - 'null'
        payment_method:
          type: object
          properties:
            capture:
              type: boolean
              description: 两张卡共用的捕获设置。
            account_updater:
              type:
                - boolean
                - 'null'
            payment_methods:
              type: array
              description: 每张卡一条记录。不提供单卡状态：请从各卡的 `transactions` 中读取其结果。
              minItems: 2
              maxItems: 2
              items:
                type: object
                properties:
                  sequence:
                    type: integer
                    description: 卡的位置：`1` 或 `2`。
                  type:
                    type: string
                    enum:
                      - CARD
                  amount:
                    type: object
                    description: 该卡支付的总额部分。
                    required:
                      - currency
                      - value
                    properties:
                      currency:
                        type: string
                        description: ISO 4217 货币代码（3 个字符）。
                        example: BRL
                      value:
                        type: number
                        description: 以主单位表示的金额（0.0001 的倍数）。
                        example: 300
                  payment_method_detail:
                    type: object
                    description: 卡详细信息，与 v1 支付对象一致。
                  payment_method_owner:
                    type: object
                    description: 持卡人，在请求中发送时返回。
                  transactions:
                    type: array
                    description: >-
                      该卡的交易。经过 3DS 的卡会显示 `THREE_D_SECURE`，随后是 `PURCHASE` 或
                      `AUTHORIZE`。
                    items:
                      type: object
                      description: 该卡的一笔交易。请从其交易中读取该卡的结果。
                      properties:
                        id:
                          type: string
                          format: uuid
                          description: 交易 id。用于按交易执行的操作。
                        type:
                          type: string
                          description: >-
                            交易类型，例如
                            `THREE_D_SECURE`、`PURCHASE`、`AUTHORIZE`、`CAPTURE`、`CANCEL`
                            或 `REFUND`。
                        status:
                          type: string
                          description: >-
                            该交易的状态，例如 `SUCCEEDED`、`DECLINED`、`PENDING` 或
                            `ERROR`。
                        category:
                          type: string
                          example: CARD
                        amount:
                          type: number
                          description: 该交易的金额。
                        provider_id:
                          type: string
                          description: 处理该交易的服务提供商。
                        response_code:
                          type: string
                          description: 该交易的 Yuno 响应代码。
                        response_message:
                          type: string
                        reason:
                          type:
                            - string
                            - 'null'
                        description:
                          type:
                            - string
                            - 'null'
                        merchant_reference:
                          type:
                            - string
                            - 'null'
                        three_d_secure_action_required:
                          type:
                            - boolean
                            - 'null'
                        created_at:
                          type: string
                          format: date-time
                        updated_at:
                          type:
                            - string
                            - 'null'
                          format: date-time
        customer_payer:
          type: object
          description: 付款方，与请求中发送的一致。
        additional_data:
          type:
            - object
            - 'null'
        callback_url:
          type: string
        workflow:
          type: string
          enum:
            - DIRECT
            - REDIRECT
            - SDK_CHECKOUT
        metadata:
          type: array
          items:
            type: object
  securitySchemes:
    sec0:
      type: apiKey
      in: header
      name: public-api-key
      x-default: <Your public-api-key>
    sec1:
      type: apiKey
      in: header
      name: private-secret-key
      x-default: <Your private-secret-key>

````

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