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

# NuPay

> 通过 Yuno 的 SDK 或 Direct API 工作流接受 NuPay 支付。NuPay 是 NuBank 推出的数字支付方式，支持一次性支付、注册和 2FA 模式。

本指南介绍如何将 NuBank 推出的数字支付方式 NuPay 集成到您的 checkout 中。Yuno 同时支持 **Yuno SDK**（推荐）和 **Direct API** 两种工作流。您将了解如何：

* 将 NuPay 注册为客户的支付方式
* 无需注册即可进行支付（2FA 模式）
* 使用分期付款进行支付（支付条件）
* 设置订阅

## 要求

开始之前，您需要：

* 一个可访问 Dashboard 的 Yuno 账户
* API 密钥和 `account_id`（可在 Dashboard 中找到）
* 在 Yuno 中创建的客户（或在步骤 1 中创建）

## 创建和管理客户

使用您的外部 `merchant_customer_id` 创建一次客户，之后根据需要通过 Yuno `id` 或 `merchant_customer_id` 检索客户。

1. 使用[创建客户](https://docs.y.uno/reference/customers/create-customer.md) endpoint，并提供您自己的 `merchant_customer_id`（客户在您系统中的唯一 ID）。响应会返回 `id`，即 Yuno 客户 ID。
2. 使用 Yuno `id` 调用[检索客户](https://docs.y.uno/reference/customers/retrieve-customer.md)。
3. 使用查询参数 `merchant_customer_id` 调用[按外部 ID 检索客户](https://docs.y.uno/reference/customers/retrieve-customer-by-external-id.md)。

## 注册 NuPay 支付方式

按照以下步骤为客户注册 `NU_PAY_ENROLLMENT` 支付方式。

> [tab] Yuno SDK
>
> 通过 SDK 集成，Yuno 会负责展示 NuPay 支付方式、将客户重定向到 NuBank 进行身份验证，并管理返回流程。
>
> ### 步骤 1：创建客户
>
> 使用[创建客户](https://docs.y.uno/reference/customers/create-customer.md) endpoint 创建客户，并获取其 Yuno 客户 `id`。
>
> ### 步骤 2：创建客户会话
>
> 使用客户 `id` 和[创建客户会话](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session.md) endpoint 获取 `customer_session`。
>
> ### 步骤 3：初始化 SDK 并注册
>
> 使用 `customer_session` 初始化 Yuno 的 SDK（Web、Android 或 iOS）。
>
> 如果使用 SDK checkout 或 headless 集成，请调用[注册支付方式（Checkout）](https://docs.y.uno/reference/payment-methods-checkout/enroll-payment-method-checkout.md)（`POST /customers/sessions/{customer_session}/payment-methods`），并将 `payment_method_type` 设为 `NU_PAY_ENROLLMENT`。
>
> SDK 会自动展示 NuPay 支付方式，管理客户到 NuBank 的重定向，并处理身份验证流程。
>
> ### 步骤 4：确认注册
>
> 监听 [webhooks](https://docs.y.uno/zh-hans/docs/webhooks.md) 或检索已注册的支付方式，以确认状态为 `ENROLLED`。

> [tab] Direct API
>
> 按照以下步骤，使用 Direct 工作流为客户注册 `NU_PAY_ENROLLMENT`。
>
> ### 步骤 1：创建客户
>
> 如果您还没有客户，请按上文所示创建一个。您将使用返回的客户 `id`。
>
> ### 步骤 2：注册支付方式
>
> 使用[注册支付方式](https://docs.y.uno/reference/payment-methods-direct-workflow/enroll-payment-method-api.md)，并提供以下请求参数：
>
> * **type**：`NU_PAY_ENROLLMENT`
> * **account\_id**：您账户的 UUID（来自 Yuno Dashboard）
> * **workflow**：`DIRECT`
>
> 预期的响应字段：
>
> * **vaulted\_token**：已注册支付方式的 UUID
> * **status**：`READY_TO_ENROLL`
> * **sub\_status**：`WAITING_ADDITIONAL_STEP`
> * **action**：`REDIRECT_URL`
> * **redirect\_url**：用于将客户重定向到 Nu 进行身份验证的 URL
>
> ### 步骤 3：重定向客户
>
> 将客户重定向到 `redirect_url`。客户完成 Nu 流程后，Nu 会将最终状态通知 Yuno。
>
> ### 步骤 4：确认注册
>
> 使用 `vaulted_token` 调用[按 ID 检索已注册的支付方式](https://docs.y.uno/reference/payment-methods-direct-workflow/retrieve-enrolled-payment-method-by-id-api.md)。注册成功时返回：
>
> * **status**：`ENROLLED`
>
> * **sub\_status**：`ENROLLED`
>
> > [!WARNING]
> >
> > 只有在 Yuno 收到 Nu 的确认后，注册才算完成。

## 无需注册的支付（2FA 模式）

您可以接受 NuPay 一次性支付，而无需客户注册其支付方式。这通常称为 **2FA 模式**，因为客户需要对每笔交易单独进行身份验证。

> [tab] Yuno SDK
>
> 使用 Yuno 的 SDK 接受无需注册的支付。SDK 会负责展示 NuPay，并重定向客户以完成身份验证。
>
> ### 步骤 1：创建结账会话
>
> 首先使用[创建结账会话](https://docs.y.uno/zh-hans/reference/checkout-sessions/create-checkout-session.md) endpoint 创建结账会话。
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "country": "BR",
>   "customer_id": "{{customer_id}}",
>   "merchant_order_id": "order-0000024",
>   "amount": {
>     "currency": "BRL",
>     "value": 15000
>   }
> }
> ```
>
> 响应会返回 `checkout_session` ID。
>
> ### 步骤 2：初始化 SDK
>
> 使用 `checkout_session` ID 初始化 Yuno 的 SDK（Web、Android 或 iOS）。NuPay 会自动作为可用的支付选项显示在 SDK 界面中。
>
> ### 步骤 3：客户完成支付
>
> 当客户选择 NuPay 时：
>
> 1. SDK 提示客户进行身份验证。
> 2. 客户被重定向到 Nu 进行 2FA 身份验证。
> 3. SDK 接收结果，并通过 Yuno 处理支付。
>
> ### 步骤 4：处理 SDK 工作流支付（可选）
>
> 如果您在使用 SDK checkout 的同时直接调用 Yuno 支付 API，请将 `workflow` 设为 `SDK_CHECKOUT`，并传递 `checkout.session` 令牌：
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "description": "One-time NuPay Payment via SDK",
>   "account_id": "{{account_id}}",
>   "merchant_order_id": "0000024",
>   "country": "BR",
>   "amount": {
>     "currency": "BRL",
>     "value": 150
>   },
>   "customer_payer": {
>     "id": "{{customer_id}}"
>   },
>   "workflow": "SDK_CHECKOUT",
>   "checkout": {
>     "session": "{{checkout_session_id}}"
>   },
>   "payment_method": {
>     "type": "NU_PAY"
>   }
> }
> ```

> [tab] Direct API
>
> ### 步骤 1：创建支付
>
> 使用 Direct 工作流和 `NU_PAY` 支付方式类型调用[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)。在此模式下，您不需要 `vaulted_token`。
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "description": "One-time NuPay Payment",
>   "account_id": "{{account_id}}",
>   "merchant_order_id": "0000024",
>   "country": "BR",
>   "amount": {
>     "currency": "BRL",
>     "value": 150
>   },
>   "customer_payer": {
>     "id": "{{customer_id}}"
>   },
>   "workflow": "DIRECT",
>   "callback_url": "https://your-callback.com",
>   "payment_method": {
>     "type": "NU_PAY"
>   }
> }
> ```
>
> ### 步骤 2：处理响应
>
> 由于此模式需要客户身份验证，响应将返回一个用于重定向用户的操作。
>
> * **status**：`READY_TO_PAY`
> * **sub\_status**：`WAITING_ADDITIONAL_STEP`
> * **action**：`REDIRECT_URL`
> * **redirect\_url**：用于将客户重定向到 Nu 进行 2FA 身份验证的 URL。
>
> ### 步骤 3：确认支付
>
> 客户完成身份验证后，使用[按 ID 检索支付](https://docs.y.uno/reference/payments/retrieve-payment-by-id)确认最终状态。

## 带支付条件的支付（分期付款）

NuPay 同时支持对已注册的支付方式和一次性支付（2FA 模式）使用分期付款。

> [tab] Yuno SDK
>
> 在 SDK 中，NuPay 支持对已注册的支付方式和一次性支付（2FA 模式）使用分期付款。
>
> ### 步骤 1：获取支付条件
>
> 根据所用流程，使用 [APM 分期付款](https://docs.y.uno/reference/installments/apm-installments) endpoint 请求可用的分期付款选项：
>
> > [tab] 注册流程
> >
> > ```bash theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> > curl -X POST --location 'https://api-sandbox.y.uno/v1/apm-installments' \
> > --header 'public-api-key: {{your_public_api_key}}' \
> > --header 'private-secret-key: {{your_secret_api_key}}' \
> > --header 'X-account-code: {{your_account_id}}' \
> > --header 'Content-Type: application/json' \
> > --data '{
> >   "country": "BR",
> >   "amount": {
> >     "currency": "BRL",
> >     "value": "250"
> >   },
> >   "customer": {
> >     "id": "{{customer_id}}"
> >   },
> >   "payment_method": "NU_PAY_ENROLLMENT",
> >   "vaulted_token": "{{vaulted_token}}"
> > }'
> > ```
>
> > [tab] 2FA 模式
> >
> > ```bash theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> > curl -X POST --location 'https://api-sandbox.y.uno/v1/apm-installments' \
> > --header 'public-api-key: {{your_public_api_key}}' \
> > --header 'private-secret-key: {{your_secret_api_key}}' \
> > --header 'X-account-code: {{your_account_id}}' \
> > --header 'Content-Type: application/json' \
> > --data '{
> >   "country": "BR",
> >   "payment_method": "NU_PAY",
> >   "amount": {
> >     "currency": "BRL",
> >     "value": "250"
> >   },
> >   "customer": {
> >     "document": {
> >       "document_type": "CPF",
> >       "document_number": "52998224725"
> >     },
> >     "email": "customer@email.com"
> >   }
> > }'
> > ```
>
> 从响应中选择计划 `id` 和分期期数。
>
> ### 步骤 2：使用 SDK 工作流创建支付
>
> 使用 SDK 工作流创建支付：设置 `workflow: "SDK_CHECKOUT"`，并传递 `checkout.session` 以及计划详情：
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "description": "NuPay Installment Payment via SDK",
>   "account_id": "{{account_id}}",
>   "merchant_order_id": "0000023",
>   "country": "BR",
>   "amount": {
>     "currency": "BRL",
>     "value": 250
>   },
>   "customer_payer": {
>     "id": "{{customer_id}}"
>   },
>   "workflow": "SDK_CHECKOUT",
>   "checkout": {
>     "session": "{{checkout_session_id}}"
>   },
>   "payment_method": {
>     "type": "NU_PAY_ENROLLMENT",
>     "vaulted_token": "{{vaulted_token}}",
>     "detail": {
>       "wallet": {
>         "card_data": {
>           "installments_plan_id": "{{plan_id}}",
>           "installments": 2
>         }
>       }
>     }
>   }
> }
> ```

> [tab] Direct API
>
> ### 步骤 1：确认前提条件
>
> 根据所用流程，您需要：
>
> * **注册流程**：Yuno 客户 `id` 和已注册的 NuPay `vaulted_token`。
> * **2FA 模式**：客户详细信息，特别是其税号（CPF）和 email。
>
> ### 步骤 2：获取支付条件
>
> 使用 [APM 分期付款](https://docs.y.uno/reference/installments/apm-installments) endpoint 请求 NuPay 的可用分期付款选项。请求参数因集成流程而异。
>
> > [tab] 注册流程
> >
> > ```bash theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> > curl -X POST --location 'https://api-sandbox.y.uno/v1/apm-installments' \
> > --header 'public-api-key: {{your_public_api_key}}' \
> > --header 'private-secret-key: {{your_secret_api_key}}' \
> > --header 'X-account-code: {{your_account_id}}' \
> > --header 'Content-Type: application/json' \
> > --data '{
> >   "country": "BR",
> >   "amount": {
> >     "currency": "BRL",
> >     "value": "250"
> >   },
> >   "customer": {
> >     "id": "{{customer_id}}"
> >   },
> >   "payment_method": "NU_PAY_ENROLLMENT",
> >   "vaulted_token": "{{vaulted_token}}"
> > }'
> > ```
>
> > [tab] 2FA 模式
> >
> > ```bash theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> > curl -X POST --location 'https://api-sandbox.y.uno/v1/apm-installments' \
> > --header 'public-api-key: {{your_public_api_key}}' \
> > --header 'private-secret-key: {{your_secret_api_key}}' \
> > --header 'X-account-code: {{your_account_id}}' \
> > --header 'Content-Type: application/json' \
> > --data '{
> >   "country": "BR",
> >   "payment_method": "NU_PAY",
> >   "amount": {
> >     "currency": "BRL",
> >     "value": "250"
> >   },
> >   "customer": {
> >     "document": {
> >       "document_type": "CPF",
> >       "document_number": "52998224725"
> >     },
> >     "email": "customer@email.com"
> >   }
> > }'
> > ```
>
> 响应会返回一个分期付款计划数组，包括 `id`、可用的 `installments` 和金额。选择一个计划 `id` 和允许的分期期数。
>
> ### 步骤 3：创建支付
>
> 使用 Direct 工作流和 NuPay 类型调用[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)。在钱包的 `card_data` 中包含所选的计划 ID 和分期期数。
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "description": "test",
>   "account_id": "{{account_id}}",
>   "merchant_order_id": "0000023",
>   "country": "BR",
>   "merchant_reference": "ref-merchant-AA01",
>   "amount": {
>     "currency": "BRL",
>     "value": 250
>   },
>   "customer_payer": {
>     "id": "{{customer_id}}"
>   },
>   "workflow": "DIRECT",
>   "callback_url": "https://your-callback.com",
>   "payment_method": {
>     "type": "NU_PAY_ENROLLMENT",
>     "vaulted_token": "{{vaulted_token}}",
>     "detail": {
>       "wallet": {
>         "card_data": {
>           "installments_plan_id": "{{plan_id}}",
>           "installments": 2
>         }
>       }
>     }
>   }
> }
> ```
>
> ### 步骤 4：检索支付
>
> 使用[按 ID 检索支付](https://docs.y.uno/reference/payments/retrieve-payment-by-id)确认最终状态。

## 订阅流程

您可以使用 NuPay 进行定期扣款。

> [tab] Yuno SDK
>
> 使用 SDK 注册令牌，即可轻松设置 NuPay 定期支付或订阅：
>
> 1. 创建客户。
> 2. 通过 Yuno SDK（Checkout 工作流）注册 NuPay，以获取 `vaulted_token`。
> 3. 使用[创建订阅](https://docs.y.uno/reference/subscriptions/create-subscription.md) endpoint，以已注册的 `vaulted_token` 创建订阅。
> 4. 根据需要检索和管理订阅状态。

> [tab] Direct API
>
> 1. 创建客户
> 2. 将 NuPay 注册为支付方式（见上文）
> 3. 使用[创建订阅](https://docs.y.uno/reference/subscriptions/create-subscription.md)，以已注册的 `vaulted_token` 创建订阅
> 4. 使用[检索订阅](https://docs.y.uno/reference/subscriptions/retrieve-subscription.md)检索订阅

> [!NOTE]
>
> **限制**
>
> * NuPay 订阅不支持支付条件（分期付款）
> * 不支持直接在支付请求中创建订阅

## Endpoints

* [创建客户](https://docs.y.uno/reference/customers/create-customer.md)
* [检索客户](https://docs.y.uno/reference/customers/retrieve-customer.md)
* [按外部 ID 检索客户](https://docs.y.uno/reference/customers/retrieve-customer-by-external-id.md)
* [注册支付方式（Direct）](https://docs.y.uno/reference/payment-methods-direct-workflow/enroll-payment-method-api.md)
* [注册支付方式（Checkout）](https://docs.y.uno/reference/payment-methods-checkout/enroll-payment-method-checkout.md)
* [按 ID 检索已注册的支付方式](https://docs.y.uno/reference/payment-methods-direct-workflow/retrieve-enrolled-payment-method-by-id-api.md)
* [创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)
* [按 ID 检索支付](https://docs.y.uno/reference/payments/retrieve-payment-by-id)
* [APM 分期付款](https://docs.y.uno/reference/installments/apm-installments)
* [创建订阅](https://docs.y.uno/reference/subscriptions/create-subscription.md)
* [检索订阅](https://docs.y.uno/reference/subscriptions/retrieve-subscription.md)


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