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

# 取消支付

> 在待处理的支付完成前将其取消，并将其状态更新为已取消。

由于 **AUTHORIZE** 交易状态而处于 **PENDING** 状态的支付，如果不再需要，可以在完成前取消。发送取消请求会将支付状态更新为 **CANCELLED**。

> [!WARNING]
>
> **3DS 支付**
>
> 由于 3DS 身份验证而处于 **PENDING** 状态的支付无法取消。这些支付处于等待用户身份验证的临时状态。支付状态将根据身份验证结果自动更新为 **FRAUD VERIFIED** 或 **CANCELLED**。

> [!NOTE]
>
> **替代支付方式**
>
> PIX 等替代支付方式也支持取消处于 PENDING 状态的支付。如需了解更多信息，请联系您的技术客户经理。

如果您需要已取消交易的收据，可以在收据生成后进行检索。为此，请使用[按 ID 检索支付](https://docs.y.uno/zh-hans/reference/payments/retrieve-payment-by-id-v2.md) endpoint，并查看 `payment.transaction` 对象中的 `receipt_url` 字段。有关 `receipt`、`receipt_url` 和 `receipt_language`，请参阅[支付对象](https://docs.y.uno/zh-hans/reference/payments/the-payment-object.md)。

要使用此 endpoint，您必须在请求中提供 `X-Idempotency-Key`。如需了解更多信息，请查看[身份验证](https://docs.y.uno/zh-hans/reference/getting-started/authentication.md#idempotency)页面。


## OpenAPI

````yaml openapi/zh-hans/payments/cancel-payment.json POST /payments/{payment_id}/transactions/{transaction_id}/cancel
openapi: 3.1.0
info:
  title: payment-api-refundcancel-payment
  version: 1.0.2
servers:
  - url: https://api-sandbox.y.uno/v1
    description: Sandbox
  - url: https://api.y.uno/v1
    description: Production (US)
security:
  - sec0: []
    sec1: []
    sec2: []
paths:
  /payments/{payment_id}/transactions/{transaction_id}/cancel:
    post:
      summary: 取消支付
      operationId: cancel-payment
      parameters:
        - name: payment_id
          in: path
          description: 支付的唯一标识符（UUID，36 个字符）。
          schema:
            type: string
          required: true
        - name: transaction_id
          in: path
          description: 交易的唯一标识符（UUID，36 个字符）。
          schema:
            type: string
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - merchant_reference
              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: 由商户定义的支付交易标识（MAX 255；MIN 3）。
                response_additional_data:
                  type: object
                  description: 指定交易响应所需的附加数据
                  properties:
                    receipt:
                      type: boolean
                      description: 指示交易响应是否需要收据
                    receipt_language:
                      type: string
                      description: 指示要生成的收据的语言
                      enum:
                        - ES
                        - EN
                        - PT
                    transactions_history:
                      type: boolean
                      description: 为 true 时，响应中包含交易历史
                    raw_request:
                      type: boolean
                      description: 为 true 时，输出中包含服务提供商的原始请求
                    raw_response:
                      type: boolean
                      description: 为 true 时，输出中包含服务提供商的原始响应
            examples:
              Request Example:
                value:
                  description: Duplicate
                  reason: REQUESTED_BY_CUSTOMER
                  merchant_reference: AAB01-432245
      responses:
        '201':
          description: '201'
          content:
            application/json:
              examples:
                Result:
                  value:
                    id: 438bea6c-9061-4416-b824-469c3c05868d
                    type: CANCEL
                    status: SUCCEEDED
                    category: CARD
                    amount:
                      captured: 0
                      currency: USD
                      currency_conversion: null
                      refunded: 0
                      value: 30000
                    merchant_reference: ''
                    created_at: '2024-06-06T14:03:08.384014Z'
                    updated_at: '2024-06-06T14:03:08.453617Z'
                    provider_data:
                      id: YUNO_TEST_PAYMENT_GW
                      transaction_id: ''
                      account_id: ''
                      status: SUCCEEDED
                      sub_status: ''
                      status_detail: SUCCEEDED
                      response_message: null
                      response_code: SUCCEEDED
                      raw_response:
                        message: provider response
                      third_party_transaction_id: null
                      third_party_account_id: null
                      iso8583_response_code: '00'
                      iso8583_response_message: Approved or completed successfully
                    connection_data:
                      id: 58cc35f4-faef-4107-8e09-d18d60121d38
                      name: Connection name
                    response_code: SUCCEEDED
                    response_message: Transaction successful
                    payment:
                      id: 2d6f75c1-c4bc-4d2d-80ec-0af4d12c85da
                      account_id: ''
                      description: Test
                      country: US
                      status: CANCELED
                      sub_status: CANCELED
                      merchant_order_id: '0000023'
                      created_at: '2024-06-06T14:01:34.286228Z'
                      updated_at: '2024-06-06T14:03:08.484781Z'
                      amount:
                        captured: 0
                        authorized: 30000
                        currency: USD
                        currency_conversion: null
                        refunded: 0
                        value: 30000
                      split_marketplace: []
                    customer_payer: null
                    simplified_mode: false
                    receipt: false
                    receipt_url: null
                    receipt_language: null
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: 438bea6c-9061-4416-b824-469c3c05868d
                  type:
                    type: string
                    example: CANCEL
                  status:
                    type: string
                    example: SUCCEEDED
                  category:
                    type: string
                    example: CARD
                  amount:
                    type: object
                    properties:
                      captured:
                        type: integer
                        example: 0
                        default: 0
                      currency:
                        type: string
                        example: USD
                      currency_conversion: {}
                      refunded:
                        type: integer
                        example: 0
                        default: 0
                      value:
                        type: integer
                        example: 30000
                        default: 0
                  merchant_reference:
                    type: string
                    example: ''
                  created_at:
                    type: string
                    example: '2024-06-06T14:03:08.384014Z'
                  updated_at:
                    type: string
                    example: '2024-06-06T14:03:08.453617Z'
                  provider_data:
                    type: object
                    properties:
                      id:
                        type: string
                        example: YUNO_TEST_PAYMENT_GW
                      transaction_id:
                        type: string
                        example: ''
                      account_id:
                        type: string
                        example: ''
                      status:
                        type: string
                        example: SUCCEEDED
                      sub_status:
                        type: string
                        example: ''
                      status_detail:
                        type: string
                        example: SUCCEEDED
                      response_message: {}
                      response_code:
                        type: string
                        example: SUCCEEDED
                      raw_request:
                        type: object
                        description: Yuno 发送给服务提供商的请求的混淆副本。仅对列入允许名单的组织返回。
                      raw_response:
                        type: object
                        properties:
                          message:
                            type: string
                            example: provider response
                      third_party_transaction_id: {}
                      third_party_account_id: {}
                      iso8583_response_code:
                        type: string
                        example: '00'
                      iso8583_response_message:
                        type: string
                        example: Approved or completed successfully
                  connection_data:
                    type: object
                    properties:
                      id:
                        type: string
                        example: 58cc35f4-faef-4107-8e09-d18d60121d38
                      name:
                        type: string
                        example: Connection name
                  response_code:
                    type: string
                    example: SUCCEEDED
                  response_message:
                    type: string
                    example: Transaction successful
                  payment:
                    type: object
                    properties:
                      id:
                        type: string
                        example: 2d6f75c1-c4bc-4d2d-80ec-0af4d12c85da
                      account_id:
                        type: string
                        example: ''
                      description:
                        type: string
                        example: Test
                      country:
                        type: string
                        example: US
                      status:
                        type: string
                        example: CANCELED
                      sub_status:
                        type: string
                        example: CANCELED
                      merchant_order_id:
                        type: string
                        example: '0000023'
                      created_at:
                        type: string
                        example: '2024-06-06T14:01:34.286228Z'
                      updated_at:
                        type: string
                        example: '2024-06-06T14:03:08.484781Z'
                      amount:
                        type: object
                        properties:
                          captured:
                            type: integer
                            example: 0
                            default: 0
                          authorized:
                            type: number
                            description: >-
                              服务提供商已批准的金额（0.0001 的倍数），扣除任何 Yuno 促销（`value` 减去
                              `discount_amount`），并加上已批准的增量授权。在全额批准时，或服务提供商未返回已批准金额时，它等于该净额。对于发送了
                              `payment_method.detail.card.partial_approval:
                              true` 的卡支付，部分批准后支付仍保持全额批准的状态，因此当 `authorized` 小于
                              `value` 减去 `discount_amount`（无促销时，小于
                              `value`）时，即为部分批准。对于未获批准的支付，或在引入此字段之前创建的支付，不会返回此字段。
                            example: 30000
                          currency:
                            type: string
                            example: USD
                          currency_conversion: {}
                          refunded:
                            type: integer
                            example: 0
                            default: 0
                          value:
                            type: integer
                            example: 30000
                            default: 0
                      discount_amount:
                        type: object
                        description: >-
                          应用于支付的 Yuno 促销的总折扣：即 `additional_data.order.discounts`
                          中 `YUNO_PROMOTION` 行的总和。未应用促销时不存在。实际扣款金额为
                          `amount.value` 减去此值，见 `transactions.amount`。请参阅
                          [Promotions](/zh-hans/docs/payment-features/promotions)。
                        properties:
                          currency:
                            type: string
                            description: 折扣的货币，与 `amount.currency` 相同。
                          value:
                            type: number
                            description: 折扣。
                      split_marketplace:
                        type: array
                  customer_payer: {}
                  simplified_mode:
                    type: boolean
                    example: false
                    default: true
                  receipt:
                    type: boolean
                    example: false
                    default: true
                  receipt_url: {}
                  receipt_language: {}
        '400':
          description: '400'
          content:
            application/json:
              examples:
                Result:
                  value:
                    code: INVALID_REQUEST
                    messages:
                      - Invalid request
              schema:
                type: object
                properties:
                  code:
                    type: string
                    example: INVALID_REQUEST
                  messages:
                    type: array
                    items:
                      type: string
                      example: Invalid request
        '401':
          description: '401'
          content:
            application/json:
              examples:
                Unauthorized:
                  value:
                    code: INVALID_CREDENTIALS
                    messages:
                      - Invalid credentials
              schema:
                type: object
                properties:
                  code:
                    type: string
                    example: INVALID_CREDENTIALS
                  messages:
                    type: array
                    items:
                      type: string
                      example: Invalid credentials
        '403':
          description: '403'
          content:
            application/json:
              examples:
                Forbidden:
                  value:
                    code: AUTHORIZATION_REQUIRED
                    messages:
                      - The merchant has no authorization to use this API.
              schema:
                type: object
                properties:
                  code:
                    type: string
                    example: AUTHORIZATION_REQUIRED
                  messages:
                    type: array
                    items:
                      type: string
                      example: The merchant has no authorization to use this API.
      deprecated: false
components:
  securitySchemes:
    sec0:
      type: apiKey
      in: header
      x-default: <Your public-api-key>
      name: public-api-key
    sec1:
      type: apiKey
      in: header
      x-default: <Your private-secret-key>
      name: private-secret-key
    sec2:
      type: apiKey
      in: header
      x-default: <Your X-Idempotency-Key>
      name: X-Idempotency-Key

````

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