> ## 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 注册

> 在 Web 上使用 full-checkout 注册支付方式，挂载注册表单并处理 callback

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

Web SDK 让您可以轻松实现注册流程，将支付方式保存到客户账户。

按照与[支付流程](https://docs.y.uno/docs/sdks/full-checkout/web-payments#include-the-library-in-your-project)相同的步骤在项目中引入库。这样即可完成[步骤 1](#step-1-include-the-library-in-your-project)，然后继续执行下面的注册流程。

## 其他资源

* Yuno 提供一个 [TypeScript 库](https://www.npmjs.com/package/@yuno-payments/sdk-web-types)，作为 SDK 的补充。

* 如果您不确定应采用哪种流程，请参阅[选择适合您的集成方式](https://docs.y.uno/zh-hans/docs/sdks/overview/choose-integration.md)。

* 有关完整实现，请参阅[演示应用](https://github.com/yuno-payments/yuno-sdk-web)（从代码库克隆）。

## 要求

* 在 Yuno 中创建的[客户](https://docs.y.uno/reference/customers/create-customer.md)、[客户会话](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session.md)和[注册支付方式对象](https://docs.y.uno/reference/payment-methods-checkout/enroll-payment-method-checkout.md)：设置您的 backend 时请参考各个 API。
* 公共 API 密钥（从 [Yuno Dashboard](https://dashboard.y.uno/) → **Developers** > **Credentials** 获取）

## 参数

有关参数和 callback 的完整列表，请参阅 [Web SDK 通用参考](https://docs.y.uno/zh-hans/docs/sdks/resources/references/web.md)。

| 参数 | 说明 |
| - | - |
| `customerSession` | 来自您 backend 的客户会话 ID（创建客户会话 API）。必填。 |
| `countryCode` | ISO 国家代码（例如 `US`）。 |
| `language` | UI 的语言代码（例如 `en`）。可选。 |
| `showLoading` | 显示加载动画。可选。 |
| `onLoading` | Callback：加载状态更新。可选。 |
| `elementSelector` | 挂载注册表单的 CSS 选择器。可选。请在 `renderMode: { type: "element", elementSelector }` 中传入，放在顶层时 SDK 会忽略它。 |
| `card` | 卡片表单选项。可选。 |
| `enrollmentStatus` | Callback：注册结束，接收 `vaultedToken` 和 `status`。 |
| `issuersFormEnable` | 显示发卡机构（银行）列表。可选。 |
| `texts` | 自定义按钮或标签文本。可选。 |

## full-checkout 注册（Web）

此流程使用 `mountEnrollmentLite`，即当前 Web SDK 中的注册方法，它会渲染预构建的注册表单。请按以下步骤实现注册。

### 步骤 1：在项目中引入库

在项目中引入库的方式与[支付流程](https://docs.y.uno/docs/sdks/full-checkout/web-payments#include-the-library-in-your-project)相同。

### 步骤 2：初始化 SDK

有关初始化，请参阅[快速入门指南](https://docs.y.uno/zh-hans/docs/sdks/overview/quickstart.md#web-sdk-integration)。

### 步骤 3：创建客户会话和注册支付方式对象

在您的**服务器端**创建[客户会话](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session.md)和[注册支付方式对象](https://docs.y.uno/reference/payment-methods-checkout/enroll-payment-method-checkout.md)，以确保私有 API 密钥的安全。创建支付方式对象时，定义客户可以注册哪种支付方式。

#### 服务器端示例

在您的 backend 上创建客户会话和注册支付方式。这样可以确保您的私有 API 密钥安全。

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// 1. Create customer session
const customerSession = await fetch(
  "https://api-sandbox.y.uno/v1/customers/sessions",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "public-api-key": PUBLIC_API_KEY,
      "private-secret-key": PRIVATE_SECRET_KEY,
    },
    body: JSON.stringify({
      account_id: ACCOUNT_ID,
      customer_id: "your-customer-id",
      country: "US",
    }),
  }
).then((res) => res.json());

// 2. Create enrollment payment method
const enrollment = await fetch(
  `https://api-sandbox.y.uno/v1/customers/sessions/${customerSession.customer_session}/payment-methods`,
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "public-api-key": PUBLIC_API_KEY,
      "private-secret-key": PRIVATE_SECRET_KEY,
      "X-Idempotency-Key": crypto.randomUUID(),
    },
    body: JSON.stringify({
      account_id: ACCOUNT_ID,
      payment_method_type: "CARD",
      country: "US",
    }),
  }
).then((res) => res.json());

// Return the customer session ID to your client
return customerSession.customer_session;
```

#### 客户端示例

从服务器收到 `customerSession` 后，在客户端初始化 Yuno SDK 并挂载注册表单。

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
// Initialize Yuno SDK
const yuno = await Yuno.initialize(PUBLIC_API_KEY);

// Mount the enrollment form
await yuno.mountEnrollmentLite({
  customerSession, // Received from your server
  countryCode: "US",
  language: "en",
  showLoading: true,
  onLoading: (args) => {
    console.log(args);
  },
});
```

要在注册前验证卡片（零金额授权），请在服务器上定义支付方式对象时添加 `verify` 结构。

### 步骤 4：挂载注册

使用 `await yuno.mountEnrollmentLite()` 并传入以下参数。

| 参数 | 说明 |
| - | - |
| `customerSession` | 指当前注册的[客户会话](https://docs.y.uno/reference/customer-sessions-enrollment/create-customer-session.md)。示例：`e15648b0-fcd5-4799-a14c-cc463ae8a133`。 |
| `countryCode` | 支付流程的国家。请使用 `ENUM` 值，参见[国家覆盖范围](https://docs.y.uno/zh-hans/docs/sdks/resources/country-coverage.md)。 |
| `language` | 支付表单的语言。可使用[支持的语言](https://docs.y.uno/zh-hans/docs/sdks/resources/languages-supported.md)中列出的任意代码。示例：`en`。如果可用，默认使用浏览器语言。 |
| `showLoading` | 控制支付过程中 Yuno 加载/加载动画页面的可见性。 |
| `onLoading` | 用于接收有关服务器调用或加载事件的通知，必填。 |
| `elementSelector` | 挂载 Yuno SDK 的 HTML 元素。请在 `renderMode: { type: "element", elementSelector }` 中传入，放在顶层时 SDK 会忽略它。 |
| `card` | 为信用卡表单定义特定设置。 |
| `enrollmentStatus` | 注册结束后的 callback，接收 `vaultedToken` 和 `status`。状态选项：`CREATED`、`EXPIRED`、`REJECTED`、`READY_TO_ENROLL`、`ENROLL_IN_PROCESS`、`UNENROLL_IN_PROCESS`、`ENROLLED`、`DECLINED`、`CANCELED`、`ERROR`、`UNENROLLED`。 |
| `issuersFormEnable` | 启用发卡机构表单（银行列表）。 |
| `texts` | 自定义支付表单按钮的文本，以匹配您应用的语言或品牌。 |
| `card.isCreditCardProcessingOnly` | 可选。强制将卡片交易按仅信用卡处理，适用于同时具备信用卡和借记卡功能的卡片。 |

以下代码块展示了注册参数配置和挂载的示例。

```javascript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
await yuno.mountEnrollmentLite({
  customerSession: 'e15648b0-fcd5-4799-a14c-cc463ae8a133',
  /**
   * The complete list of country codes is available on /docs/sdks/resources/country-coverage
   */
  countryCode: country,
  /**
  - Language for payment forms (see Supported languages)
  - Defaults to browser language when available
  */
  language: 'en',
  /**
   * Hide or show the Yuno loading/spinner page
   * Default is true
   * @optional
   */
  showLoading: true,
  /**
   * Required if you'd like to be informed if there is a server call
   * @param { isLoading: boolean, type: 'DOCUMENT' | 'ONE_TIME_TOKEN'  } data
   * @optional
   */
  onLoading: (args) => {
    console.log(args);
  },
  /**
   *  API card
   *  @optional
   */
  card: {
    /**
     * Mode render card can be step or extends
     * Default extends
     */
    type: "extends",
    /**
     * Write custom CSS to style the card form. Your CSS will be injected into the iframe.
     * Example:
     * `@import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&display=swap');
     *  .Yuno-front-side-card__name-label {
     *    color: red !important;
     *    font-family: 'Luckiest Guy' !important;
     *   }`
     */
    styles: '',
    /**
     * Show checkbox for save/enroll card
     * Default is false
     */
    cardSaveEnable: false,
    /**
     * Custom texts in Card forms buttons
     * Example:
     *
     *  texts: {
     *    cardForm?: {
     *      enrollmentSubmitButton?: string;
     *       paymentSubmitButton?: string;
     *     }
     *     cardStepper?: {
     *       numberCardStep?: {
     *         nextButton?: string;
     *       },
     *       cardHolderNameStep?: {
     *         prevButton?: string;
     *         nextButton?: string;
     *       },
     *       expirationDateStep?: {
     *         prevButton?: string;
     *         nextButton?: string;
     *       },
     *       cvvStep?: {
     *         prevButton?: string;
     *         nextButton?: string;
     *       }
     *     }
     *  }
     */
    texts: {},
    /**
     * Hide or show the document fields into card form
     * Default is true
     * @optional
     */
    documentEnable: true,
  },
  /**
   * Call back is called with the following object
   * @param {{
   *  status: 'CREATED'
   *    | 'EXPIRED',
   *    | 'REJECTED',
   *    | 'READY_TO_ENROLL',
   *    | 'ENROLL_IN_PROCESS',
   *    | 'UNENROLL_IN_PROCESS',
   *    | 'ENROLLED',
   *    | 'DECLINED',
   *    | 'CANCELED',
   *    | 'ERROR',
   *    | 'UNENROLLED',
   *  vaultedToken: string,
   * }}
   */
  enrollmentStatus: ({ status, vaultedToken}) => {
    console.log('status', { status, vaultedToken})
  },
  /**
   * If this is called the SDK should be mounted again
   * @param { error: 'CANCELED_BY_USER' | any }
   * @optional
   */
  error: (error) => {
    console.log('There was an error', error)
  },
});
```

为简洁起见，此示例省略了上文所述的 `card.isCreditCardProcessingOnly` 选项，详情请参阅参数表。

## 通用参考

有关完整的参数和自定义详情，请参阅 [Web SDK 通用参考](https://docs.y.uno/zh-hans/docs/sdks/resources/references/web.md)。


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