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

# 快速入门：您的第一笔 sandbox 支付

> 创建连接，在 Yuno sandbox 中使用测试卡发送一笔支付，并在 Dashboard 中查看。

入门

教程 · 约 10 分钟

Yuno 是面向支付的 AI 操作系统，而支付是您在其上运行的第一项业务。拿到 sandbox 凭据后，大约 10 分钟即可发送您的第一笔 sandbox 支付。

创建连接
使用测试卡发送一笔支付
在 Dashboard 中查看

<video src="https://docs.y.uno/videos/explainers/first-payment.mp4" poster="/videos/explainers/first-payment.jpg" controls preload="none" playsInline aria-label="您的第一笔支付" />

视频：您的第一笔支付（66 s，屏幕字幕，无旁白）

## 开始之前

本页的每次调用都需要以下信息。

| 项目 | 值 |
| - | - |
| 账户代码 | Dashboard 中 **Developers** 下的 `account_id` |
| 密钥 | `public-api-key` 和 `private-secret-key`，均以 `sandbox_` 开头 |
| 基础 URL | `https://api-sandbox.y.uno/v1`（保留 `/v1`） |
| 金额 | `amount.value` 是一个数字，与 `currency` 搭配使用。本页发送 `25` 和 `USD` |
| 工具 | Node 18 或更高版本，或 `curl` |

### 1. 获取 sandbox 凭据

