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

# 输入时获取卡片信息

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

注册可选的 `onCardInfoChanged` callback，即可在购物者于卡片表单中输入卡号时，接收卡片的品牌、类型、类别、发卡机构和国家。您会在购物者提交表单之前获得这些详细信息，因此可以实时调整您的 checkout：在订单摘要中显示卡品牌或发卡银行，说明仅适用于信用卡的促销活动，或根据发卡银行所在国家调整提示信息。

该 callback 仅用于提供信息，并且是可选的：如果您不注册它，SDK 的行为保持不变。SDK 本身就会从第六位数字开始查询卡片详细信息，以显示卡品牌并加载分期付款，而该 callback 会将同一次查询的结果交给您。它不会发起额外的网络调用，也绝不会包含完整卡号、安全码、有效期或持卡人姓名。

| 平台 | 起始版本 | 注册位置 |
| - | - | - |
| iOS | SDK `2.30.0` | `YunoPaymentDelegate` 或 `YunoEnrollmentDelegate` 上的 `onCardInfoChanged(_:)`。对于 Seamless，使用 `SeamlessParams.onCardInfoChanged` |
| Android | SDK `2.29.0` | `setOnCardInfoChanged { }`，在您启动 checkout 或注册之前调用 |

在 SDK 为新卡显示的每个卡片表单中，无论是支付还是注册，该 callback 都会触发。对于已保存（已注册）的卡片，它不会被调用，因为购物者无需输入卡号；在 Headless 集成中也不会被调用，因为 SDK 在其中不显示卡片表单。

## 您会收到什么

