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

# PagaLeve

> 通过 PagaLeve 接受 Pix Parcelado（分期付款 Pix）和一次性 Pix 支付，可使用 Yuno 的 SDK 或 Direct API 工作流。

本指南介绍如何将 PagaLeve（一家面向巴西、基于 Pix 的支付服务提供商）集成到您的 checkout 中。Yuno 同时支持 **Yuno SDK**（推荐）和 **Direct API** 工作流。您将了解如何：

* 使用 PagaLeve 进行一次性 Pix 支付
* 使用 PagaLeve 进行 Pix Parcelado（分期付款 Pix）支付

## 要求

开始之前，您需要：

* 拥有 Dashboard 访问权限的 Yuno 账户
* API 密钥和 `account_id`（可在 Dashboard 中找到）
* 在您的 Yuno 账户中设置好的 PagaLeve 连接（请参阅[连接](https://docs.y.uno/zh-hans/docs/using-yuno/dashboard-overview/connections.md)）

## 创建和管理客户

使用您的外部 `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)。

> [!TIP]
>
> 无需先创建 Yuno 客户记录。PagaLeve 直接在创建支付调用中接受客户信息（CPF、email、姓名、电话、出生日期、地址），与普通 Pix 相同。仍建议预先创建客户，以便与您的其他支付方式保持一致。

## 一次性 Pix 支付

使用 PagaLeve 接受标准的单笔 Pix 支付。

> [tab] Yuno SDK
>
> ### 步骤 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"}}
> {
>   "account_id": "{{account_id}}",
>   "country": "BR",
>   "customer_id": "{{customer_id}}",
>   "merchant_order_id": "order-0000024",
>   "payment_description": "One-time Pix Payment with PagaLeve",
>   "amount": {
>     "currency": "BRL",
>     "value": 15000
>   }
> }
> ```
>
> 响应会返回 `checkout_session` ID。
>
> ### 步骤 2：初始化 SDK
>
> 使用 `checkout_session` ID 初始化 Yuno 的 SDK（Web、Android 或 iOS）。PagaLeve 会在 SDK 界面中显示为可用的支付选项，一次性支付使用支付方式类型 `"PIX"`。
>
> > [!TIP]
> >
> > 客户在 PagaLeve 托管的 checkout 页面上完成支付。如果您的 PagaLeve 连接启用了 `TRANSPARENT_CHECKOUT`，客户则改为通过 checkout URL 在 SDK 内完成支付。无论哪种方式，PagaLeve 都会通过 webhook 向 Yuno 确认结果。请参阅下方的[状态转换](#status-transitions)。

> [tab] Direct API
>
> ### 步骤 1：创建支付
>
> 通过 Direct 工作流使用[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)。
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "description": "One-time Pix Payment with PagaLeve",
>   "account_id": "{{account_id}}",
>   "merchant_order_id": "0000024",
>   "country": "BR",
>   "amount": {
>     "currency": "BRL",
>     "value": 150
>   },
>   "customer_payer": {
>     "id": "{{customer_id}}"
>   },
>   "callback_url": "https://your-callback.com",
>   "workflow": "DIRECT",
>   "payment_method": {
>     "type": "PIX"
>   }
> }
> ```
>
> > [!TIP]
> >
> > 响应会在支付方式详情中返回 checkout 的 `redirect_url`。将客户重定向到该地址以完成支付；PagaLeve 通过 webhook 向 Yuno 确认结果。有关 PagaLeve 的状态如何对应 Yuno 的状态，请参阅下方的[状态转换](#status-transitions)。
>
> ### 步骤 2：确认支付
>
> 使用[按 ID 检索支付](https://docs.y.uno/reference/payments/retrieve-payment-by-id)确认最终状态。

## Pix Parcelado（分期付款）支付

PagaLeve 支持 Pix Parcelado，让客户将一笔 Pix 支付拆分为分期付款。客户在 PagaLeve 自己的 checkout 页面上选择分期付款方案：Yuno 不会预先返回可用方案，创建支付调用中也不会发送任何方案或分期付款数据。

> [tab] Yuno SDK
>
> ### 步骤 1：创建支付
>
> 使用 `payment_method.type` `"PIX_PARCELADO"` 创建支付。在 `additional_data.order.items` 中传入订单的明细项，以便 PagaLeve 生成分期付款报价。
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "description": "Pix Parcelado Payment with PagaLeve",
>   "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": "PIX_PARCELADO"
>   },
>   "additional_data": {
>     "order": {
>       "items": [
>         {
>           "id": "{{sku}}",
>           "name": "{{item_name}}",
>           "quantity": 1,
>           "unit_amount": 250,
>           "category": "{{item_category}}"
>         }
>       ]
>     }
>   }
> }
> ```
>
> > [!TIP]
> >
> > 响应会在 `payment_method.payment_method_detail.bank_transfer.redirect_url` 中返回重定向地址：Pix Parcelado 在内部归类为 `BANK_TRANSFER`，因此它与其他银行转账方式使用相同的详情对象。`installments` 和 `installments_plan_id` 在创建时返回为空；客户在重定向后于 PagaLeve 托管的 checkout 页面上选择分期期数。支付的初始状态为 `Created`，最终的 `Successful` 或已拒绝状态通过 webhook 送达。请参阅下方的[状态转换](#status-transitions)。

> [tab] Direct API
>
> ### 步骤 1：创建支付
>
> 通过 Direct 工作流并使用 `payment_method.type` `"PIX_PARCELADO"` 调用[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)。在 `additional_data.order.items` 中传入订单的明细项，格式与上方 SDK 选项卡中所示相同。
>
> > [!TIP]
> >
> > 有关 PagaLeve 如何报告状态变化，请参阅下方的[状态转换](#status-transitions)；有关响应中重定向 URL 的返回位置以及客户选择分期付款方案的位置，请参阅上方的 SDK 选项卡。
>
> ### 步骤 2：检索支付
>
> 使用[按 ID 检索支付](https://docs.y.uno/reference/payments/retrieve-payment-by-id)确认最终状态。

> [!NOTE]
>
> **限制**
>
> * 币种仅限 BRL。
> * Pix 和 Pix Parcelado 共用同一退款流程，两者的退款方式相同，包括 `DUPLICATE`、`FRAUDULENT` 和 `REQUESTED_BY_CUSTOMER` 原因。
> * 与 NuPay 不同，PagaLeve 不使用注册或 vault 存储模式。每笔支付都是一次性 checkout。

## 状态转换

PagaLeve 通过 webhooks 报告支付状态，并以异步方式处理。对于 `CANCELED` 和 `EXPIRED`，webhook 会直接发布该状态。对于其他成功状态，它会先通过 `ProcessPayment` endpoint 捕获该支付。

| PagaLeve 状态 | Yuno 状态 |
| - | - |
| `NEW` | 已创建 |
| `ACCEPTED` | 待处理（等待服务提供商确认） |
| `AUTHORIZED` | 成功 |
| `COMPLETED` | 成功 |
| `RELEASED` | 成功 |
| `CAPTURED` | 成功 |
| `CANCELED` | 已被用户取消 |
| `EXPIRED` | 已被服务提供商设为过期 |
| `PAYMENT_DECLINED` | 已被服务提供商拒绝 |

## 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)
* [创建结账会话](https://docs.y.uno/zh-hans/reference/checkout-sessions/create-checkout-session.md)
* [创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)
* [按 ID 检索支付](https://docs.y.uno/reference/payments/retrieve-payment-by-id)


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