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

# 分期付款

> 在 Web、iOS 和 Android 上，当购物者在卡片表单中选择分期付款选项时获得通知

> [!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.

注册可选的 `onInstallmentSelected` callback，使您的购物车总额与购物者在卡片表单中选择的分期付款方案保持同步。当默认分期付款选项被预先选择时，以及购物者每次更改选择时，SDK 都会通知您。当方案被重新计算时（例如 BIN 变更后），SDK 也会通知您。

该 callback 在所有平台上均为可选：如果您不注册它，SDK 的行为保持不变。您的 callback 内部抛出的异常会被 SDK 捕获，绝不会中断支付流程。

| 平台 | 起始版本 | 注册位置 |
| - | - | - |
| Web | SDK `1.6.7` | `startCheckout` 中的 `card.onInstallmentSelected` |
| iOS | SDK `2.21.0` | `YunoPaymentDelegate` 上的 `onInstallmentSelected(_:)` |
| Android | SDK `2.20.0` | `startCheckout` 的 `onInstallmentSelected` 参数 |

## 实现

> [tab] Web
>
> ### 使用 `onGetInstallments` 提供您自己的分期付款选项
>
> 自 Web SDK **1.6.7** 起可用。在 `card` 选项中传入 `onGetInstallments`；SDK 在获知卡片的 BIN 后调用它，并在分期付款选择器中渲染您返回的内容。该 callback 的超时时间为 10 秒；如果超时、抛出错误，或返回空数组、`undefined` 或不返回任何内容，SDK 会回退到在 Yuno 中配置的分期付款方案。
>
> ```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> await yuno.startCheckout({
>   checkoutSession: session.checkout_session,
>   elementSelector: '#payment-form',
>   countryCode: 'BR',
>   card: {
>     onGetInstallments: async ({ bin, brand, cardType, amount, currency }) => {
>       const plans = await fetch(`/api/installments?bin=${bin}&amount=${amount}`).then((r) => r.json())
>       return plans.map((plan) => ({
>         installment: plan.count,
>         label: plan.label,
>         amount: { currency, value: plan.value, total_value: plan.total },
>       }))
>     },
>   },
>   // ...
> })
> ```
>
> 该 callback 接收单个对象参数，并且可以是异步的：
>
> ```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> type OnGetInstallments = (args: {
>   bin: string
>   brand: string
>   cardType: string
>   issuerCode?: string
>   issuerName?: string
>   amount?: string
>   currency?: string
> }) => MerchantInstallmentOption[] | void | Promise<MerchantInstallmentOption[] | void>
>
> type MerchantInstallmentOption = {
>   installment: number
>   label: string
>   amount?: {
>     currency: string
>     value: string
>     total_value: string
>   }
>   additionalData?: Record<string, unknown>
> }
> ```
>
> | 参数 | 类型 | 描述 |
> | - | - | - |
> | `bin` | `string` | 卡片的 BIN（前几位数字），由 Yuno 解析。在获知 BIN 之前不会调用该 callback。 |
> | `brand` | `string` | 卡品牌，例如 `VISA`、`MASTERCARD`。 |
> | `cardType` | `string` | `CREDIT` 或 `DEBIT`。 |
> | `issuerCode`, `issuerName` | `string` | 发卡银行（当 Yuno 能够解析时）。 |
> | `amount`, `currency` | `string` | 以字符串表示的结账会话金额及其币种。 |
>
> | 返回字段 | 类型 | 描述 |
> | - | - | - |
> | `installment` | `number` | 分期期数，例如 `3`。用作选项的键，因此请保持其唯一。 |
> | `label` | `string` | 在选择器中渲染的确切文本，使用购物者的语言。 |
> | `amount` | `object` | 可选的 `currency`、`value`（每期金额）和 `total_value`，均为字符串。会传递给 `onInstallmentSelected`。 |
> | `additionalData` | `object` | 可选。类型中接受该字段，但目前不会传递给 `onInstallmentSelected`（保留供将来使用）。 |
>
> 每当 BIN 或金额发生变化时，SDK 都会再次调用 `onGetInstallments`，并且如果已经开始了更新的调用，会忽略过时的响应。您返回的选项会以 `isMerchantInstallment: true` 报告给 `onInstallmentSelected`。
>
> ### 使用 `onInstallmentSelected` 响应购物者的选择
>
> 在 `startCheckout` 的 `card` 选项中传入该 callback：
>
> ```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> await yuno.startCheckout({
>   checkoutSession: session.checkout_session,
>   elementSelector: '#payment-form',
>   countryCode: 'BR',
>   card: {
>     onInstallmentSelected: (selection) => {
>       if (!selection) {
>         // The previous selection no longer applies: restore your base total
>         return
>       }
>       const { installment, label, amount, isMerchantInstallment } = selection
>       // Update your cart total, e.g. with amount?.total_value
>       console.log('Installment selected:', { installment, label, amount, isMerchantInstallment })
>     },
>   },
>   // ...
> })
> ```
>
> 该 callback 接收单个对象参数；当之前的选择不再有效时，接收 `null`：
>
> ```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> type OnInstallmentSelected = (args: {
>   installment: number
>   label: string
>   amount?: {
>     currency: string
>     value: string
>     total_value: string
>   }
>   installmentId?: string   // 1.11.28+
>   type?: string            // 1.11.28+
>   rate?: number            // 1.11.28+
>   financialCosts?: Array<{ type, rate, formattedValue }>  // 1.11.28+
>   additionalData?: Record<string, unknown>
>   isMerchantInstallment: boolean
> } | null) => void
> ```
>
> | 字段 | 类型 | 描述 |
> | - | - | - |
> | `installment` | `number` | 所选的分期期数（例如 `3`）。 |
> | `label` | `string` | 表单中渲染的确切分期付款标签，已本地化（例如 `3x de R$875.00 - Total R$2,625.00`）。 |
> | `amount` | `object` | 可选。`currency`、`value` 和 `total_value`，为原始字符串，与分期付款方案报告的内容完全一致。 |
> | `installmentId` | `string` | 可选，自 SDK `1.11.28` 起提供。该选项所属分期付款方案的 ID。同一方案的选项共享该 ID，因此请将其与 `installment` 结合使用以识别选项。随一次性令牌一起发送。 |
> | `type` | `string` | 可选，自 SDK `1.11.28` 起提供。分期付款方案类型。 |
> | `rate` | `number` | 可选，自 SDK `1.11.28` 起提供。该选项的年利率（APR），取自 `financialCosts` 中的 `APR` 条目。没有时为 `undefined`。 |
> | `financialCosts` | `array` | 可选，自 SDK `1.11.28` 起提供。该分期付款选项的财务成本明细，包含 `type`、`rate` 和 `formattedValue`。 |
> | `additionalData` | `object` | 保留供将来使用。目前始终为 `undefined`。 |
> | `isMerchantInstallment` | `boolean` | 当所选选项由您自己的 `onGetInstallments` callback 提供时（商户分期付款）为 `true`；对于 Yuno 提供的方案为 `false`。 |
>
> 当所选选项来自您的 `onGetInstallments` callback（`isMerchantInstallment: true`）时，`installmentId`、`type`、`rate` 和 `financialCosts` 为 `undefined`，并且一次性令牌会以 `installment: null` 创建。
>
> 触发规则：
>
> * 一旦方案渲染完成且默认分期付款选项被预先选择，就会以当前选择触发，因此您的总额从首次渲染起即正确。
> * 购物者每次做出选择时都会触发。
> * 当可用选项发生变化时（例如 BIN 变更导致方案重新计算），会以当前选择再次触发。
> * 当之前通知过的选项不再可用时以 `null` 触发，例如购物者切换到不支持分期付款的卡片时（自 SDK `1.10.3` 起）。仅当之前通知过选择时才会触发，因此从未有过分期付款的表单不会触发。
> * 适用于所有卡片流程，包括 Secure Fields 和 Click to Pay。

> [tab] iOS
>
> 实现 `YunoPaymentDelegate` 的可选方法 `onInstallmentSelected(_:)`：
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> class ViewController: UIViewController, YunoPaymentDelegate {
>
>     // ... required YunoPaymentDelegate implementation ...
>
>     func onInstallmentSelected(_ installmentSelected: YunoInstallmentSelected?) {
>         guard let installmentSelected else {
>             // Installments are no longer available — restore your base total
>             return
>         }
>         // Update your cart total, e.g. with installmentSelected.amount?.totalValue
>     }
> }
> ```
>
> 该方法接收 `YunoInstallmentSelected?` payload：
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> @objc public final class YunoInstallmentSelected: NSObject {
>     @objc public let installment: Int
>     @objc public let label: String
>     @objc public let amount: YunoInstallmentAmount?
>     @objc public let additionalData: [String: Any]?
> }
>
> @objc public final class YunoInstallmentAmount: NSObject {
>     @objc public let currency: String
>     @objc public let value: String
>     @objc public let totalValue: String
> }
> ```
>
> | 字段 | 类型 | 描述 |
> | - | - | - |
> | `installment` | `Int` | 所选的分期期数（例如 `3`）。 |
> | `label` | `String` | 表单中渲染的确切分期付款标签，已本地化（例如 `3x of R$ 500,31 - Total R$ 1.500,93`）。 |
> | `amount` | `YunoInstallmentAmount?` | `currency`、`value` 和 `totalValue`，为原始字符串，与分期付款方案报告的内容完全一致。 |
> | `additionalData` | `[String: Any]?` | 所选选项的 `additional_data` 对象（当分期付款服务提供时）。 |
>
> 触发规则：
>
> * 方案加载时默认分期付款选项被预先选择后触发一次，因此您的总额从首次渲染起即正确。
> * 购物者每次做出选择时都会触发；方案变化后（例如 BIN 变更），也会以重新计算后的默认选项触发。
> * 当之前报告的选择不再适用时（例如购物者切换到不支持分期付款的卡片），以 `nil` 触发一次。请恢复您的基础总额。在报告第一次选择之前，绝不会以 `nil` 调用。
> * 在主线程上传递。该方法为可选；省略它时 SDK 的行为保持不变。

> [tab] Android
>
> 调用 `startCheckout` 时传入该 callback：
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> startCheckout(
>   checkoutSession = "checkout_session",
>   countryCode = "country_code_iso",
>   callbackPaymentState = { state, subState, message -> /* ... */ },
>   onInstallmentSelected = { selection ->
>     if (selection != null) {
>       // Update your cart total, e.g. with selection.amount?.totalValue
>     } else {
>       // Installments are no longer available — restore your base total
>     }
>   },
> )
> ```
>
> 该 callback 接收 `InstallmentSelected?` payload：
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> data class InstallmentSelected(
>     val installment: Int,
>     val label: String,
>     val amount: InstallmentAmount? = null,
>     val additionalData: Map<String, Any?>? = null,
> )
>
> data class InstallmentAmount(
>     val currency: String,
>     val value: String,
>     val totalValue: String,
> )
> ```
>
> | 字段 | 类型 | 描述 |
> | - | - | - |
> | `installment` | `Int` | 所选的分期期数（例如 `3`）。 |
> | `label` | `String` | 表单中渲染的确切分期付款标签，已本地化（例如 `3x de R$875.00 - Total R$2,625.00`）。 |
> | `amount` | `InstallmentAmount?` | `currency`、`value` 和 `totalValue`，为原始字符串，与分期付款方案报告的内容完全一致。 |
> | `additionalData` | `Map<String, Any?>?` | 保留供将来使用。目前始终为 `null`。 |
>
> 触发规则：
>
> * 方案渲染时默认分期付款选项被预先选择后触发一次，因此您的总额从首次渲染起即正确。
> * 购物者每次做出选择时都会触发；方案变化后（例如 BIN 变更），也会以重新计算后的默认选项触发。
> * 当已报告过选择之后分期付款不再可用时（例如购物者切换到不支持分期付款的卡片），以 `null` 触发一次。请恢复您的基础总额。
> * 当卡片表单渲染时没有分期付款，则不会触发。该 callback 在主线程上运行，不注册任何 callback 时 SDK 的行为保持不变。


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