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

# 创建支付

> 介绍如何使用 Yuno 的 Create Payment endpoint 创建客户和基础支付。

本指南介绍如何通过直接集成创建基础支付。

## 要求

在按照本指南中的步骤操作之前，您需要：

* 在 Yuno Dashboard 中获取您的 [API 凭证](https://docs.y.uno/zh-hans/docs/using-yuno/settings/developers-credentials.md)，包括：
  * `public-api-key`
  * `private-secret-key`
  * `account_id`
* 在您的 Yuno Dashboard 账户中[设置连接](https://docs.y.uno/zh-hans/docs/using-yuno/dashboard-overview/connections.md)。
* 为支付方式[构建路由](https://docs.y.uno/zh-hans/docs/using-yuno/dashboard-overview/routing.md)，以定义其处理方式。

请确保在按照创建支付指南操作之前完成这些要求。

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

> [!WARNING]
>
> **启用 Yuno Test Payment Gateway**
>
> 如需在 **sandbox 环境**中测试简单的银行卡支付，您必须先启用 [Yuno Test Payment Gateway](https://docs.y.uno/zh-hans/docs/direct-integration-use-cases/yuno-testing-gateway.md)。此连接会模拟服务提供商，让您无需使用真实卡数据即可验证直接集成。

## 步骤概览

创建支付流程通常需要完成以下 2 个步骤。

1. [创建客户](https://docs.y.uno/reference/customers/create-customer.md)
2. [创建支付](#step-2-create-a-payment)

> [!NOTE]
>
> **其他支付方式和功能**
>
> 不同的支付方式（例如特定钱包或 BNPL）或功能（例如拆分支付）可能需要在创建支付之前执行额外步骤。

## 创建支付

### 步骤 1：创建客户

使用 [Create Customer](https://docs.y.uno/reference/customers/create-customer.md) 登记客户信息。您需要提供客户的个人信息。此外，您还需要提供 `merchant_customer_id`，即您的系统中用于标识该客户的唯一标识符。

> [!NOTE]
>
> **客户补充信息**
>
> 创建**客户**时，某些信息不是必填项，但如果提供，可以改善用户的支付体验。电话、账单地址和收货地址都是您可以提供的非必填数据示例。
>
> 如果您添加可选信息，请注意其中的必填字段。

创建客户流程结束时，您会收到一个 `id`，用于在 Yuno 系统中标识该用户。请使用该 `id` 初始化 checkout。

如果您要为之前已创建且已有 `id` 的现有用户创建支付，可以跳过此步骤。

### 步骤 2：创建支付

您将使用 endpoint [Create Payment](https://docs.y.uno/zh-hans/reference/payments/create-payment.md) 创建支付。借助 Yuno，您可以使用多种支付方式创建支付，并可使用 3DS 或拆分支付。不过，本指南重点介绍不涉及额外身份验证、验证或注册要求的简单支付。

下面将更详细地介绍如何创建支付。

#### 2.1 提供必需属性

提供客户相关信息，包括包含步骤 1 中 `id` 的 `customer_payer` 对象。

创建支付时，某些对象不是必需的。但如果您提供这些信息，将会提升用户的支付体验。如果您希望提供这些信息，请注意其中的必填字段。

#### 2.2 选择捕获类型

Yuno 提供 2 种支付捕获选项：

* 单步：授权和捕获同时执行。您只需创建支付，授权和捕获会自动完成。对于单步选项，您需要在请求中将属性 `capture` 设置为 `true`。
* 两步：授权和捕获在不同时间执行。如果您希望以两步方式处理支付，请在[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)时将 `capture` 设置为 `false`，然后使用 [Capture Authorization](https://docs.y.uno/reference/payments/capture-authorization.md) 请求完成流程。

#### 2.3 其他功能

Yuno 还支持在基础支付创建流程中使用一些其他功能：

* `vault_on_success`：如果您的客户使用信用卡付款，您可以在同一步骤中为该客户注册此支付方式，以供将来购买使用。
* `installments`：如果您为客户的支付提供分期付款，且您选择的处理商支持分期付款，您可以向我们发送用于创建支付的分期期数。

这两个字段都位于支付的 payment\_method 详情部分。

> [!NOTE]
>
> 如需在 `vault_on_success = true` 时生成并接收 `vaulted_token`，支付必须通过 `customer_payer.id` 引用现有的 Yuno 客户。在支付请求中内联创建或发送客户数据不会在我们这边创建客户，因此不会进行保存。满足这些条件且支付状态为 `SUCCEEDED` 时，`vaulted_token` 将在支付响应中返回，并可用于将来的交易。

### 步骤 3：检查支付状态

向 [Create Payment](https://docs.y.uno/zh-hans/reference/payments/create-payment.md) endpoint 发送请求后，您可以分析响应中的 `status` 和 `sub_status` 来检查支付状态。请参阅 [Payment Status](https://docs.y.uno/reference/payments/status-and-response-codes/payment.md) 页面，查看创建支付请求的响应中可能返回的所有选项。

根据处理商和支付方式的不同，状态可能需要一段时间才能更新。因此，您可能需要使用 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 在每个事件发生后接收通知。Yuno 建议您使用 webhooks，以便更好地监控异步支付。请参阅 [Webhooks](https://docs.y.uno/zh-hans/docs/webhooks.md) 指南，了解如何配置 Yuno 提供的 webhooks 解决方案。

> [!NOTE]
>
> **测试卡支付**
>
> 如果您需要测试一般的银行卡支付，Yuno 提供 Yuno Test Payment Gateway。它的工作方式与连接相同，但仅在 sandbox 环境中可用。请参阅 [Yuno Test Payment Gateway 页面](https://docs.y.uno/zh-hans/docs/direct-integration-use-cases/yuno-testing-gateway.md)了解所有功能，或直接查看[如何测试卡支付](https://docs.y.uno/zh-hans/docs/direct-integration-use-cases/yuno-testing-gateway.md#test-card-payments-with-yuno-testing-gateway)指南。


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