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

# Seamless 模式

> 将 Web Seamless 集成（yuno.startSeamlessCheckout + yuno.mountSeamlessCheckout / mountSeamlessExternalButtons）迁移到统一的 Transaction API。

Seamless 模式是**由 SDK 管理的变体**：SDK 在内部创建支付，商户只需选择何时以及在何处渲染表单，并通过 `yuno.startPayment()` 触发启动。与非 Seamless 模式不同，Seamless **不**提供 `yunoCreatePayment`：支付创建始终由 SDK 管理。

在统一 API 中，同样的流程是一个**未**连接 `createPayment` 的普通 `Transaction`（存在 `createPayment` 会切换到手动模式；不存在则保持托管模式）。您的 Pay 按钮使用用户在列表中选择的支付方式调用 `transaction.start({ paymentMethod })`。

## 开始之前

* 加载统一 SDK 包而不是旧版包，并按照对照代码所示进行初始化：`window.Yuno.initialize(...)` 变为 `SdkPayments.initialize(...)`。您的公共 API 密钥以及您的 backend 创建的结账会话保持不变（[开始之前](https://docs.y.uno/zh-hans/docs/yuno-sdk/get-started.md#before-you-begin)）。
* 决定由谁创建支付。结账会话的 `workflow` 必须与该决定一致：

| 由谁创建支付 | 在 Seamless 中您的做法 | 在统一 API 中 | 会话 `workflow` |
| - | - | - | - |
| 您的 backend | 无对应项：Seamless 从不允许您创建支付 | 覆盖 `createPayment` | 默认（`SDK_CHECKOUT`） |
| SDK | 始终如此 | 不覆盖 | `SDK_SEAMLESS` |

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

## 对照

### Seamless Full

```typescript Before. Seamless Full theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const yuno = await window.Yuno.initialize('your-public-api-key')

await yuno.startSeamlessCheckout({
    checkoutSession: 'session-from-backend',
    elementSelector: '#root',
    countryCode: 'CO',
    language: 'en',
    yunoPaymentResult: (status) => console.log('done:', status),
})

await yuno.mountSeamlessCheckout()

// Merchant's pay button triggers. SDK does everything else
document.getElementById('pay').addEventListener('click', () => {
    yuno.startPayment()
})
```

```typescript After. Unified Transaction (managed) theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const sdkPayments = await SdkPayments.initialize('your-public-api-key')

const transaction = sdkPayments.transaction({
    checkoutSession: 'session-from-backend',
    countryCode: 'CO',
    language: 'en',
    elementSelector: '#payment-form', // form container for the selected method (form flows only)
    // managed mode: no createPayment wired
    onStatus: (result) => console.log('done:', result.status),
})

let selectedPaymentMethod: PaymentMethodSelected | null = null

const views = transaction.getPaymentMethodsViews({
    types: ['paymentMethodList'],
    onPaymentSelected: (paymentMethod) => {
        selectedPaymentMethod = paymentMethod
    },
})

views.paymentMethodList?.mount({ elementSelector: '#root' })

// Your Pay button. With forms unfolded in the list, start() submits the form the shopper filled.
// With folded forms, start() mounts the form into #payment-form and the shopper pays from it.
document.getElementById('pay').addEventListener('click', () => {
    if (selectedPaymentMethod) transaction.start({ paymentMethod: selectedPaymentMethod })
})
```

### Seamless External Buttons

```typescript Before. Seamless External Buttons theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const yuno = await window.Yuno.initialize('your-public-api-key')

await yuno.startSeamlessCheckout({
    checkoutSession: 'session-from-backend',
    countryCode: 'CO',
    yunoPaymentResult: (status) => console.log('done:', status),
})

yuno.mountSeamlessExternalButtons([
    { elementSelector: '#apple-pay', paymentMethodType: 'APPLE_PAY' },
    { elementSelector: '#google-pay', paymentMethodType: 'GOOGLE_PAY' },
    { elementSelector: '#paypal', paymentMethodType: 'PAYPAL' },
])
```

```typescript After. Unified Transaction (managed, wallet buttons) theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const sdkPayments = await SdkPayments.initialize('your-public-api-key')

const transaction = sdkPayments.transaction({
    checkoutSession: 'session-from-backend',
    countryCode: 'CO',
    onStatus: (result) => console.log('done:', result.status),
})

// Tapping a wallet button pays. No start() call needed
const views = transaction.getPaymentMethodsViews({
    types: ['applePay', 'googlePay', 'paypal'],
})

views.applePay?.mount({ elementSelector: '#apple-pay' })
views.googlePay?.mount({ elementSelector: '#google-pay' })
views.paypal?.mount({ elementSelector: '#paypal' })
```

## 变更内容

按您编辑代码的顺序分组。**重命名**：作用相同，名称变更。**移动**：值相同，归属对象变更。**移除**：无需调用任何内容。**新增**：没有旧版对应项。最后一列是除重命名之外您唯一需要做的事。

### 初始化和配置

| Seamless | 统一 API | 变更 | 操作 |
| - | - | - | - |
| `window.Yuno.initialize(publicApiKey)` | `SdkPayments.initialize(publicApiKey)` | 重命名 | 全局对象是 `window.SdkPayments`。与之前一样，对其使用 `await`：它会解析为您用来创建交易的 `SdkPayments` 实例。 |
| `startSeamlessCheckout` 配置中的 `checkoutSession`、`countryCode`、`language` | 交易配置中的相同字段 | 移动 | 值相同，单一工厂方法。 |
| `startSeamlessCheckout` 配置中的 `elementSelector` | 交易配置中的 `elementSelector` | 移动 | 当 `start({ paymentMethod })` 渲染表单时必需。表单在该元素内渲染，缺少该元素时 SDK 会抛出异常。Headless 流程会忽略它。列表和钱包视图在 `.mount()` 上保留各自的 `elementSelector`（请参阅“视图”）。 |

### Callback

| Seamless | 统一 API | 变更 | 操作 |
| - | - | - | - |
| `yunoPaymentResult(status, subStatus?)` | `onStatus(result)` | 重命名 | 仍然是唯一的结果 callback，现在是交易配置中的一个字段。它接收一个 `TransactionStatus` 对象（`status`、`substatus`、`message`）。请参阅 [`Status`](https://docs.y.uno/zh-hans/docs/yuno-sdk/reference/objects-you-receive#status)。 |
| *（无）* | `getPaymentMethodsViews` 内的 `onPaymentSelected(paymentMethod)` | 新增 | 可选。使用列表时，请保存它传递的支付方式，并通过您的 Pay 按钮将其传给 `transaction.start({ paymentMethod })`（请参阅“入口点”）。钱包按钮不需要它。点击即为确认，SDK 会自行发起支付并通过 `onStatus` 报告。 |
| *（无：支付创建始终由 SDK 管理）* | `createPayment` | 新增 | 不要连接它。它的存在会切换到手动模式（非 Seamless 行为）；它的缺失会使 SDK 保持托管模式，即与 Seamless 相同的模型。 |

### 视图

| Seamless | 统一 API | 变更 | 操作 |
| - | - | - | - |
| `yuno.mountSeamlessCheckout()` | `getPaymentMethodsViews({ types: ['paymentMethodList'], onPaymentSelected })`，然后 `views.paymentMethodList?.mount({ elementSelector })` | 重命名 | 获取视图句柄，然后使用选择器调用 `.mount(...)`。请参阅[支付方式列表](https://docs.y.uno/zh-hans/docs/yuno-sdk/features/payment-methods-list.md)。 |
| `yuno.mountSeamlessExternalButtons([{ elementSelector, paymentMethodType }])` | `getPaymentMethodsViews({ types: ['applePay', 'googlePay', 'paypal', 'paypalBraintree', 'revolutPay', 'samsungPay'] })`，然后 `views.applePay?.mount({ elementSelector, ...config })` 等 | 重命名 | 每个钱包按钮调用一次 `.mount()`。将每个 v1 `paymentMethodType` 映射到其视图键：`APPLE_PAY` 对应 `applePay`，`GOOGLE_PAY` 对应 `googlePay`，`PAYPAL` 对应 `paypal`，`PAYPAL_BRAINTREE` 对应 `paypalBraintree`，`REVOLUT_PAY` 对应 `revolutPay`，`SAMSUNG_PAY` 对应 `samsungPay`。每个视图的样式（按钮颜色、类型等）在各自的 `.mount()` 调用中设置。 |
| `yuno.unmountSeamlessExternalButton(type)` / `yuno.unmountSeamlessExternalButtons()` | *（已移除）* | 移除 | 已移除按按钮卸载。`transaction.unmount()` 会移除该交易挂载的表单，并在尚未传递结果时通过 `onStatus` 报告 `USER_CANCEL`。钱包按钮会保留在页面上，直到您移除它们的容器。 |

### 入口点

| Seamless | 统一 API | 变更 | 操作 |
| - | - | - | - |
| `yuno.startSeamlessCheckout(config)` | `sdkPayments.transaction(config)` | 重命名 | `Seamless` 工厂方法已不复存在：请使用常规工厂方法，不带 `createPayment`（请参阅“Callback”）。 |
| `yuno.startPayment()`（商户触发） | 使用列表时为 `transaction.start({ paymentMethod })`，使用 `start()` 挂载的表单时为 `transaction.submit()` | 重命名 | 使用列表时，您的 Pay 按钮使用用户选择的支付方式调用 `start({ paymentMethod })`。它会提交列表以内联方式打开的表单。使用预先选择的支付方式时，`start({ paymentMethod })` 会将表单挂载到配置的 `elementSelector` 中，您的 Pay 按钮调用 `submit()`（设置 `showPayButton: false`）。钱包按钮在点击时完成支付，两者都不需要。 |

## 相关内容

* [支付方式列表](https://docs.y.uno/zh-hans/docs/yuno-sdk/features/payment-methods-list.md)。`getPaymentMethodsViews` 参考。
* [`TransactionConfig`](https://docs.y.uno/zh-hans/docs/yuno-sdk/reference/objects-you-pass#transaction-config)。完整的字段参考。
* [Lite 模式](https://docs.y.uno/zh-hans/docs/yuno-sdk/migration/web/lite.md)。适用于使用 `yunoCreatePayment`（手动模式）的非 Seamless 集成。


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