> ## 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 SDK 运行时，谁负责什么，以何种顺序进行。

每个集成都运行相同的顺序：您的 backend 创建会话，您的应用启动 `Transaction`，SDK 引导购物者到达最终状态并将其报告给 `onStatus`，Yuno 再向您的 backend 确认结果。不同集成之间的区别在于由谁创建支付，以及您传入哪个会话。下面的三种流程涵盖所有情况。

## 默认流程：由 SDK 创建支付

使用 `workflow: "SDK_SEAMLESS"` 创建结账会话，并且不要覆盖 `createPayment`。SDK 完成 `start` 与 `onStatus` 之间的所有工作。

```mermaid theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
sequenceDiagram
  autonumber
  participant Shopper
  participant App as Your app
  participant Backend as Your backend
  participant SDK as Yuno SDK
  participant Yuno as Yuno API
  App->>Backend: Start checkout
  Backend->>Yuno: POST /v1/checkout/sessions (workflow SDK_SEAMLESS)
  Yuno-->>Backend: checkout session
  Backend-->>App: checkout session
  App->>SDK: Transaction(config).start(paymentSelected)
  SDK->>Shopper: Form for the selected method
  Shopper-->>SDK: Payment details
  SDK->>Yuno: Tokenize (one-time token)
  SDK->>Yuno: Create the payment
  SDK->>Shopper: 3DS or payment action, if required
  SDK->>Yuno: Poll the payment status
  SDK-->>App: onStatus(status)
  Yuno-->>Backend: Payment webhook
```

1. 您的 backend 创建结账会话，并将其 ID 交给您的应用。
2. 您的应用初始化 SDK 一次，使用该会话和您的 controller 构建 `TransactionConfig`，并以购物者选择的支付方式调用 `start`。
3. SDK 渲染该支付方式的表单（当您传入 `transactionData` 时则跳过表单），并将详细信息令牌化为一次性令牌。
4. SDK 使用该令牌创建支付，运行 3DS 或该支付方式所需的任何其他操作，并轮询状态直至其成为最终状态。
5. `onStatus` 接收最终状态。在 iOS 上，异步支付方式会先报告 `PENDING`；请参阅 [`onStatus`](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/on-status)。如果 `showStatusScreen` 为 `true`，SDK 还会显示其结果页面。
6. Yuno 向您的 backend 发送支付 webhook。请在履行订单之前在那里确认结果。

## 当您的 backend 创建支付时

覆盖 `createPayment` 并保留默认的会话 workflow（`SDK_CHECKOUT`）。SDK 在令牌化之后暂停，将令牌交给您，并在您的处理程序返回时恢复。

```mermaid theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
sequenceDiagram
  autonumber
  participant Shopper
  participant App as Your app
  participant Backend as Your backend
  participant SDK as Yuno SDK
  participant Yuno as Yuno API
  App->>Backend: Start checkout
  Backend->>Yuno: POST /v1/checkout/sessions (default workflow)
  Yuno-->>Backend: checkout session
  Backend-->>App: checkout session
  App->>SDK: Transaction(config).start(paymentSelected)
  SDK->>Shopper: Form for the selected method
  Shopper-->>SDK: Payment details
  SDK->>Yuno: Tokenize (one-time token)
  SDK-->>App: createPayment(token)
  App->>Backend: one-time token
  Backend->>Yuno: POST /v1/payments
  Backend-->>App: payment created
  App-->>SDK: return from createPayment
  SDK->>Shopper: 3DS or payment action, if required
  SDK->>Yuno: Poll the payment status
  SDK-->>App: onStatus(status)
  Yuno-->>Backend: Payment webhook
```

区别在于第 9 步到第 13 步：SDK 将一次性令牌传递给 `createPayment`，您的 backend 创建支付，而从处理程序返回才会恢复流程。如果处理程序抛出异常，流程将停止，并且不会调用 `onStatus`。仅当您需要 SDK 在支付创建后立即停止时，才将 `autoContinuePayment` 设置为 `false`。在 Web 上，它仅在您覆盖 `createPayment` 时适用；在 iOS 上，它也适用于 SDK 自身的支付创建。随后 SDK 不运行 3DS，不轮询状态，也不会就该次尝试向 `onStatus` 报告任何内容。在 Web 上，PayPal 会忽略该标志并始终继续。请参阅 [`autoContinuePayment`](https://docs.y.uno/zh-hans/docs/yuno-sdk/reference/objects-you-pass#autocontinuepayment)。

> [!WARNING]
>
> 会话的 `workflow` 必须与创建支付的一方相匹配。使用默认 workflow 且没有覆盖 `createPayment` 的会话会以 `INTERNAL_ERROR` 结束：backend 会拒绝 SDK 的支付创建。请参阅 [`createPayment`](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/create-payment)。

## 注册：保存支付方式而不扣款

传入 `customerSession` 而不是 `checkoutSession`。由于没有需要创建的支付，因此永远不会调用 `createPayment`。

```mermaid theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
sequenceDiagram
  autonumber
  participant Shopper
  participant App as Your app
  participant Backend as Your backend
  participant SDK as Yuno SDK
  participant Yuno as Yuno API
  Backend->>Yuno: POST /v1/customers (once per customer)
  Backend->>Yuno: POST /v1/customers/sessions
  Yuno-->>Backend: customer session
  Backend-->>App: customer session
  App->>SDK: Transaction(config).start(paymentSelected)
  SDK->>Shopper: Form for the selected method
  Shopper-->>SDK: Payment details
  SDK->>Yuno: Tokenize and enroll
  SDK->>Shopper: 3DS, if required
  SDK-->>App: onStatus(status)
  Yuno-->>Backend: Enrollment webhook
  Backend->>Yuno: List the customer's payment methods
```

存储的令牌永远不会传递给应用。在 `onStatus` 报告成功后，您的 backend 从 Yuno 读取已注册的支付方式，并使用其存储的令牌进行未来的支付。

## 各步骤的文档位置

| 步骤 | 页面 |
| - | - |
| 创建会话和首笔支付 | [开始使用](https://docs.y.uno/zh-hans/docs/yuno-sdk/get-started.md) |
| 选择由谁创建支付、收集数据、渲染表单 | [我从哪里开始？](https://docs.y.uno/zh-hans/docs/yuno-sdk/where-do-i-start.md) |
| `createPayment` 和会话 workflow | [`createPayment`](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/create-payment) |
| 最终状态以及在您的服务器上确认它 | [`onStatus`](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/on-status) |
| 使用客户会话进行注册 | [注册](https://docs.y.uno/zh-hans/docs/yuno-sdk/features/enrollment.md) |
| 从外部应用或页面返回（iOS） | [处理 deeplink](https://docs.y.uno/zh-hans/docs/yuno-sdk/features/handle-deeplinks.md) |


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