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

# 取消与捕获流程

> 为已授权的卡支付配置实时、手动或延迟捕获以及取消设置

本指南介绍捕获和取消操作的所有可用方式，并说明在每种场景下如何与我们的 API 交互。

## 本指南内容

* [**捕获模式**](#capture-modes)
  * [实时捕获](#real-time-capture)
  * [手动捕获](#manual-capture)
  * [延迟捕获](#delayed-capture)
  * [Apple Pay 和 Google Pay](#apple-pay-and-google-pay)
* [**取消模式**](#cancel-modes)
  * [手动取消](#manual-cancel)
  * [延迟取消](#delayed-cancel)
* [**配置要求**](#configuration-requirements)
* [**请求示例**](#example-requests)
  * [示例 1：实时捕获](#example-1-real-time-capture)
  * [示例 2：仅手动捕获](#example-2-manual-capture-only)
  * [示例 3：延迟捕获](#example-3-delayed-capture)
  * [示例 4：延迟取消](#example-4-delayed-cancel)
  * [示例 5：组合使用延迟捕获和取消](#example-5-combined-delayed-capture-and-cancel-with-enhanced-validation)
* [**何时使用各模式**](#when-to-use-each-mode)
* [**字段参考**](#field-reference)

## 捕获模式

Yuno 提供三种捕获支付的方式，由 [创建支付 API](https://docs.y.uno/zh-hans/reference/payments/create-payment.md) 中的 `capture` 字段和可选的 `delayed_capture_settings` 配置决定。实际的功能可用性或具体实现细节可能因您用于路由支付的支付服务提供商而异。

### 实时捕获

此模式处理支付并立即转移资金，没有任何延迟，实际上是将授权和捕获合并为单个**购买**操作。当 `payment_method.detail.card.capture` 设置为 `true` 时，交易将作为购买执行，即授权和捕获同时发生。

根据支付服务提供商的 API，Yuno 可能将其作为一笔直接购买交易执行，也可能先进行授权，随后立即调用捕获。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "payment_method": {
    "detail": {
      "card": {
        "capture": true,
        "card_data": {
          // card details
        }
      }
    }
  }
}
```

### 手动捕获

使用此配置时，在您调用 [捕获 API](https://docs.y.uno/reference/payments/capture-authorization.md) 或在您的 [Yuno Dashboard](https://dashboard.y.uno/) 中手动捕获之前，Yuno 不会捕获该支付。设置 `capture: false` 可仅授权支付而不捕获。

手动捕获提供最大的灵活性，因为您可以完全控制执行捕获的时间。但是，务必尽快捕获，因为支付服务提供商会限制授权保持未捕获状态的时长，且这些限制因服务提供商和地区而异。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "payment_method": {
    "detail": {
      "card": {
        "capture": false,
        "card_data": {
          // card details
        }
      }
    }
  }
}
```

> [!WARNING]
>
> **捕获不同金额**
>
> 如果您需要捕获与最初授权金额不同的金额，必须使用手动捕获。实时捕获和延迟捕获模式始终捕获最初授权的金额。

### 预授权冻结（`authorization_type`）

当您使用 `capture: false` 授权支付时，可以设置 `payment_method.detail.card.authorization_type` 来声明所需的冻结类型。`STANDARD`（默认值，省略该字段时也使用此值）创建常规授权。`PRE_AUTHORIZATION` 请求延长的预授权冻结，部分服务提供商要求先进行此类冻结，之后您才能通过 [增量授权](https://docs.y.uno/reference/payments/increment-authorization.md) 提高冻结金额。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "payment_method": {
    "type": "CARD",
    "detail": {
      "card": {
        "capture": false,
        "authorization_type": "PRE_AUTHORIZATION"
      }
    }
  }
}
```

* `authorization_type` 仅在 `capture` 为 `false` 时适用。在 `capture: true` 的情况下发送 `PRE_AUTHORIZATION`（或省略 `capture`，因为其默认值为 `true`），将返回 `400` 错误，错误代码为 `INVALID_PARAMETERS`。
* 没有对应预授权功能的服务提供商会将该支付作为标准授权处理（尽力而为）。
* 当您发送该字段时，其值会在支付查询响应中交易的 `payment_method.detail.card.authorization_type` 下返回。如果省略该字段，支付将按 `STANDARD` 处理，但不会存储任何值，因此该字段不会出现在查询响应中。

### 延迟捕获

将 `capture: false` 与 `delayed_capture_settings` 一起配置，可将支付的捕获安排在稍后的时间执行，具体时间由 `delay` 字段指定。

> [!WARNING]
>
> **仅限全额捕获**
>
> 延迟捕获仅适用于捕获授权的**全部金额**。如果您需要捕获部分金额，必须改用 [手动捕获](https://docs.y.uno/zh-hans/docs/direct-integration-use-cases/capture-payments.md)。对于发送时带有 `partial_approval: true` 且批准金额低于请求金额的卡支付，授权的全部金额为 `amount.authorized`。

> [!NOTE]
>
> **`simplified_mode`**
>
> 将 `simplified_mode` 设置为 `true` 后，如果计划的捕获尝试中出现错误，Yuno 将重试捕获操作。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "payment_method": {
    "detail": {
      "card": {
        "capture": false,
        "delayed_capture_settings": {
          "delay": "P7D",
          "simplified_mode": false
        },
        "card_data": {
          // card details
        }
      }
    }
  }
}
```

使用延迟捕获操作时，`delay` 字段为必填项，并且必须遵循 [ISO 8601 标准](https://en.wikipedia.org/wiki/ISO_8601#Durations)。例如：

* `"PT3H"` 表示 3 小时
* `"P7D"` 表示 7 天
* `"P1M"` 表示 1 个月

如果您在计划时间之前调用 [捕获 API](https://docs.y.uno/reference/payments/capture-authorization.md)，您的调用将覆盖延迟并立即执行捕获。**此操作会自动取消已计划的 Yuno 触发器**。或者，您也可以通过您的 [Yuno Dashboard](https://dashboard.y.uno/) 手动捕获支付。

### Apple Pay 和 Google Pay

上述捕获模式同样适用于由 Yuno 解密并作为卡支付处理的 Apple Pay 和 Google Pay 支付，[Apple Pay](https://docs.y.uno/zh-hans/docs/wallets/apple-pay/apple-pay-direct-integration.md) 和 [Google Pay](https://docs.y.uno/zh-hans/docs/wallets/google-pay/google-pay-direct-integration.md) 直接集成以及这两种钱包的 SDK 集成均以这种方式运作。`capture` 字段的发送位置取决于您创建支付的方式：

* **直接 API 集成**（`workflow: "DIRECT"`，钱包令牌位于 `payment_method.detail.wallet.payment_token` 中）：在 `payment_method.detail.wallet` 内发送 `capture`，与令牌放在一起。
* **SDK 集成**（使用 SDK 在 `payment_method.token` 中返回的一次性令牌创建支付）：在 `payment_method.detail.card` 内发送 `capture`，与卡支付完全相同。在此流程中，`payment_method.detail.card.capture` 优先于在钱包层级发送的 `capture` 值。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "workflow": "DIRECT",
  "payment_method": {
    "type": "APPLE_PAY",
    "detail": {
      "wallet": {
        "payment_token": "{...}",
        "capture": false
      }
    }
  }
}
```

之后，该授权使用与卡授权相同的 endpoint 和 Dashboard 操作进行捕获或取消。与卡一样，服务提供商是否支持钱包支付的授权以及授权可保持多长时间，取决于服务提供商。

## 取消模式

当您授权支付但未立即捕获时，这些资金会暂时冻结在客户的支付方式上。如果您决定不捕获该支付，务必取消授权以释放冻结的资金，从而提供更好的客户体验。取消模式让您可以控制何时以及如何作废这些授权。

### 手动取消

在手动取消模式下，已授权的支付会保持有效，直到您明确取消为止。Yuno 不会自动作废这些授权，让您完全掌控何时释放资金。您可以使用 [取消 API](https://docs.y.uno/reference/payments/cancel-or-refund-a-payment.md) 或通过 Yuno Dashboard 界面取消授权。

对于不会捕获的授权，务必尽快取消以释放冻结的资金。如果授权未被取消，客户体验会受到显著影响，因为资金可能会被预留一段时间，具体时长取决于客户所在地区和卡组织。

### 延迟取消

配置 `delayed_cancel_settings`，可为取消未捕获的授权设置延迟，类似于延迟捕获。如果您决定不在指定时间范围内捕获，此功能会自动释放客户资金，避免在客户的支付方式上无限期冻结资金，从而显著改善客户体验。

使用延迟取消操作时，`delay` 字段为必填项，并且必须遵循 [ISO 8601 标准](https://en.wikipedia.org/wiki/ISO_8601#Durations)。例如：

* `"PT3H"` 表示 3 小时
* `"P7D"` 表示 7 天
* `"P30D"` 表示 30 天

> [!NOTE]
>
> **`simplified_mode`**
>
> 将 `simplified_mode` 设置为 `true` 后，如果计划的取消尝试中出现错误，Yuno 将重试取消操作。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "payment_method": {
    "detail": {
      "card": {
        "capture": false,
        "delayed_cancel_settings": {
          "delay": "P30D",
          "simplified_mode": false
        },
        "card_data": {
          // card details
        }
      }
    }
  }
}
```

如果您在计划时间之前调用 [捕获 API](https://docs.y.uno/reference/payments/capture-authorization.md) 或 [取消 API](https://docs.y.uno/reference/payments/cancel-or-refund-a-payment.md)，您的调用将覆盖延迟并立即执行该操作。**此操作会自动取消已计划的 Yuno 触发器**。或者，您也可以通过 Yuno Dashboard 手动捕获或取消支付。

> [!NOTE]
>
> **延迟捕获和取消设置**
>
> Yuno 建议不要**同时**使用 `delayed_capture_settings` 和 `delayed_cancel_settings`，以避免意外行为。请根据您的需求一次只使用其中一个。

## 配置要求

* `delayed_capture_settings` 和 `delayed_cancel_settings` 仅在 `capture = false` 时有效
* 如果 `capture = true`，则必须省略这些对象或将其设置为 `null`
* 可以通过 API endpoint 或 Yuno Dashboard 执行手动操作

## 请求示例

### 示例 1：实时捕获

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "country": "US",
  "amount": {
    "currency": "USD",
    "value": "20000"
  },
  "customer_payer": {
    "id": "<customer_id>",
    "first_name": "John",
    "last_name": "Doe",
    "email": "johndoe@example.com"
  },
  "workflow": "DIRECT",
  "payment_method": {
    "detail": {
      "card": {
        "capture": true,
        "card_data": {
          "number": "4111111111111111",
          "expiration_month": 11,
          "expiration_year": 28,
          "security_code": "123",
          "holder_name": "John Doe"
        }
      }
    },
    "type": "CARD"
  },
  "account_id": "<account_id>",
  "description": "Real-time capture payment",
  "merchant_order_id": "000023"
}
```

### 示例 2：仅手动捕获

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "country": "US",
  "amount": {
    "currency": "USD",
    "value": "20000"
  },
  "customer_payer": {
    "id": "<customer_id>",
    "first_name": "John",
    "last_name": "Doe",
    "email": "johndoe@example.com"
  },
  "workflow": "DIRECT",
  "payment_method": {
    "detail": {
      "card": {
        "capture": false,
        "card_data": {
          "number": "4111111111111111",
          "expiration_month": 11,
          "expiration_year": 28,
          "security_code": "123",
          "holder_name": "John Doe"
        }
      }
    },
    "type": "CARD"
  },
  "account_id": "<account_id>",
  "description": "Authorization only - manual capture",
  "merchant_order_id": "000024"
}
```

### 示例 3：延迟捕获

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "country": "US",
  "amount": {
    "currency": "USD",
    "value": "20000"
  },
  "customer_payer": {
    "id": "<customer_id>",
    "first_name": "John",
    "last_name": "Doe",
    "email": "johndoe@example.com"
  },
  "workflow": "DIRECT",
  "payment_method": {
    "detail": {
      "card": {
        "capture": false,
        "delayed_capture_settings": {
          "delay": "P7D",
          "simplified_mode": false
        },
        "card_data": {
          "number": "4111111111111111",
          "expiration_month": 11,
          "expiration_year": 28,
          "security_code": "123",
          "holder_name": "John Doe"
        }
      }
    },
    "type": "CARD"
  },
  "account_id": "<account_id>",
  "description": "Authorization with delayed capture",
  "merchant_order_id": "000025"
}
```

### 示例 4：延迟取消

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "country": "US",
  "amount": {
    "currency": "USD",
    "value": "20000"
  },
  "customer_payer": {
    "id": "<customer_id>",
    "first_name": "John",
    "last_name": "Doe",
    "email": "johndoe@example.com"
  },
  "workflow": "DIRECT",
  "payment_method": {
    "detail": {
      "card": {
        "capture": false,
        "delayed_cancel_settings": {
          "delay": "P30D",
          "simplified_mode": false
        },
        "card_data": {
          "number": "4111111111111111",
          "expiration_month": 11,
          "expiration_year": 28,
          "security_code": "123",
          "holder_name": "John Doe"
        }
      }
    },
    "type": "CARD"
  },
  "account_id": "<account_id>",
  "description": "Authorization with delayed cancel",
  "merchant_order_id": "000026"
}
```

### 示例 5：组合使用延迟捕获和取消，并进行增强验证

此示例展示了一个完整的支付请求，其中同时包含延迟捕获和取消设置，以及增强的客户验证字段：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "country": "US",
  "amount": {
    "currency": "USD",
    "value": "20000"
  },
  "customer_payer": {
    "merchant_customer_validations": {
      "account_is_verified": true,
      "email_is_verified": true,
      "phone_is_verified": true
    },
    "id": "<customer_id>",
    "first_name": "John",
    "last_name": "Doe",
    "email": "johndoe@example.com"
  },
  "workflow": "DIRECT",
  "payment_method": {
    "detail": {
      "card": {
        "capture": false,
        "delayed_capture_settings": {
          "delay": "P20D",
          "simplified_mode": true
        },
        "delayed_cancel_settings": {
          "delay": "P40D",
          "simplified_mode": true
        },
        "card_data": {
          "number": "4111111111111111",
          "expiration_month": 11,
          "expiration_year": 28,
          "security_code": "123",
          "holder_name": "John Doe"
        },
        "verify": false
      }
    },
    "type": "CARD"
  },
  "account_id": "<account_id>",
  "description": "Payment with card details",
  "merchant_order_id": "000023"
}
```

> [!NOTE]
>
> **注意**
>
> 虽然此示例同时配置了 `delayed_capture_settings` 和 `delayed_cancel_settings`，但 Yuno 建议一次只使用其中一个，以避免意外行为。

## 在捕获前审核支付

手动捕获也是您在资金转移前亲自批准每笔支付的方式。具体模式如下：

1. 使用 `capture: false` 进行授权。客户的资金会被预留，而不会被扣除。
2. 执行您自己的检查：库存、收货地址、内部欺诈审核团队，或调用您的风险服务提供商。如果您希望由 Yuno 替您暂扣可疑支付，请在路由上设置 [审核列表或结果为 Review 的规则](https://docs.y.uno/zh-hans/docs/using-yuno/dashboard-overview/risk-conditions.md#review-lists)；这些支付会在到达服务提供商之前被暂扣，您可以在 Risk Conditions 的 **Held payments** 选项卡中批准或拒绝它们。
3. 调用 [捕获授权](https://docs.y.uno/reference/payments/capture-authorization.md) 扣取资金，或调用 [取消](https://docs.y.uno/reference/payments/cancel-payment.md) 释放资金。在支付中添加 `delayed_cancel_settings`，这样您始终未作出决定的授权会被自动释放。

对于您拒绝的支付，客户永远不会被扣款，也无需退款。

## 何时使用各模式

### 在以下情况下使用实时捕获：

* 您立即提供商品或服务
* 您无需在授权后验证库存或进行欺诈检查
* 您希望使用最简单的支付流程

### 在以下情况下使用手动捕获：

* 您需要在完成支付前核实库存
* 您希望捕获与授权金额不同的金额
* 您有决定捕获还是取消的复杂业务逻辑
* 您希望在向客户扣款前亲自批准每笔支付
* 您需要最大程度地控制捕获时间

### 在以下情况下使用延迟捕获：

* 您希望在特定时间段后自动捕获
* 您的履约流程可预测
* 您希望在保持控制的同时减少人工干预

### 在以下情况下使用延迟取消：

* 您希望在未于规定时间内捕获时自动释放客户资金
* 您希望通过避免无限期冻结资金来改善客户体验
* 您的履约流程有最长时间限制

## 字段参考

| 字段 | 类型 | 描述 |
| - | - | - |
| `capture` | `boolean` | 决定卡支付是立即捕获（`true`，购买）还是仅授权（`false`，需要捕获或取消）。 |
| `authorization_type` | `string` | 可选，仅在 `capture` 为 `false` 时适用。`STANDARD`（默认值）创建常规授权；`PRE_AUTHORIZATION` 请求延长的预授权冻结，用于后续的 [增量授权](https://docs.y.uno/reference/payments/increment-authorization.md)。在 `capture: true`（或省略 `capture`，其默认值为 `true`）时使用 `PRE_AUTHORIZATION` 会返回 `400`（`INVALID_PARAMETERS`）。 |
| `delayed_capture_settings.delay` | `string` | Yuno 捕获支付前的延迟时间。必须遵循 [ISO 8601 时长格式](https://en.wikipedia.org/wiki/ISO_8601#Durations)（例如，"P7D" 表示 7 天，"PT3H" 表示 3 小时）。 |
| `delayed_capture_settings.simplified_mode` | `boolean` | 如果为 `true`，Yuno 会在捕获失败时重试。 |
| `delayed_cancel_settings.delay` | `string` | Yuno 取消授权前的延迟时间。必须遵循 [ISO 8601 时长格式](https://en.wikipedia.org/wiki/ISO_8601#Durations)（例如，"P30D" 表示 30 天）。 |
| `delayed_cancel_settings.simplified_mode` | `boolean` | 如果为 `true`，Yuno 会在取消失败时重试。 |


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