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

# 快速入门指南

> 使用预构建的 checkout UI，在 Web、iOS 和 Android 上实现 Yuno 的完整支付流程

> [!NOTE]
>
> **This page documents a legacy SDK.** Starting a new integration? Use the [Yuno SDK](https://docs.y.uno/docs/yuno-sdk/get-started.md). Already on a legacy SDK? Follow the [migration guide](https://docs.y.uno/docs/yuno-sdk/migration/overview.md).
>
> The new **Yuno SDK** (Web v2.x, iOS v3.x, Android v3.x, React Native v2.x) replaces the Full, Lite, Seamless, Render, Headless, and Secure Fields SDKs with one API across every platform. Legacy SDKs remain supported side by side during the transition and are scheduled for deprecation in **2027**. Contact your Account Manager for migration planning.

欢迎阅读 Yuno SDK 快速入门指南。本指南向您展示如何轻松实现 Yuno 的完整支付流程，这是其最直接的解决方案，提供预构建 UI 并自动展示支付方式。

选择您的平台并按照步骤操作，开始使用 Yuno 处理您的首批支付。

> [tab] Web SDK 集成
>
> ### 1. 安装
>
> ```bash theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> npm install @yuno-payments/sdk-web
> ```
>
> 若要在页面加载时开始下载 SDK，请在您的 HTML `<head>` 中添加 preload 和 preconnect。请参阅[预加载 SDK 脚本](https://docs.y.uno/zh-hans/docs/sdks/resources/references/web.md#preload-the-sdk-script)。
>
> 或者通过 CDN 引入：
>
> ```html theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> <script src="https://sdk-web.y.uno/v1.11/main.js"></script>
> ```
>
> ### 2. 初始化并处理支付
>
> ```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> import { loadScript } from '@yuno-payments/sdk-web';
>
> // Load the SDK script, then initialize it with your public API key
> // (with the CDN script tag, skip the import and use window.Yuno in place of loadScript())
> const Yuno = await loadScript();
> const yuno = await Yuno.initialize('your-public-api-key');
>
> // Create checkout session on your backend
> // Your backend calls: POST https://api-sandbox.y.uno/v1/checkout/sessions
> // Backend adds: account_id, merchant_order_id, payment_description (server-side)
> const session = await fetch('/api/create-session', {
> method: 'POST',
> headers: { 'Content-Type': 'application/json' },
> body: JSON.stringify({
>     customer_id: 'customer-123',
>     amount: { currency: 'USD', value: 1000 },
>     country: 'US'
> })
> }).then(r => r.json());
>
> // Configure checkout
> await yuno.startCheckout({
> checkoutSession: session.checkout_session,
> elementSelector: '#payment-form',
> countryCode: 'US',
> language: 'en',
> async createPayment(oneTimeToken) {
>     // Your backend calls: POST https://api-sandbox.y.uno/v1/payments
>     // with header: X-Idempotency-Key
>     // and body: { account_id, description, country, merchant_order_id, amount,
>     //             checkout: { session }, payment_method: { token: oneTimeToken }, ... }
>     const payment = await fetch('/api/process-payment', {
>     method: 'POST',
>     headers: { 'Content-Type': 'application/json' },
>     body: JSON.stringify({
>         one_time_token: oneTimeToken,
>         checkout_session: session.checkout_session
>     })
>     }).then(r => r.json());
>
>     // Required for async payment methods (3DS, PIX, etc.)
>     await yuno.continuePayment();
> }
> });
>
> // Mount payment form
> await yuno.mountCheckout();
>
> // Start the payment when the shopper clicks your pay button
> document.getElementById('pay-button')?.addEventListener('click', async () => {
>     await yuno.startPayment();
> });
> ```
>
> ### 3. 添加 HTML 容器和支付按钮
>
> ```html theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> <div id="payment-form"></div>
> <button id="pay-button">Pay Now</button>
> ```
>
> 请参阅下方的[测试卡](#test-cards)。
>
> 如需全面了解所有 Web SDK 参数，请参阅 [Web SDK 通用参考](https://docs.y.uno/zh-hans/docs/sdks/resources/references/web.md)。
>
> [完整 Web 指南 →](https://docs.y.uno/docs/sdks/full-checkout/web-payments)
>
> 新 SDK 对应内容：[Web Full 模式迁移](https://docs.y.uno/zh-hans/docs/yuno-sdk/migration/web/full.md)。

> [tab] iOS
>
> ### 1. 安装
>
> YunoSDK 不再在 CocoaPods 上发布；最后一个 CocoaPods 版本是 2.30.0。从 2.31.0 起，请使用 Swift Package Manager 安装：
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> dependencies: [
>     .package(url: "https://github.com/yuno-payments/yuno-sdk-ios", .upToNextMajor(from: "2.31.0"))
> ]
> ```
>
> 然后将以下产品之一添加到您的应用 target 中，切勿同时添加两者：
>
> * `YunoSDK-Static`：静态 framework，相当于 CocoaPods 所提供的版本。
> * `YunoSDK`：动态 framework，通常的选择。
>
> 两者的模块名称相同，因此 `import YunoSDK` 无需更改。最低要求 iOS 14.0。
>
> ### 2. 初始化并实现 delegate
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> import UIKit
> import YunoSDK
>
> // Initialize in AppDelegate or App struct
> Yuno.initialize(
>     apiKey: "your-public-api-key",
>     config: YunoConfig()
> )
>
> // In your view controller - implement YunoPaymentFullDelegate
> class PaymentViewController: UIViewController, @preconcurrency YunoPaymentFullDelegate {
>
>     // Required delegate properties
>     var checkoutSession: String { "session-from-backend" }
>     var countryCode: String { "US" }
>     var language: String? { "en" }
>     var viewController: UIViewController? { self }
>
>     override func viewDidLoad() {
>         super.viewDidLoad()
>         Task { await displayPaymentMethods() }
>     }
>
>     func displayPaymentMethods() async {
>         // Get payment methods view
>         let paymentView: UIView = await Yuno.getPaymentMethodViewAsync(delegate: self)
>         view.addSubview(paymentView)
>         // Add constraints...
>     }
>
>     // Required: Create payment with one-time token
>     func yunoCreatePayment(with token: String) {
>         // Call your backend: POST /v1/payments
>         createPaymentOnBackend(token: token) { result in
>             // After payment creation, continue for async methods
>             Yuno.continuePayment()
>         }
>     }
>
>     // Required: Handle payment result
>     func yunoPaymentResult(_ result: Yuno.Result) {
>         switch result.status {
>         case .succeeded:
>             print("Payment succeeded!")
>         case .fail:
>             print("Payment failed")
>         case .processing:
>             print("Payment processing")
>         default:
>             break
>         }
>     }
>
>     // Required by YunoPaymentFullDelegate
>     func yunoDidSelect(paymentMethod: PaymentMethodSelected) {
>         // Enable your pay button
>     }
>
>     func yunoDidUnenrollSuccessfully(_ success: Bool) {}
>
>     func yunoUpdatePaymentMethodsViewHeight(_ height: CGFloat) {
>         // Update your payment view height constraint
>     }
>
>     // Start payment when user taps pay button
>     @IBAction func payButtonTapped(_ sender: UIButton) {
>         Yuno.startPayment(showPaymentStatus: true)
>     }
> }
> ```
>
> 请参阅下方的[测试卡](#test-cards)。
>
> 如需全面了解所有 iOS SDK 参数，请参阅 [iOS SDK 通用参考](https://docs.y.uno/zh-hans/docs/sdks/resources/references/ios.md)。
>
> [完整 iOS 指南 →](https://docs.y.uno/docs/sdks/full-checkout/ios-payments)
>
> 新 SDK 对应内容：[iOS Full 模式迁移](https://docs.y.uno/zh-hans/docs/yuno-sdk/migration/ios/payment/full.md)。

> [tab] Android
>
> ### 1. 安装
>
> **build.gradle**：
>
> ```groovy theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> repositories {
>     maven { url "https://yunopayments.jfrog.io/artifactory/snapshots-libs-release" }
> }
>
> dependencies {
>     implementation 'com.yuno.payments:android-sdk:2.27.0'
> }
> ```
>
> ### 2. 初始化并处理支付
>
> **在 Application 中初始化**：
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> import android.app.Application
> import com.yuno.sdk.Yuno
> import com.yuno.sdk.YunoConfig
>
> class MyApplication : Application() {
>     override fun onCreate() {
>         super.onCreate()
>         Yuno.initialize(
>             this,
>             apiKey = "your-public-api-key",
>             config = YunoConfig(
>                 keepLoader = true,
>             )
>         )
>     }
> }
> ```
>
> > [!NOTE]
> >
> > 有关 `keepLoader` 参数和强制性错误处理的详细说明，请参阅 [Android 参考指南](https://docs.y.uno/zh-hans/docs/sdks/resources/references/android.md#keeploader-parameter)。
>
> **在 Activity/Fragment 中**：
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> import android.os.Bundle
> import androidx.activity.ComponentActivity
> import androidx.activity.compose.setContent
> import androidx.compose.foundation.layout.Column
> import androidx.compose.foundation.layout.fillMaxSize
> import androidx.compose.foundation.rememberScrollState
> import androidx.compose.foundation.verticalScroll
> import androidx.compose.material3.Button
> import androidx.compose.material3.Text
> import androidx.compose.runtime.getValue
> import androidx.compose.runtime.mutableStateOf
> import androidx.compose.runtime.remember
> import androidx.compose.runtime.setValue
> import androidx.compose.ui.Modifier
> import androidx.lifecycle.lifecycleScope
> import com.yuno.presentation.core.components.PaymentMethodListViewComponent
> import com.yuno.sdk.payments.continuePayment
> import com.yuno.sdk.payments.startCheckout
> import com.yuno.sdk.payments.startPayment
> import kotlinx.coroutines.launch
>
> class PaymentActivity : ComponentActivity() {
>     private var checkoutSession: String? = null
>
>     override fun onCreate(savedInstanceState: Bundle?) {
>         super.onCreate(savedInstanceState)
>
>         // Create checkout session on your backend first
>         // Your backend calls: POST https://api-sandbox.y.uno/v1/checkout/sessions
>         lifecycleScope.launch {
>             val session = createCheckoutSession() // Your backend call
>             checkoutSession = session.id
>
>             // Start checkout with session
>             startCheckout(
>                 checkoutSession = session.id,
>                 countryCode = "US",
>                 callbackPaymentState = { state, subState, message ->
>                     when (state) {
>                         "SUCCEEDED" -> println("Payment succeeded!")
>                         "FAIL" -> println("Payment failed: ${message?.code}")
>                         "PROCESSING" -> println("Payment processing")
>                         "REJECT" -> println("Payment rejected: ${message?.reason}")
>                         else -> println("Payment state: $state")
>                     }
>                 }
>             )
>         }
>
>         setContent {
>             var paymentMethodSelected by remember { mutableStateOf(false) }
>
>             Column(
>                 modifier = Modifier
>                     .fillMaxSize()
>                     .verticalScroll(rememberScrollState())
>             ) {
>                 // Display payment methods
>                 PaymentMethodListViewComponent(
>                     activity = this@PaymentActivity,
>                     onPaymentSelected = { isSelected, _ ->
>                         paymentMethodSelected = isSelected
>                     }
>                 )
>
>                 // Pay button
>                 Button(
>                     onClick = {
>                         startPayment(
>                             showPaymentStatus = true,
>                             callbackOTT = { token ->
>                                 token?.let { ott ->
>                                     lifecycleScope.launch {
>                                         // Call your backend: POST /v1/payments
>                                         // with { payment_method: { token: ott }, checkout_session: ... }
>                                         createPayment(ott, checkoutSession!!)
>
>                                         // Required for async payment methods
>                                         continuePayment()
>                                     }
>                                 }
>                             }
>                         )
>                     },
>                     enabled = paymentMethodSelected
>                 ) {
>                     Text("Pay Now")
>                 }
>             }
>         }
>     }
> }
> ```
>
> 请参阅下方的[测试卡](#test-cards)。
>
> 如需全面了解所有 Android SDK 参数，请参阅 [Android SDK 通用参考](https://docs.y.uno/zh-hans/docs/sdks/resources/references/android.md)。
>
> [完整 Android 指南 →](https://docs.y.uno/docs/sdks/full-checkout/android-payments)
>
> 新 SDK 对应内容：[Android Full 模式迁移](https://docs.y.uno/zh-hans/docs/yuno-sdk/migration/android/payment/full.md)。

## 处理失败的支付

新 SDK 对应内容：[onStatus](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/on-status.md) 控制器。

Web SDK 可以在不重新加载页面的情况下从失败的支付中恢复。两种机制协同工作：

* *支付重试*：当支付返回 `DECLINED` 或 `ERROR` 时进行内联卡片重试。在 *Seamless* 中，SDK 会自动处理重试。在 *Full Checkout*、*Lite* 和 *Secure Fields* 中，您需要在 backend 确认拒绝后调用 `continuePayment`。适用于未注册的信用卡和借记卡。完整参考请参阅[支付重试](https://docs.y.uno/zh-hans/docs/sdks/resources/references/web.md#payment-retry)。

* *切换支付方式*：调用 `updateCheckoutSession(newSession)` 注入新的结账会话，而无需卸载 SDK。会话切换后，从已渲染的支付方式列表中进行选择是可行的；而*不同的*一组支付方式则需要卸载并重新挂载 SDK，而不是重新加载页面。请参阅 [updateCheckoutSession](https://docs.y.uno/zh-hans/docs/sdks/resources/references/web.md#updatecheckoutsession)。

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Inside your createPayment callback:
const payment = await createPaymentOnYourBackend(oneTimeToken);

const isCard = payment.payment_method?.type === 'CARD';
const failed = payment.status === 'DECLINED' || payment.status === 'ERROR';

if (isCard && failed) {
  // Card retry: keeps the card form open with the decline shown.
  await yuno.continuePayment();
} else if (payment.checkout?.sdk_action_required) {
  // Additional action: 3DS, bank redirect, etc.
  await yuno.continuePayment({ showPaymentStatus: true });
} else {
  // No further SDK action — unmount.
  await yuno.unmountSdk();
}
```

> [!NOTE]
>
> 在重试的尝试中，SDK **不会**触发 `paymentResult`。它会将克隆的结账会话以 `{ type: 'PAYMENT_RETRY', data: { newCheckoutSession } }` 的形式传递给您的 `onLoading` callback。请在您的 `startCheckout` 配置中注册 `onLoading` 以接收它：
>
> ```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> await yuno.startCheckout({
>   checkoutSession: session.checkout_session,
>   // ...
>   onLoading: ({ type, data }) => {
>     if (type === 'PAYMENT_RETRY') {
>       // A fresh session has been cloned for the retry.
>       const newCheckoutSession = data.newCheckoutSession;
>     }
>   }
> });
> ```

## Backend 集成

您的 backend 必须实现两个 API endpoint 才能与 Yuno 配合使用。新 SDK 使用相同的结账会话：请参阅[创建结账会话](https://docs.y.uno/zh-hans/docs/yuno-sdk/get-started.md#create-the-checkout-session-backend)。

### 创建结账会话

在显示支付 UI 之前，您的 backend 会创建结账会话：

* **Endpoint**：`POST https://api-sandbox.y.uno/v1/checkout/sessions`
* **必填（OpenAPI）**：`account_id`、`merchant_order_id`、`payment_description`、`country`
* **还需发送**：`customer_id`（来自 Create Customer）和 `amount` `{ currency, value }`
* **SDK 可选参数**：`workflow`（`SDK_CHECKOUT` | `SDK_SEAMLESS` | `CHECKOUT`）、`callback_url`、`checkout_id`
* **返回**：`checkout_session` ID（在 SDK 中使用）
* **参考**：[创建结账会话 API](https://docs.y.uno/zh-hans/reference/checkout-sessions/create-checkout-session.md)

**请求示例**：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "account_id": "YOUR_ACCOUNT_ID",
  "merchant_order_id": "order-001",
  "payment_description": "Sandbox quickstart payment",
  "country": "US",
  "customer_id": "YOUR_CUSTOMER_UUID",
  "amount": {
    "currency": "USD",
    "value": 100
  },
  "workflow": "SDK_CHECKOUT"
}
```

### 创建支付

在一次性令牌（OTT）callback 中，您的 backend 会创建支付：

* **Endpoint**：`POST https://api-sandbox.y.uno/v1/payments`
* **必需标头**：`X-Idempotency-Key`（每次尝试唯一的 UUID），请参阅[身份验证](https://docs.y.uno/reference/getting-started/authentication.md)
* **必填请求体（OpenAPI）**：`account_id`、`description`、`country`、`merchant_order_id`、`amount`、`payment_method`、`checkout`
* **`payment_method.token`** = 来自 SDK callback 的一次性令牌
* **`checkout.session`** = 来自步骤 1 的结账会话 ID
* **返回**：支付状态和 `sdk_action_required` 字段
* **参考**：[创建支付 API](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)

**标头示例**：

```http theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
public-api-key: YOUR_PUBLIC_API_KEY
private-secret-key: YOUR_PRIVATE_SECRET_KEY
X-Idempotency-Key: YOUR_UUID
content-type: application/json
accept: application/json
```

**请求示例**：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "account_id": "YOUR_ACCOUNT_ID",
  "description": "Sandbox quickstart payment",
  "country": "US",
  "merchant_order_id": "order-001",
  "amount": {
    "currency": "USD",
    "value": 100
  },
  "customer_payer": {
    "id": "YOUR_CUSTOMER_UUID"
  },
  "checkout": {
    "session": "YOUR_CHECKOUT_SESSION_UUID"
  },
  "payment_method": {
    "token": "ONE_TIME_TOKEN_FROM_SDK"
  }
}
```

**重要**：如果 API 响应包含 `sdk_action_required: true` 或 `checkout.sdk_action_required: true`，您必须调用 SDK 的 `continuePayment()` 方法来完成异步支付方式（3DS 认证、PIX、银行重定向等）。

## 参数

本快速入门中使用的主要参数：

| 参数 | 描述 |
| - | - |
| `publicKey` / `apiKey` | 您的 Yuno 公共 API 密钥（frontend）。可从 [Yuno Dashboard](https://dashboard.y.uno/) → **Developers** > **Credentials** 获取。 |
| `checkoutSession` | 由您的 backend 返回的结账会话 ID（创建会话 endpoint）。开始支付时必需。 |
| `countryCode` | 支付的 ISO 国家代码（例如 `US`、`CO`）。请参阅[国家覆盖范围](https://docs.y.uno/zh-hans/docs/sdks/resources/country-coverage.md)。 |
| `elementSelector`（Web） | 挂载支付表单的元素的 CSS 选择器（例如 `#payment-form`）。 |

完整参数参考：[支付流程（Web）](https://docs.y.uno/docs/sdks/full-checkout/web-payments)、[支付流程（iOS）](https://docs.y.uno/docs/sdks/full-checkout/ios-payments)、[支付流程（Android）](https://docs.y.uno/docs/sdks/full-checkout/android-payments)。

## 替代集成方式

如果您需要对用户界面或特定支付流程进行更多控制，Yuno 提供了替代集成方式：

### Lite SDK

一种轻量级集成，让您完全控制支付方式的展示，同时由 Yuno 负责安全的支付处理。

* [Web 实现](https://docs.y.uno/zh-hans/docs/sdks/lite-web/payment.md)
* [Android 实现](https://docs.y.uno/zh-hans/docs/sdks/lite-android/checkout.md)
* [iOS 实现](https://docs.y.uno/zh-hans/docs/sdks/lite-ios/checkout.md)
* 新 SDK 对应内容：[Web Lite 模式迁移](https://docs.y.uno/zh-hans/docs/yuno-sdk/migration/web/lite.md)

### Secure Fields

使用 Yuno 的 UI 组件从零开始构建您自己的支付表单，实现最大程度的自定义（仅限 Web）。

* [Secure Fields 指南](https://docs.y.uno/docs/sdks/customization/secure-fields/index)
* 新 SDK 对应内容：[Secure Fields](https://docs.y.uno/zh-hans/docs/yuno-sdk/features/secure-fields.md)

## 测试卡

新 SDK 有自己的列表：请参阅[测试卡](https://docs.y.uno/zh-hans/docs/yuno-sdk/get-started.md#test-cards)。

| 卡号 | 场景 |
| - | - |
| 4111 1111 1111 1111 | 成功 |
| 4000 0000 0000 0002 | 已拒绝 |
| 4000 0000 0000 3220 | 3DS 挑战 |


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