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

# 通过 API

> 逐步说明如何通过 Yuno API endpoint 迁移客户并注册支付方式。

本指南逐步介绍如何使用 Yuno API endpoint 迁移令牌。按照所述步骤操作，您将整理出一份包含客户及其已注册支付方式的列表。

## 要求

在执行本指南中的步骤之前，请确保您已：

* 完成[从 gateway 账户导入卡片](https://docs.y.uno/zh-hans/docs/security-and-compliance/data-migration-processes/token-migration-process.md#importing-cards-from-a-gateway-account-steps-1-and-2)流程的三个相关步骤。
* 在 Yuno Dashboard 上获取您的 [API 凭证](https://docs.y.uno/zh-hans/docs/using-yuno/settings/developers-credentials.md)，其中包括：
  * `public-api-key`
  * `private-secret-key`
  * `account_id`

在继续阅读本指南之前，请确保您已完成这些步骤并拥有必要的数据。

## 通过 API 迁移令牌

### 第 1 步：创建客户

要开始令牌迁移流程，您需要使用[创建客户](https://docs.y.uno/reference/customers/create-customer.md) endpoint 将客户添加到 Yuno 系统。请注意，无法为 Yuno 系统中不存在的客户注册支付方式。如果客户已存在于 Yuno 中，您可以跳过此步骤。

要登记新客户，请提供其个人信息。此外，您必须提供 `merchant_customer_id`，这是您系统中用于标识该客户的唯一标识符。

> [!NOTE]
>
> **客户补充信息**
>
> 创建客户时，某些信息是可选的，但如果提供，可以提升用户的支付体验。非必填数据的示例包括电话号码、账单地址和收货地址。
>
> 如果您选择添加可选信息，请确保同时提供所有必填字段。

完成客户创建流程后，您将收到一个 `id`，用于在 Yuno 系统中标识该用户。使用此 `id` 注册现有的支付方式。

### 第 2 步：检查客户数据（可选）

在此步骤中，您可以选择验证每个已登记客户的信息。使用[检索客户](https://docs.y.uno/reference/customers/retrieve-customer.md) endpoint 访问客户数据。为此，请提供最初创建客户时生成的 `id`。

### 第 3 步：注册支付方式

要完成迁移流程，您需要使用第三方 vault 或 gateway 的数据为每个客户注册支付方式。

使用[注册支付方式](https://docs.y.uno/reference/payment-methods-direct-workflow/enroll-payment-method-api.md) endpoint 登记支付方式。请记住，此请求所需的 `customer_id` 是在[第 1 步](https://docs.y.uno/zh-hans/docs/security-and-compliance/data-migration-processes/via-api.md#step-1-create-customers)创建客户时获得的 `id`。此外，请包含 `provider_data` 对象，其中含有外部服务提供商的令牌，如下方代码片段所示：

```sh Request theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
curl --request POST \
     --url https://api-sandbox.y.uno/v1/customers/{{customer_id}}/payment-methods \
     --header 'X-Idempotency-Key: <Your X-Idempotency-Key>' \
     --header 'accept: application/json' \
     --header 'charset: utf-8' \
     --header 'content-type: application/json' \
     --header 'private-secret-key: <Your private-secret-key>' \
     --header 'public-api-key: <Your public-api-key>' \
     --data '
{
  "country": "BR",
  "type": "CARD",
  "workflow": "DIRECT",
  "provider_data": {
    "id": "MERCADO_PAGO",
    "payment_method_token": "{{provider_card_token}}"
  },
  "account_id": "{{account_id}}" 
}
'
```

在该 endpoint 的响应中，您将收到一个标识已注册支付方式的 `vaulted_token`。此 `vaulted_token` 将用于未来的支付，无需再提供额外的支付方式详细信息。

### 第 4 步：检查已注册的支付方式（可选）

支付方式注册后，您可以使用[检索已注册的支付方式](https://docs.y.uno/reference/payment-methods-direct-workflow/retrieve-enrolled-payment-methods-api.md) endpoint 验证其是否注册成功。请记住，此请求所需的 `customer_id` 是在[第 1 步](https://docs.y.uno/zh-hans/docs/security-and-compliance/data-migration-processes/via-api.md#step-1-create-customers)创建客户时获得的 `id`。


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