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

# 注册

> 保存客户的支付方式以供将来使用，不进行扣款。

注册功能让您可以将客户的支付方式令牌化并保存，而无需处理扣款。使用它来登记客户可在将来支付中使用的银行卡或其他方式。

同一个 `Transaction` 类负责处理注册。只有会话类型不同。在 Web 上，注册交易提供 `start()`、`secureFields()` 和 `unmount()`。仅用于支付的方法（`getPaymentMethodsViews`、`submit`、`updateCheckoutSession`）以及仅用于支付的配置字段不可用。

> [!NOTE]
>
> 会话类型决定模式：传入 `checkoutSession` 会运行**支付**，而传入 `customerSession` 会运行**注册**。必须且只能提供两者之一。在 iOS 上，选择在编译时完成：`TransactionConfig` 针对每种会话类型各有一个初始化方法，因此无法写出同时包含两者或两者都不包含的配置。在 Android 和 Web 上，同时提供两者或两者都不提供，会在构造时因验证错误而失败。在 Android 上，错误信息为 `Exactly one of checkoutSession or customerSession must be provided`。在 Web 上，错误信息为 `Provide either checkoutSession or customerSession, not both.` 或 `A checkoutSession or customerSession is required.` 在 React Native 上，`new Transaction(config)` 会抛出 `Exactly one of checkoutSession or customerSession must be provided`。完整的决策指南请参阅[我从哪里开始？](https://docs.y.uno/zh-hans/docs/yuno-sdk/where-do-i-start.md)。

## 开始之前

您的 backend 必须创建注册所需的资源：

* 创建客户。请参阅 [`POST /v1/customers`](https://docs.y.uno/reference/customers/the-customer-object)。
* 创建客户会话。请参阅 [`POST /v1/customers/sessions`](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session)。
* 创建支付方式。请参阅 [`POST /v1/customers/sessions/{customer_session}/payment-methods`](https://docs.y.uno/reference/payment-methods-checkout/enroll-payment-method-checkout)。此调用需要 `X-Idempotency-Key` 标头；缺少该标头时，API 会返回 `400 INVALID_PARAMETERS`。

## 实施

在 `TransactionConfig` 中传入 `customerSession`（而不是 `checkoutSession`），然后调用 `start()`。在 Android 上，在 `paymentSelected` 中传入客户选择的方式，与支付时的做法相同。在 iOS 上，`start(paymentSelected:)` 接受同一个对象，但要注册的方式是您的 backend 在客户会话上创建的那个：SDK 从会话中读取它，而不会使用 `paymentMethodType` 来选择它。在 Web 上，`start()` 会为您的 backend 在客户会话上注册的方式渲染 SDK 表单，只有在 headless 注册时才需要 `paymentMethod`（请参阅“跳过表单”）。在 React Native 上，`start(paymentSelected)` 的行为与所在平台的原生 SDK 相同。注册完成后，SDK 会将最终状态传递给 `onStatus`。

渲染和选择要注册的支付方式由您负责。SDK 不会显示可注册方式的列表。要获取可用的方式，请调用 [`GET /v1/customers/sessions/{customer_session}/payment-methods`](https://docs.y.uno/reference/payment-methods-checkout/retrieve-payment-methods-to-enroll-checkout)。在 iOS 和 Web 上，选择通过客户会话传递给 SDK，使用的是“开始之前”中的 `POST` 调用。

> [tab] Web
>
> ```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> const transaction = sdkPayments.transaction({
>     customerSession: 'session-from-backend',
>     countryCode: 'US',
>     language: 'en', // optional, falls back to browser language
>     elementSelector: '#enrollment-form',
>     onStatus: (result) => {
>         console.log('Enrollment status:', result.status)
>     },
> })
>
> await transaction.start()
> // For headless enrollment, call start({ paymentMethod: { type: 'CARD', data } })
> // instead. The config's elementSelector is ignored. See "Skip the form" below.
> ```
>
> 在 Web 上，`elementSelector` 是可选的。如果不提供，SDK 会将自己的容器追加到 `<body>` 的末尾，并在其中渲染表单。

> [tab] iOS
>
> ```swift theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> let config = SdkPayments.TransactionConfig(
>     customerSession: "session-from-backend",
>     countryCode: "US",
>     language: "en",          // optional, falls back to device language
>     appearance: nil,         // optional
>     controller: self
> )
>
> let paymentSelected = SdkPayments.PaymentMethodSelected(
>     paymentMethodType: "CARD"  // The customer session decides the method to enroll.
>     // transactionData: ...   // optional. See "Skip the form" below.
> )
>
> SdkPayments.Transaction(config: config)
>     .start(paymentSelected: paymentSelected)
> ```

> [tab] Android
>
> ```kotlin theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> val config = TransactionConfig(
>     customerSession = "session-from-backend",
>     countryCode = "US",
>     language = "en",          // optional, falls back to device language
>     appearance = null,        // optional
>     controller = this
> )
>
> val paymentSelected = PaymentMethodSelected(
>     type = "CARD",
>     // transactionData = ... // optional. See "Skip the form" below.
> )
>
> Transaction(config)
>     .start(activity = this, paymentSelected = paymentSelected)
> ```

> [tab] React Native
>
> ```tsx theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> const enrollment = new Transaction({
>   customerSession: 'session-from-backend',
>   countryCode: 'US',
>   language: 'en', // optional, falls back to device language
>   controller: {
>     onStatus: (status) => console.log('Enrollment status:', status.status),
>   },
> });
>
> await enrollment.start({
>   type: 'CARD',
>   // transactionData: ... // optional. See "Skip the form" below.
> });
> ```

### 跳过表单

如果您在自己的 UI 中收集客户的数据，请通过 `PaymentMethodSelected` 上的 `transactionData`（Web 上为 `data`）传入这些数据。SDK 将跳过其内置表单并直接进行令牌化：这是一种 headless 流程，会忽略交易配置中的 `elementSelector`（它仅适用于基于表单的流程）。完整的数据结构请参阅 [`TransactionData`](https://docs.y.uno/zh-hans/docs/yuno-sdk/reference/objects-you-pass#transaction-data)。

> [!NOTE]
>
> 注册期间会忽略 `PaymentMethodSelected` 上的 `vaultedToken`。该流程的目的是生成新的存储令牌，因此尚无已关联的令牌可供引用。

## 注意事项

* 注册期间可能会发生 3DS 挑战。
* `createPayment` 不适用，因为没有需要创建的支付。在 Web 上，注册配置不接受该属性（TypeScript 会拒绝该属性）。在 iOS、Android 和 React Native 上，它不会被调用。
* 注册成功时，`onStatus` 会传递最终状态，其 payload 结构与支付流程相同（`status`、`substatus`、`message`）。存储令牌不会提供给客户端：请在成功状态到达后，从您 backend 的列出客户支付方式 endpoint 获取该令牌，并将其与您的客户关联存储，以便在将来的支付中使用。

## 相关内容

* [会话](https://docs.y.uno/zh-hans/docs/basic-concepts/sessions.md)。结账会话与客户会话的对比。
* [`TransactionConfig`](https://docs.y.uno/zh-hans/docs/yuno-sdk/reference/objects-you-pass#transaction-config)。完整参考。
* [`onStatus`](https://docs.y.uno/zh-hans/docs/yuno-sdk/controllers/on-status)。接收最终状态。


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