一个卡片信息对象，或 `null`（iOS 上为 `nil`），具体见[何时调用](#when-it-is-called)。

| 属性 | 键 | 描述 |
| - | - | - |
| `iin` | `iin` | 卡号的前几位数字，介于 6 到 8 位之间。绝不是完整卡号。 |
| `brand` | `brand` | 卡品牌，例如 `VISA` 或 `MASTERCARD`。 |
| `scheme` | `scheme` | 卡组织。 |
| `type` | `type` | 卡片类型，通常为 `CREDIT` 或 `DEBIT`。 |
| `category` | `category` | 卡片类别或等级，例如 `GOLD` 或 `PREPAID`。预付卡在此处标识，而不在 `type` 中。 |
| `issuerName` | `issuer_name` | 发卡银行名称。 |
| `issuerCode` | `issuer_code` | 发卡银行代码。 |
| `countryCode` | `country_code` | 发卡银行的 ISO 国家代码，例如 `BR`。 |
| `countryName` | `country_name` | 发卡银行的国家名称。 |

* 各值按卡片查询返回的原样传递。SDK 不会对其进行翻译或规范化。
* 查询未返回的值为 `null`（iOS 上为 `nil`）。某些字段（例如 `issuerCode`）经常为空，因此不要在您的逻辑中将其设为必需。
* 在 iOS 上，`iin` 始终存在。在两个平台上，其他所有字段均为可选。
* `iin` 的长度在 6 到 8 位之间变化。请勿依赖其长度。
* 每个值也可以按键获取：iOS 上的 `rawData` 和 Android 上的 `toMap()` 始终返回上述九个键，两个平台上的名称相同。在 iOS 上，`rawData` 中缺失的值为 `NSNull`。

## 何时调用

* 在购物者至少输入 6 位数字后，卡片查询返回结果时。
* 之后仅在结果发生变化时再次调用。继续输入同一张卡的更多数字不会再次调用，除非查询返回不同的详细信息。在 iOS 上，当查询匹配到同一张卡的更长前缀时，也可能收到新的调用，此时仅 `iin` 发生变化。
* 当您已收到的卡片不再适用时，以 `null`（iOS 上为 `nil`）调用：卡号少于 6 位、字段被清空或查询失败。第一次调用绝不会是 `null`。
* 在主线程上调用，因此您可以直接更新 UI。

如果查询进行中购物者继续输入或编辑卡号，过时的结果会被丢弃，因此您绝不会收到购物者已经更改的卡号的详细信息。

当卡片表单关闭、购物者完成支付或购物者选择其他支付方式时，不会发送任何内容：您收到的最后一个值保持有效。如果您的 UI 需要在这些情况下重置该值，请在您这一侧处理。

每个卡片表单都会重新开始。如果购物者关闭表单后再次打开，即使是与之前相同的卡片，新表单中的第一个结果也会被传递。

| 购物者的操作 | 您收到的内容 |
| - | - |
| 输入前 5 位数字 | 无。 |
| 输入第 6 位数字 | 查询返回结果后，立即收到卡片详细信息。 |
| 继续输入同一张卡 | 无，除非查询返回不同的详细信息。 |
| 删除数字直到剩余少于 6 位 | `null`（iOS 上为 `nil`）。 |
| 输入另一张卡的卡号 | 新卡片的详细信息。 |
| 查询失败，例如没有网络连接 | `null`（iOS 上为 `nil`），前提是您之前已收到过卡片信息。 |
| 完成支付、关闭表单或选择其他方式 | 不再收到任何内容。最后一个值保持有效。 |

## 实现

> [tab] iOS
>
> 在您传给 SDK 的 delegate 上实现可选方法 `onCardInfoChanged(_:)`：支付（Full、Lite 和 Render）使用 `YunoPaymentDelegate`，注册使用 `YunoEnrollmentDelegate`。两者中的方法相同。
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> class CheckoutViewController: UIViewController, YunoPaymentDelegate {
>
>     // ... required YunoPaymentDelegate implementation ...
>
>     func onCardInfoChanged(_ cardInfo: YunoCardInfo?) {
>         guard let cardInfo else {
>             // The card you received no longer applies
>             orderSummary.clearCardDetails()
>             return
>         }
>         orderSummary.showCardDetails(
>             brand: cardInfo.brand,
>             type: cardInfo.type,
>             issuer: cardInfo.issuerName,
>             country: cardInfo.countryCode
>         )
>     }
> }
> ```
>
> 该方法接收 `YunoCardInfo?` payload，在 Objective-C 中同样可用：
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> @objc public final class YunoCardInfo: NSObject {
>     @objc public let iin: String
>     @objc public let brand: String?
>     @objc public let scheme: String?
>     @objc public let type: String?
>     @objc public let category: String?
>     @objc public let issuerName: String?
>     @objc public let issuerCode: String?
>     @objc public let countryCode: String?
>     @objc public let countryName: String?
>     @objc public let rawData: [String: Any]
> }
> ```
>
> 要按键读取值，请使用 `rawData`：
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> func onCardInfoChanged(_ cardInfo: YunoCardInfo?) {
>     guard let values = cardInfo?.rawData else { return }
>     let category = values["category"] as? String
>     if category == "PREPAID" {
>         orderSummary.showPrepaidNotice()
>     }
> }
> ```
>
> 对于 Seamless，请改为设置 `SeamlessParams.onCardInfoChanged`，因为 Seamless 不接受 delegate。请在调用 `startPaymentSeamlessLite` 之前设置该闭包：它只会在支付开始时读取一次。
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> let params = SeamlessParams(
>     checkoutSession: checkoutSession,
>     countryCode: "CO",
>     language: "en",
>     viewController: self
> )
> params.onCardInfoChanged = { [weak self] cardInfo in
>     self?.orderSummary.update(with: cardInfo)
> }
> let result = await Yuno.startPaymentSeamlessLite(with: params, paymentSelected: paymentSelected)
> ```
>
> 在 Objective-C 中：
>
> ```objectivec theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> - (void)onCardInfoChanged:(YunoCardInfo * _Nullable)cardInfo {
>     if (cardInfo == nil) {
>         [self.orderSummary clearCardDetails];
>         return;
>     }
>     [self.orderSummary showBrand:cardInfo.brand type:cardInfo.type];
> }
> ```

> [tab] Android
>
> 在您启动 checkout、支付或注册之前，调用一次 `setOnCardInfoChanged`。一次注册即可覆盖所有卡片表单（`startPayment`、`startPaymentLite`、`startPaymentSeamlessLite`、`startPaymentRender`、`startEnrollment` 和 `startEnrollmentRender`），直到您替换它为止。
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> import com.yuno.sdk.payments.CardInfo
> import com.yuno.sdk.payments.setOnCardInfoChanged
>
> class CheckoutActivity : AppCompatActivity() {
>
>     override fun onCreate(savedInstanceState: Bundle?) {
>         super.onCreate(savedInstanceState)
>         setOnCardInfoChanged { cardInfo -> renderCardDetails(cardInfo) }
>         startCheckout(
>             checkoutSession = "checkout_session",
>             countryCode = "country_code_iso",
>             callbackPaymentState = { state, subState, message -> /* ... */ },
>         )
>     }
>
>     override fun onDestroy() {
>         setOnCardInfoChanged(null)
>         super.onDestroy()
>     }
>
>     private fun renderCardDetails(cardInfo: CardInfo?) {
>         if (cardInfo == null) {
>             orderSummary.clearCardDetails()
>             return
>         }
>         orderSummary.showCardDetails(cardInfo.brand, cardInfo.type, cardInfo.issuerName, cardInfo.countryCode)
>     }
> }
> ```
>
> 当您不再需要该 callback 时，调用 `setOnCardInfoChanged(null)`，例如在 `onDestroy` 中。SDK 会一直保留该 callback，直到您替换它或传入 `null`，否则捕获了 `Activity` 的 lambda 会使其一直保留在内存中。
>
> 如果您在卡片表单打开后才注册该 callback，您将收到下一次变化，而不是屏幕上已有的卡片信息。
>
> 要按键读取值，请使用 `toMap()`：
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> setOnCardInfoChanged { cardInfo ->
>     val values: Map<String, String?> = cardInfo?.toMap() ?: return@setOnCardInfoChanged
>     if (values["category"] == "PREPAID") {
>         orderSummary.showPrepaidNotice()
>     }
> }
> ```
>
> 在 Java 中：
>
> ```java theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> import com.yuno.sdk.payments.PaymentsFlowKt;
> import kotlin.Unit;
>
> PaymentsFlowKt.setOnCardInfoChanged(cardInfo -> {
>     if (cardInfo == null) {
>         orderSummary.clearCardDetails();
>     } else {
>         orderSummary.showCardDetails(cardInfo.getBrand(), cardInfo.getType());
>     }
>     return Unit.INSTANCE;
> });
> ```
>
> 您的 callback 内部抛出的异常会被 SDK 捕获并记录，因此不会破坏卡片表单。不过仍请自行处理错误，因为 SDK 不会重试该调用。

## 最佳实践

* 保持处理程序轻量。它在购物者输入时于主线程上运行，因此请将任何耗时的工作（例如调用您的 backend）移出主线程。
* 处理 `null`（iOS 上为 `nil`）：清除或隐藏您为上一张卡显示的任何内容。
* 将每次调用视为表单的当前状态，而不是最终值。购物者在支付前仍可更改卡号。
* 不要根据这些值阻止或延迟支付。SDK 会自行验证卡片。

## 测试

1. 在 sandbox 中，从已注册该 callback 的应用打开一个卡片表单。
2. 输入一个测试卡卡号。输入第六位数字后，您会收到卡片详细信息。
3. 删除数字直到剩余少于 6 位。您会收到 `null`（iOS 上为 `nil`）。
4. 输入另一个品牌的卡号。您会收到新的详细信息。
5. 使用已保存的卡片支付。该 callback 不会被调用。

这些值来自您所用环境的卡片查询，因此 sandbox 中的测试卡可能返回通用的发卡机构数据。

## 相关内容

* [分期付款](https://docs.y.uno/zh-hans/docs/sdks/additional-features/installments.md)。针对购物者所选分期付款选项的类似 callback。
* [Yuno SDK 中的 `onCardInfoChanged`](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/on-card-info-changed)。Yuno SDK（iOS 和 Android v3.x）中的相同信息。


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