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

# 捕获支付

> 介绍如何使用 Capture Payment endpoint 手动捕获待处理的授权。

本指南逐步介绍如何在 Yuno 中手动捕获之前创建的支付。

> [!NOTE]
>
> **自动延迟捕获**
>
> 如果您希望 Yuno 在指定的延迟时间后自动捕获支付，可以在创建支付时配置 `delayed_capture_settings`。如需了解更多信息，请参阅 [Cancel and Capture Flow](https://docs.y.uno/zh-hans/docs/payment-features/Cancel-and-capture-flow.md) 指南。

> [!WARNING]
>
> **哪些支付可以捕获**
>
> 只有状态为 **PENDING** 的支付才能捕获。有关可能的支付状态的更多详情，请参阅 [支付状态](https://docs.y.uno/zh-hans/docs/basic-concepts/payments-1.md) 页面。
>
> 如果支付已经是 **SUCCEEDED**，则表示已完成捕获，无需再次捕获。这适用于购买（`capture: true`），以及发送给仅支持即时捕获的服务提供商的授权（`capture: false`）。在第二种情况下，Yuno 会为您创建捕获交易，并以 `SUCCEEDED` 和 `sub_status = CAPTURED` 返回支付，因此您可以跳过捕获调用。

## 要求

如需捕获支付，您需要：

* 在 Yuno Dashboard 中获取您的 [API 凭证](https://docs.y.uno/zh-hans/docs/using-yuno/settings/developers-credentials.md)，包括：
  * `public-api-key`
  * `private-secret-key`
* 持有使用 [Create Payment endpoint](https://docs.y.uno/zh-hans/reference/payments/create-payment.md) 创建支付后收到的支付标识数据：
  * `id`：支付的唯一标识符，在创建支付后从参数 `id` 中获取。
  * `transaction_id`：交易的唯一标识符，在创建支付后从参数 `transaction.id` 中获取。

> [!NOTE]
>
> **探索 Yuno Postman Collections**
>
> Yuno 提供 [Postman Collections](https://docs.y.uno/reference/getting-started/postman-collections.md)，您可以使用它在本地复现这些用例。

> [!NOTE]
>
> **捕获选项**
>
> 本指南介绍使用 API endpoint 进行**手动捕获**。其他捕获选项包括：
>
> * **实时捕获**（即时购买）
> * **延迟捕获**（延迟后自动捕获）
>
> 请参阅 [Cancel and Capture Flow](https://docs.y.uno/zh-hans/docs/payment-features/Cancel-and-capture-flow.md) 指南。

## 捕获支付

只有状态为 PENDING 的支付才能捕获。请使用 [Capture Payment endpoint](https://docs.y.uno/reference/payments/capture-authorization.md) 捕获支付。如需标识要捕获的支付，您需要提供其 `id` 和 `transaction_id`。此外，您还需要在请求正文中使用对象 `amount` 提供要捕获的金额：

* 全额捕获：将金额留空。
* 部分捕获：使用参数 `amount` 提供要捕获的金额。

> [!NOTE]
>
> **使用 Yuno 促销的支付**
>
> 授权金额是客户实际支付的金额，即 `amount.value` 减去 `discount_amount`，因此全额捕获会使用该金额。请参阅 [Promotions](https://docs.y.uno/zh-hans/docs/payment-features/promotions#refunds-captures-and-cancellations)。

> [!NOTE]
>
> **部分批准的支付**
>
> 如果您发送支付时设置了 `payment_method.detail.card.partial_approval: true`，且服务提供商批准的金额少于请求金额，则授权金额为 `amount.authorized`。全额捕获会使用 `amount.authorized`，部分捕获不得超过该金额：超过 `amount.authorized` 的捕获会被拒绝，并返回 `400 INVALID_PARAMETERS`。对于其他所有支付，超过授权金额的捕获会转发给服务提供商，由其决定是否接受。

如需确认支付已成功捕获，请检查 [Capture Payment](https://docs.y.uno/reference/payments/capture-authorization.md) endpoint 响应中的参数是否包含以下值：

* `type = CAPTURE`
* `status = SUCCEEDED`
* `payment.status = SUCCEEDED`
* `payment.sub_status = CAPTURED/PARTIALLY_CAPTURED`

如果响应包含上述值，则表示捕获成功。

### 支付已处于最终状态

如果您对不再处于 `PENDING` 状态的支付（例如已捕获、已退款或已取消）调用捕获 endpoint，该 endpoint 会返回 HTTP 400 和代码 `INVALID_STATUS`：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "code": "INVALID_STATUS",
  "messages": ["Invalid transaction status."]
}
```

请将此代码映射为“此支付不再适用任何后续操作”，并且不要重试捕获。如需了解支付的当前状态，请使用 [Retrieve payment](https://docs.y.uno/reference/payments/retrieve-payment-by-id) endpoint。

### 检查支付状态

如果出于某种原因，您需要确认支付已捕获：

* 使用 [Retrieve Payment by ID](https://docs.y.uno/reference/payments/retrieve-payment-by-id) 或 [Retrieve Payment by merchant\_order\_id](https://docs.y.uno/reference/payments/retrieve-payment-by-merchant-order-id.md) 获取支付的详细信息。
* 或者，设置 webhooks 以接收每个事件的通知。请参阅 [Webhooks](https://docs.y.uno/zh-hans/docs/webhooks/configure-webhooks.md) 指南，了解如何在 Yuno 中配置 webhooks。

## 另请参阅

* [取消支付](https://docs.y.uno/zh-hans/docs/direct-integration-use-cases/cancel-payments.md)


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