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

# onCardInfoChanged

> 在购物者输入卡号时，携带卡组织、类型、类别、发卡机构和国家/地区调用。

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

它仅用于提供信息：无论是否使用它，支付的工作方式都相同。SDK 已经会从第六位数字开始查询卡片详细信息，以显示卡组织并加载分期付款，而此控制器会将同一次查询的结果交给您。它不会发起额外的网络调用，也绝不会包含完整卡号、安全码、有效期或持卡人姓名。

自 SDK `3.1.0` 起可在 iOS 和 Android 上使用。SDK 会从其为新卡显示的每个卡片表单中调用它，包括支付和注册。对于已保存的卡片不会调用它，因为购物者不会输入卡号。

## 您收到的内容

一个 `CardInfo` 对象，或 `null`（在 iOS 上为 `nil`）。

| 字段 | 键 | 类型 | 说明 |
| - | - | - | - |
| `iin` | `iin` | String（在 Android 上为 String?） | 卡号的前几位数字，介于 6 到 8 位之间。绝不是完整卡号。 |
| `brand` | `brand` | String? | 卡组织，例如 `VISA` 或 `MASTERCARD`。 |
| `scheme` | `scheme` | String? | 卡片网络。 |
| `type` | `type` | String? | 卡片类型，通常为 `CREDIT` 或 `DEBIT`。 |
| `category` | `category` | String? | 卡片类别或等级，例如 `GOLD` 或 `PREPAID`。预付卡在此处标记，而不是在 `type` 中。 |
| `issuerName` | `issuer_name` | String? | 发卡银行名称。 |
| `issuerCode` | `issuer_code` | String? | 发卡银行代码。 |
| `countryCode` | `country_code` | String? | 发卡银行的 ISO 国家/地区代码，例如 `BR`。 |
| `countryName` | `country_name` | String? | 发卡银行的国家/地区名称。 |

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

## 调用时机

* 在卡片查询返回结果之后，且购物者已输入至少 6 位数字时。
* 仅在结果发生变化时再次调用。继续输入同一张卡的更多数字不会再次调用它，除非查询返回了不同的详细信息。在 iOS 上，当查询匹配到同一张卡更长的前缀时，也可能收到新的调用，此时只有 `iin` 发生变化。
* 在主线程上调用，因此您可以直接更新 UI。

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

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

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

## `null` 传递

当您已收到的卡片信息不再适用时，控制器会收到 `null`（在 iOS 上为 `nil`）：卡号少于 6 位、字段被清空，或查询失败。请清除或隐藏您为上一张卡显示的所有内容。第一次调用绝不会是 `null`。

当卡片表单关闭、购物者支付或购物者选择其他支付方式时，不会发送任何内容。如果您的 UI 需要在这些情况下重置，请在您这一侧处理。

## 签名

在 iOS 上，请在您的 `TransactionController` 上实现该方法。在 Android 上，请在支付或注册的 `TransactionConfig` 上链式调用 `onCardInfoChanged`：它会返回一个新的配置，因此请使用返回的值。

> [tab] iOS
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> func onCardInfoChanged(_ cardInfo: CardInfo?) {
>     if let cardInfo {
>         orderSummary.showCardDetails(
>             brand: cardInfo.brand,
>             type: cardInfo.type,
>             issuer: cardInfo.issuerName,
>             country: cardInfo.countryCode
>         )
>     } else {
>         orderSummary.clearCardDetails()
>     }
> }
> ```

> [tab] Android
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> val config = TransactionConfig(
>     countryCode = countryCode,
>     checkoutSession = checkoutSession,
>     controller = controller,
> ).onCardInfoChanged { cardInfo ->
>     if (cardInfo != null) {
>         orderSummary.showCardDetails(cardInfo.brand, cardInfo.type, cardInfo.issuerName, cardInfo.countryCode)
>     } else {
>         orderSummary.clearCardDetails()
>     }
> }
> ```

在 Android 上，每笔交易都使用其自身配置的 callback。未使用 `onCardInfoChanged` 构建的配置，或使用 `onCardInfoChanged(null)` 构建的配置，不会收到任何内容。

## 最佳实践

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

## 相关内容

* [监听事件](https://docs.y.uno/docs/yuno-sdk/controllers/listen-to-events)。其他提供信息的控制器。
* [`onInstallmentSelected`](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/on-installment-selected)。购物者在同一卡片表单中选择的分期付款选项。
* [控制器概览](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/overview.md)。各平台如何接入控制器。


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