登录 [Yuno Dashboard](https://dashboard.y.uno/)，打开 **Developers**，找到以下三个值：

* **账户代码**，在 Dashboard 中显示为 `account_id`
* **`public-api-key`**
* **`private-secret-key`**

Sandbox 密钥以 `sandbox_` 开头。生产环境密钥与之不同，以 `prod_` 开头。

![Yuno Dashboard 登录页面](https://mintcdn.com/yuno-3979e326/mqKc4056TZzyLssc/images/reference/step-1-set-up-your-account/image1.png?fit=max\&auto=format\&n=mqKc4056TZzyLssc\&q=85\&s=09be08d430f7f2e7af07821dd84f146f)

如果您还没有账户，请联系您的 Yuno 对接人，或发送邮件至 [sales@y.uno](mailto:sales@y.uno)。目前不支持自助注册。

将凭据设置为环境变量：

```bash Shell theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
export YUNO_PUBLIC_API_KEY="sandbox_..."
export YUNO_PRIVATE_SECRET_KEY="sandbox_..."
export YUNO_ACCOUNT_ID="your-account-code"
```

创建一个客户来验证密钥。基础 URL 为 `https://api-sandbox.y.uno/v1`。

```bash cURL theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
curl --request POST \
  --url https://api-sandbox.y.uno/v1/customers \
  --header "public-api-key: $YUNO_PUBLIC_API_KEY" \
  --header "private-secret-key: $YUNO_PRIVATE_SECRET_KEY" \
  --header "content-type: application/json" \
  --data '{
    "merchant_customer_id": "customer-0001",
    "first_name": "John",
    "last_name": "Doe",
    "email": "john.doe@example.com"
  }'
```

```javascript Node.js theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const res = await fetch("https://api-sandbox.y.uno/v1/customers", {
  method: "POST",
  headers: {
    "public-api-key": process.env.YUNO_PUBLIC_API_KEY,
    "private-secret-key": process.env.YUNO_PRIVATE_SECRET_KEY,
    "content-type": "application/json",
  },
  body: JSON.stringify({
    merchant_customer_id: "customer-0001",
    first_name: "John",
    last_name: "Doe",
    email: "john.doe@example.com",
  }),
});
const customer = await res.json();
console.log(customer.id);
```

```python Python theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
import os
import requests

res = requests.post(
    "https://api-sandbox.y.uno/v1/customers",
    headers={
        "public-api-key": os.environ["YUNO_PUBLIC_API_KEY"],
        "private-secret-key": os.environ["YUNO_PRIVATE_SECRET_KEY"],
    },
    json={
        "merchant_customer_id": "customer-0001",
        "first_name": "John",
        "last_name": "Doe",
        "email": "john.doe@example.com",
    },
)
print(res.json()["id"])
```

响应中包含一个 `id`。将其保存为 `YUNO_CUSTOMER_ID`，后续的支付步骤会用到它。

> [!TIP]
>
> **通过条件**：`POST /v1/customers` 返回 `201`。
>
> * `401` 表示密钥对错误。请从 **Developers** 重新复制两个 sandbox 密钥。
> * `404` 且响应体为空，表示基础 URL 中缺少 `/v1`。

### 2. 连接 Yuno Test Payment Gateway 并发布路由

Yuno Test Payment Gateway 模拟一个卡支付服务提供商。它仅在 sandbox 中可用，且无需凭据。

1. 打开 [Connections](https://dashboard.y.uno/connections)，搜索 **Yuno Test Payment Gateway**，点击 **Connect**，为连接命名，然后点击 **Save**。
2. 打开 [Routing](https://dashboard.y.uno/routing)，打开 **Not published** 选项卡，找到 **Card**，然后点击 **Set Up**。
3. 点击 **+ Create new route**，为其命名，然后点击 **Save**。
4. 点击箭头，选择 **Add step**，选择 **Yuno Test Payment Gateway**，然后点击 **Publish**。
5. 打开 [Checkout builder](https://dashboard.y.uno/checkout-builder)，开启 **Card**，并发布设置。

> [!TIP]
>
> **通过条件**：新的结账会话列出 `CARD`。按照步骤 4 创建一个会话，并将其 `checkout_session` 保存为 `YUNO_CHECKOUT_SESSION`。然后调用 [`GET /v1/checkout/sessions/{checkout_session}/payment-methods`](https://docs.y.uno/reference/checkout-sessions/retrieve-payment-methods-for-checkout)，在列表中查找 `"type": "CARD"`。
>
> 如果缺少 `CARD`，请检查以下三项设置：Test Payment Gateway 已连接，Card 路由位于 **Published** 下，且 Checkout builder 中已开启 Card。

### 3. 选择支付的创建方式

`workflow` 字段告诉 Yuno 由谁创建支付。选择其中一种，然后在步骤 4 中使用对应的选项卡。

| Workflow | 由谁创建支付 | 适用场景 |
| - | - | - |
| `SDK_SEAMLESS` | 由 SDK 创建支付 | 您希望涉及的环节最少。推荐 |
| `SDK_CHECKOUT` 加 `createPayment` callback | 由您的 backend 根据 SDK 交给您的一次性令牌创建 | 您需要在服务器上添加订单数据、欺诈检查或幂等性处理 |
| `DIRECT` | 由您的 backend 发送原始卡数据 | 您的系统已纳入 PCI DSS 范围。否则仅将其用于 sandbox 测试 |

会话与集成方式不一致会导致 `INTERNAL_ERROR`。有关每种方式的完整说明，请参阅 [Yuno SDK 入门](https://docs.y.uno/docs/yuno-sdk/get-started.md) 和 [Direct 流程](https://docs.y.uno/zh-hans/docs/direct-integration-use-cases/direct-flow.md)。

> [!TIP]
>
> **通过条件**：您能说出将要发送的 workflow：`SDK_SEAMLESS`、`SDK_CHECKOUT` 或 `DIRECT`。结账会话（SDK 方式）或支付（`DIRECT`）会在 `workflow` 字段中携带该值。

### 4. 发送支付

> [tab] DIRECT
>
> > [!WARNING]
> >
> > 从您的服务器发送原始卡号仅适用于 sandbox 测试。在生产环境中，这需要纳入 PCI DSS 范围。否则，请使用 Yuno SDK 或 Secure Fields 收集卡数据。
>
> `DIRECT` workflow 是一种背对背（back-to-back）支付，由您的服务器发送卡数据。使用您在步骤 1 中保存为 `YUNO_CUSTOMER_ID` 的客户 `id`。
>
> 使用测试卡创建支付。每笔支付都要发送一个新的 `X-Idempotency-Key`。
>
> ```bash cURL theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> curl --request POST \
>   --url https://api-sandbox.y.uno/v1/payments \
>   --header "public-api-key: $YUNO_PUBLIC_API_KEY" \
>   --header "private-secret-key: $YUNO_PRIVATE_SECRET_KEY" \
>   --header "X-Idempotency-Key: $(uuidgen)" \
>   --header "content-type: application/json" \
>   --data '{
>     "account_id": "'"$YUNO_ACCOUNT_ID"'",
>     "merchant_order_id": "order-0001",
>     "description": "First test payment",
>     "country": "US",
>     "amount": { "currency": "USD", "value": 25 },
>     "workflow": "DIRECT",
>     "customer_payer": { "id": "'"$YUNO_CUSTOMER_ID"'" },
>     "payment_method": {
>       "type": "CARD",
>       "detail": { "card": { "card_data": {
>         "number": "4507990000000002",
>         "expiration_month": 11,
>         "expiration_year": 28,
>         "security_code": "123",
>         "holder_name": "John Doe"
>       } } }
>     }
>   }'
> ```
>
> ```javascript Node.js theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> const res = await fetch("https://api-sandbox.y.uno/v1/payments", {
>   method: "POST",
>   headers: {
>     "public-api-key": process.env.YUNO_PUBLIC_API_KEY,
>     "private-secret-key": process.env.YUNO_PRIVATE_SECRET_KEY,
>     "X-Idempotency-Key": crypto.randomUUID(),
>     "content-type": "application/json",
>   },
>   body: JSON.stringify({
>     account_id: process.env.YUNO_ACCOUNT_ID,
>     merchant_order_id: "order-0001",
>     description: "First test payment",
>     country: "US",
>     amount: { currency: "USD", value: 25 },
>     workflow: "DIRECT",
>     customer_payer: { id: process.env.YUNO_CUSTOMER_ID },
>     payment_method: {
>       type: "CARD",
>       detail: { card: { card_data: {
>         number: "4507990000000002",
>         expiration_month: 11,
>         expiration_year: 28,
>         security_code: "123",
>         holder_name: "John Doe",
>       } } },
>     },
>   }),
> });
> const payment = await res.json();
> console.log(payment.status, payment.sub_status);
> ```
>
> ```python Python theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> import os
> import uuid
> import requests
>
> res = requests.post(
>     "https://api-sandbox.y.uno/v1/payments",
>     headers={
>         "public-api-key": os.environ["YUNO_PUBLIC_API_KEY"],
>         "private-secret-key": os.environ["YUNO_PRIVATE_SECRET_KEY"],
>         "X-Idempotency-Key": str(uuid.uuid4()),
>     },
>     json={
>         "account_id": os.environ["YUNO_ACCOUNT_ID"],
>         "merchant_order_id": "order-0001",
>         "description": "First test payment",
>         "country": "US",
>         "amount": {"currency": "USD", "value": 25},
>         "workflow": "DIRECT",
>         "customer_payer": {"id": os.environ["YUNO_CUSTOMER_ID"]},
>         "payment_method": {
>             "type": "CARD",
>             "detail": {"card": {"card_data": {
>                 "number": "4507990000000002",
>                 "expiration_month": 11,
>                 "expiration_year": 28,
>                 "security_code": "123",
>                 "holder_name": "John Doe",
>             }}},
>         },
>     },
> )
> payment = res.json()
> print(payment["status"], payment["sub_status"])
> ```
>
> 当响应如下所示时，表示支付成功：
>
> ```json Response (trimmed) theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "id": "6c44ed29-cc51-4479-a5eb-108afdaadd50",
>   "status": "SUCCEEDED",
>   "sub_status": "APPROVED",
>   "amount": { "currency": "USD", "value": 25 }
> }
> ```

> [tab] SDK\_SEAMLESS
>
> `SDK_SEAMLESS` 选项卡将工作分为两部分：您的服务器创建结账会话，浏览器加载 SDK 并启动交易。
>
> **在您的服务器上**，创建结账会话。使用 `workflow: "SDK_SEAMLESS"`，让 SDK 为您创建支付。否则交易将以 `INTERNAL_ERROR` 结束。
>
> ```bash cURL theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> curl --request POST \
>   --url https://api-sandbox.y.uno/v1/checkout/sessions \
>   --header "public-api-key: $YUNO_PUBLIC_API_KEY" \
>   --header "private-secret-key: $YUNO_PRIVATE_SECRET_KEY" \
>   --header "content-type: application/json" \
>   --data '{
>     "account_id": "'"$YUNO_ACCOUNT_ID"'",
>     "merchant_order_id": "order-0001",
>     "payment_description": "First test payment",
>     "country": "US",
>     "amount": { "currency": "USD", "value": 25 },
>     "workflow": "SDK_SEAMLESS"
>   }'
> ```
>
> ```javascript Node.js theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> const res = await fetch("https://api-sandbox.y.uno/v1/checkout/sessions", {
>   method: "POST",
>   headers: {
>     "public-api-key": process.env.YUNO_PUBLIC_API_KEY,
>     "private-secret-key": process.env.YUNO_PRIVATE_SECRET_KEY,
>     "content-type": "application/json",
>   },
>   body: JSON.stringify({
>     account_id: process.env.YUNO_ACCOUNT_ID,
>     merchant_order_id: "order-0001",
>     payment_description: "First test payment",
>     country: "US",
>     amount: { currency: "USD", value: 25 },
>     workflow: "SDK_SEAMLESS",
>   }),
> });
> const session = await res.json();
> console.log(session.checkout_session);
> ```
>
> ```python Python theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> import os
> import requests
>
> res = requests.post(
>     "https://api-sandbox.y.uno/v1/checkout/sessions",
>     headers={
>         "public-api-key": os.environ["YUNO_PUBLIC_API_KEY"],
>         "private-secret-key": os.environ["YUNO_PRIVATE_SECRET_KEY"],
>     },
>     json={
>         "account_id": os.environ["YUNO_ACCOUNT_ID"],
>         "merchant_order_id": "order-0001",
>         "payment_description": "First test payment",
>         "country": "US",
>         "amount": {"currency": "USD", "value": 25},
>         "workflow": "SDK_SEAMLESS",
>     },
> )
> print(res.json()["checkout_session"])
> ```
>
> **在浏览器中**，从 CDN 加载 SDK，然后使用服务器返回的 `checkout_session` 值启动交易。
>
> ```html Browser theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> <div id="payment-form"></div>
> <script src="https://sdk-web.y.uno/v2/main.js"></script>
> <script>
>   async function startYuno() {
>     const sdkPayments = await SdkPayments.initialize("your-public-api-key");
>     const transaction = sdkPayments.transaction({
>       checkoutSession: "checkout-session-from-your-server",
>       countryCode: "US",
>       elementSelector: "#payment-form",
>       onStatus: (result) => console.log("Final status:", result.status),
>     });
>     await transaction.start({ paymentMethod: { type: "CARD" } });
>   }
>
>   if (window.SdkPayments) {
>     startYuno();
>   } else {
>     window.addEventListener("sdk-payments-ready", startYuno);
>   }
> </script>
> ```
>
> 表单会渲染在 `#payment-form` 中。输入测试卡 **4507 9900 0000 0002**，有效期 **11/28**，CVV **123**，姓名 **John Doe**，然后点击 Pay。结果会通过 `onStatus` 返回，状态为 `SUCCEEDED`。
>
> 有关 iOS、Android 及全部选项，请参阅 [SDK 入门](https://docs.y.uno/docs/yuno-sdk/get-started.md)。

> [tab] SDK\_CHECKOUT
>
> 您的服务器使用 `workflow: "SDK_CHECKOUT"` 创建结账会话。浏览器启动交易并传入 `createPayment` callback。SDK 将一次性令牌交给该 callback，您的 backend 再用它创建支付。
>
> **在您的服务器上**，使用步骤 1 中的客户创建结账会话：
>
> ```bash cURL theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> curl --request POST \
>   --url https://api-sandbox.y.uno/v1/checkout/sessions \
>   --header "public-api-key: $YUNO_PUBLIC_API_KEY" \
>   --header "private-secret-key: $YUNO_PRIVATE_SECRET_KEY" \
>   --header "content-type: application/json" \
>   --data '{
>     "account_id": "'"$YUNO_ACCOUNT_ID"'",
>     "merchant_order_id": "order-0001",
>     "payment_description": "First test payment",
>     "country": "US",
>     "customer_id": "'"$YUNO_CUSTOMER_ID"'",
>     "amount": { "currency": "USD", "value": 25 },
>     "workflow": "SDK_CHECKOUT"
>   }'
> ```
>
> **在浏览器中**，启动交易并覆盖 `createPayment`。将 `token.token` 和 `token.checkout_session` 发送到您的 backend：
>
> ```html Browser theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> <div id="payment-form"></div>
> <script src="https://sdk-web.y.uno/v2/main.js"></script>
> <script>
>   async function startYuno() {
>     const sdkPayments = await SdkPayments.initialize("your-public-api-key");
>     const transaction = sdkPayments.transaction({
>       checkoutSession: "checkout-session-from-your-server",
>       countryCode: "US",
>       elementSelector: "#payment-form",
>       createPayment: async (token) => {
>         await fetch("/api/pay", {
>           method: "POST",
>           headers: { "content-type": "application/json" },
>           body: JSON.stringify({
>             token: token.token,
>             checkout_session: token.checkout_session,
>           }),
>         });
>       },
>       onStatus: (result) => console.log("Final status:", result.status),
>     });
>     await transaction.start({ paymentMethod: { type: "CARD" } });
>   }
>
>   if (window.SdkPayments) {
>     startYuno();
>   } else {
>     window.addEventListener("sdk-payments-ready", startYuno);
>   }
> </script>
> ```
>
> 在每条路径上（包括网络故障）都要让 Promise 结束（settle），否则交易会一直处于进行中状态。请参阅 [`createPayment`](https://docs.y.uno/docs/yuno-sdk/controllers/create-payment)。
>
> **再次在您的服务器上**，您的 `/api/pay` 处理程序通过 `POST /v1/payments` 创建支付。在 `payment_method.token` 中发送令牌，在 `checkout.session` 中发送会话：
>
> ```javascript Node.js theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> // token and checkoutSession come from the browser request body
> async function createPayment({ token, checkoutSession }) {
>   const res = await fetch("https://api-sandbox.y.uno/v1/payments", {
>     method: "POST",
>     headers: {
>       "public-api-key": process.env.YUNO_PUBLIC_API_KEY,
>       "private-secret-key": process.env.YUNO_PRIVATE_SECRET_KEY,
>       "X-Idempotency-Key": crypto.randomUUID(),
>       "content-type": "application/json",
>     },
>     body: JSON.stringify({
>       account_id: process.env.YUNO_ACCOUNT_ID,
>       merchant_order_id: "order-0001",
>       description: "First test payment",
>       country: "US",
>       amount: { currency: "USD", value: 25 },
>       customer_payer: { id: process.env.YUNO_CUSTOMER_ID },
>       payment_method: { token },
>       checkout: { session: checkoutSession },
>     }),
>   });
>   return res.json();
> }
> ```
>
> 输入测试卡 **4507 9900 0000 0002**，有效期 **11/28**，CVV **123**，姓名 **John Doe**，然后点击 Pay。响应的结构与上文的 `DIRECT` 响应相同。

> [!TIP]
>
> **通过条件**：使用测试卡 **4507 9900 0000 0002**（11/28，CVV 123，John Doe）时，支付的 `status` 为 `SUCCEEDED`。

### 5. 查看结果

* 检查响应中的 `status` 和 `sub_status`。`SUCCEEDED` 加 `APPROVED` 表示 gateway 已批准该支付。
* 在 Dashboard 中打开 [Payments](https://dashboard.y.uno/payments)，找到您的支付，打开即可查看详情。
* 如需在服务器上接收结果，请[配置 webhook](https://docs.y.uno/zh-hans/docs/webhooks/configure-webhooks.md)并[验证其签名](https://docs.y.uno/zh-hans/docs/webhooks/verify-webhook-signatures-hmac.md)（HMAC）。

所有支付状态请参阅 [支付状态](https://docs.y.uno/reference/payments/status-and-response-codes/payment.md)。

> [!TIP]
>
> **通过条件**：支付在 Dashboard 的 **Payments** 列表中以及响应的 `status` 字段中均显示为 `SUCCEEDED`。

## 下一步

> [card] [上线](https://docs.y.uno/zh-hans/docs/go-live.md)
>
> 指南
> Live 密钥、已发布的路由、经过验证的 webhooks 以及第一笔真实支付。

## 故障排除

> [accordion] API 返回 401
>
> 缺少 `public-api-key` 或 `private-secret-key` 标头，或其值错误。Sandbox 和生产环境使用不同的密钥，因此请确认您是在 Test Mode 下从 Dashboard 复制的 sandbox 密钥。请参阅 [身份验证](https://docs.y.uno/reference/getting-started/authentication.md)。

> [accordion] 支付以 INTERNAL\_ERROR 结束
>
> `workflow` 与您的集成方式不匹配。当您的服务器发送卡数据时，使用 `DIRECT`；当 Web SDK 创建支付时，在结账会话上使用 `SDK_SEAMLESS`。

> [accordion] 没有服务提供商处理该支付
>
> Card 没有已发布的路由。打开 [Routing](https://dashboard.y.uno/routing)，检查包含 Yuno Test Payment Gateway 的 Card 路由是否位于 **Published** 选项卡下，以及 [Checkout builder](https://dashboard.y.uno/checkout-builder) 中是否已开启 Card。

> [accordion] 卡片已拒绝
>
> 测试卡与特定服务提供商绑定。本快速入门中的测试卡仅在您的 sandbox 将 Card 路由到 Yuno Test Payment Gateway 时才有效。其他结果列于 [Yuno Test Payment Gateway](https://docs.y.uno/zh-hans/docs/direct-integration-use-cases/yuno-testing-gateway.md) 页面。

遇到不熟悉的术语？请参阅[术语表](https://docs.y.uno/zh-hans/docs/glossary.md)。有关 URL、密钥和规范，请参阅 [Developers](https://docs.y.uno/zh-hans/docs/developers.md)。


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