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

# Direct Flow 集成

> 介绍面向符合 PCI 标准的商户的服务器到服务器 Direct Flow 集成，以及 DIRECT 和 REDIRECT 工作流。

## 工作原理

如果您是开发者，可以使用我们的 Direct Flow 继续使用您自己的 checkout，并仅通过服务器到服务器连接接入我们的服务。

您的公司必须通过 PCI 认证，才能使用我们的服务器到服务器银行卡支付服务。在开始实施之前，请将您的 AOC 认证转发给您的客户经理。

> [!CAUTION]
>
> 我们始终建议优先使用 Yuno 的 SDK，而非 Direct Flow 集成。Yuno 的 SDK 符合 PCI 标准，并通过处理所有复杂事项（包括欺诈防范、3DS 以及支付服务提供商的特定要求）简化支付流程。Direct Flow 要求商户手动处理这些方面，会增加复杂性和风险。

对于每种实施方式，我们都建议将支付的 `status` 和 `sub_status` 作为[支付状态](https://docs.y.uno/reference/payments/status-and-response-codes/payment.md)的主要参考。一笔支付可能关联多笔不同的[交易](https://docs.y.uno/reference/payments/status-and-response-codes/transaction.md)，因此关注支付的 **status/sub\_status**，无论执行了多少笔交易，您都能获得最新状态，为决策提供清晰的依据。通过此集成，您还可以[注册信用卡](https://docs.y.uno/zh-hans/docs/direct-integration-use-cases/direct-flow.md#enrollment)以供将来购买使用（同样仅适用于符合 PCI 标准的商户）。

## 支付

![](https://mintcdn.com/yuno-3979e326/MTlogjS0_SlxtlJG/images/reference/direct-flow/image1.png?fit=max\&auto=format\&n=MTlogjS0_SlxtlJG\&q=85\&s=d789ef18cef4df60843921d2eddeb4ee)

**1. 创建客户**

**\[可选]**：第一步是创建客户，以便关联支付方式。使用 [Create Customer](https://docs.y.uno/reference/customers/create-customer.md) endpoint 获取唯一 ID。

* 如果客户已存在，可以跳过此步骤。
* 您也可以直接在支付中发送客户信息，而无需创建客户对象。

> [!WARNING]
>
> 必须创建客户才能生成 `vaulted_token`。

**2. 创建支付**

显示您的 Yuno 账户中已启用的支付方式。客户选择后，使用 [Create Payment](https://docs.y.uno/zh-hans/reference/payments/create-payment.md) endpoint 创建包含订单详情、客户信息、金额等内容的支付。

* 有关实施详情，请参阅[示例部分](https://docs.y.uno/reference/payments/payment-examples.md)。
* 对于之前已注册的支付方式，请使用 `vaulted_token`。

在集成过程中，请将支付的 **status** 和 **sub\_status** 作为支付状态的主要参考。

### DIRECT 与 REDIRECT 工作流

在 Yuno 中使用直接集成时，您可以选择 2 种 `workflow` 选项：

* **DIRECT**：我们返回服务提供商的原始响应，您可以利用这些未经过滤的数据，按自己的方式构建体验。
* **REDIRECT**：我们同样会返回服务提供商的直接响应，此外还为商户提供使用 Yuno 重定向链接的选项，由我们仅为该笔支付处理支付体验。您可以在支付响应的 `payment_method.payment_method_detail.<type>.redirect_url` 字段中找到该 URL，其中 `<type>` 为支付方式类别：`ticket`、`bank_transfer`、`wallet` 或 `bnpl`。

两种工作流都支持银行卡（包括使用 3DS 的银行卡）和替代支付方式（PSE、Nequi、MercadoPago、PIX 等）。对于使用 3DS 的银行卡，两种工作流都要求具备 PCI 认证。

> [!NOTE]
>
> **PIX 支付数据**
>
> 对于 PIX，支付响应会在 `payment_method.payment_method_detail.bank_transfer` 对象中返回需要向付款方展示的数据。[PIX 示例](https://docs.y.uno/reference/payments/payment-examples/bank-transfer.md#pix)使用 `REDIRECT` 工作流，并返回以下字段：
>
> * `provider_image`：服务提供商提供的 URL。在该示例中，它指向二维码。
> * `beneficiary_name`、`beneficiary_document_type`、`beneficiary_document`、`bank_name`、`bank_account`：接收该支付的账户持有人详情。这些字段可能为 `null`，如 PIX 示例所示。
> * `payment_instruction`：与该支付相关的支付说明。
> * `redirect_url`：由 Yuno 托管的支付页面，与 `REDIRECT` 工作流配合使用。
>
> 使用 `DIRECT` 工作流时，服务提供商未经过滤的响应也会在 `provider_data.raw_response` 中返回。有关完整的字段说明，请参阅 [Payment 对象](https://docs.y.uno/reference/payments/the-payment-object.md)。

### 重要附加功能

* **Webhooks**：我们建议在您的 Yuno Dashboard 中配置 [Webhooks](https://docs.y.uno/zh-hans/docs/webhooks.md)。Webhooks 是确保您的系统及时了解支付进度和状态的最佳方式。由于事件通知会自动触发，您的系统无需反复向 Yuno 发送请求。

* **设备指纹**：客户的设备指纹用于欺诈防范。设备指纹通常通过在 checkout 中使用第三方 JavaScript 生成。如果您使用**直接集成**，并希望在[支付流程](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)中支持欺诈防范服务提供商，可以使用此对象指定所需信息。对于使用 Yuno checkout 的集成，该值会自动获取，因此请勿发送此字段。

  * 以下是请求正文的部分摘录，重点展示 `device_fingerprints` 对象：

    ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
    [...]
    "customer_payer": {
        "merchant_customer_id": "1690161049",
        "first_name": "Giovanna",
        "last_name": "Bartell",
        "email": "Lisandro_Leannon58@hotmail.com",
         "device_fingerprints": [
            {
                "provider_id": "MERCADO_PAGO",
                "id": "20a6c463-dd0c-4323-9115-03668d178856"
            },
            {
                "provider_id": "CLEARSALE",
                "id": "92d2ea4b-4bf7-494b-aaea-c48276135941"
            }     
      }, 
    [...]
    ```

* **three\_d\_secure\_setup\_id**：仅使用我们的 JS 获取 `three_d_secure_setup_id`，然后以纯 API 集成的方式处理支付。Direct 工作流仅适用于符合 PCI 标准的商户。它提供了一种创建支付和验证用户信息的简便方式，商户只需发送 1 个请求即可创建支付。如需成功实施直接集成，请按照上文[支付](#payment)部分所述的步骤操作，并按说明提供所需信息。使用 Yuno 的 SDK 实施 3DS 时，无需使用此服务。

## 注册

![](https://mintcdn.com/yuno-3979e326/MTlogjS0_SlxtlJG/images/reference/direct-flow/image2.png?fit=max\&auto=format\&n=MTlogjS0_SlxtlJG\&q=85\&s=1579fa6a6a4233fe216bae5f3bb9b18d)

**1. 创建客户**

使用 [Create Customer](https://docs.y.uno/reference/customers/create-customer.md) endpoint 创建客户（如果客户尚不存在），以便关联支付方式。

**2. 注册支付方式**

> [!NOTE]
>
> **Direct Flow 集成**
>
> 此功能仅适用于符合 PCI 标准的商户注册银行卡。

通过 [Enroll Payment Method](https://docs.y.uno/reference/payment-methods-direct-workflow/enroll-payment-method-api.md) endpoint 注册支付方式。您将收到用于将来购买的 `vaulted_token`。


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