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

# 定期支付

> 使用 Yuno SDK 设置 Apple Pay 订阅：先进行一笔客户发起的交易，将令牌存入 vault，然后进行商户发起的扣款。

定期支付同时使用客户发起（CIT）和商户发起（MIT）的交易。整体流程如下：

1. 使用 `recurring_payment` 对象创建结账会话。
2. 执行一笔 CIT，以授权客户的支付方式并将其存入 vault。
3. 然后使用返回的 `vaulted_token` 进行后续的 MIT 扣款。

## 为定期支付创建结账会话

在创建交易之前，您需要创建结账会话，并在结账会话请求中填写 `recurring_payment` 对象：

\*\*免费试用：\*\*提供免费试用期时，请将根级 `amount.value` 设为 `0`，并按下方示例包含 `trial_billing` 对象。实际的定期扣款在 `regular_billing` 中定义，它会告知客户试用期结束后将被收取的金额。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "account_id": "123444",
  "merchant_order_id": "12333",
  "country": "US",
  "callback_url": "https://your-callback-url.com",
  "customer_id": "12333",
  "amount": {
    "currency": "EUR",
    "value": 0
  },
  "checkout_session": {
    "payment_description": "Basic Plan — 3-day free trial",
    "workflow": "SDK_CHECKOUT"
  },
  "recurring_payment": {
    "description": "Basic Plan",
    "management_url": "https://yourURL.com/subscriptions",
    "billing_agreement": "After your 3-day free trial ends, you will be charged EUR 11.99/month until you cancel. Cancel anytime via account settings or by contacting support@test.com.",
    "regular_billing": {
      "label": "Monthly Plan",
      "amount": 11.99,
      "interval_unit": "month",
      "interval_count": 1
    },
    "trial_billing": {
      "label": "3-Day Free Trial",
      "amount": 0,
      "interval_unit": "day",
      "interval_count": 3
    },
    "availability": {
      "start_at": "2026-09-13T20:00:00Z",
      "finish_at": "2026-09-30T16:10:00Z"
    }
  }
}
```

## 客户发起的交易（CIT）

CIT 是客户授权定期支付的初始交易，例如客户订阅每月服务时。此交易需要客户参与，并会生成一个用于未来 MIT 交易的令牌。

以下示例展示了一个完整的 CIT 请求：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "account_id": "62fa3145-1408-4044-a599-caa0c2159782",
  "amount": {
    "currency": "USD",
    "value": 2000
  },
  "checkout": {
    "session": "0793c7a5-79c6-40d6-aa5f-13e4e9bdf169"
  },
  "payment_method": {
    "vault_on_success": true,
    "type": "APPLE_PAY",
    "token": "684f1f66-5322-4c84-a0b63d",
    "detail": {
      "wallet": {
        "stored_credentials": {
          "reason": "SUBSCRIPTION",
          "usage": "FIRST"
        }
      }
    }
  },
  "customer_payer": {
    "id": "070a34cb-4649-4a4e-b231-065a53060379",
    "nationality": "CO",
    "browser_info": {
      "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Safari/605.1.15",
      "accept_header": "application/json",
      "accept_content": "*/*",
      "accept_browser": "*/*",
      "color_depth": "5",
      "screen_height": "8",
      "screen_width": "8",
      "javascript_enabled": true,
      "java_enabled": false,
      "browser_time_difference": "300",
      "language": "en",
      "platform": "WEB"
    }
  },
  "merchant_order_id": "merchant-order-123",
  "country": "US",
  "description": "Apple Pay recurring setup",
  "workflow": "SDK_CHECKOUT"
}
```

CIT 的关键参数如下：

* **`vault_on_success: true`**：此参数表示这是一次定期支付设置，并会生成用于未来 MIT 交易的令牌
* **`customer_payer.id`**：与 `vault_on_success` 一起必填。它必须引用一个已存在的客户（请先使用[创建客户](https://docs.y.uno/reference/customers/create-customer.md)创建）。缺少该参数时，支付仍会成功，但不会存入任何内容：响应会带有空的 `vaulted_token`，且不会返回错误
* **`detail.wallet.stored_credentials.usage: "FIRST"`**：表示这是定期系列中的初始交易
* **`verify`**：为 `true` 时，通过钱包启用卡验证流程（例如零金额授权），而不是常规的支付扣款。

> [!NOTE]
>
> 在 `amount` 为 `0` 的免费试用流程中，请设置 `verify: true`。对于标准的付费 CIT，请省略该字段。

> [!WARNING]
>
> 不要在 CIT 中将 `stored_credentials` 放在 `detail.card` 下。对于钱包支付，该字段不会被验证，且两步式 Apple Pay 流程不会将其带入已保存的支付方式，这会导致该记录没有存储凭证标志，也没有 `network_transaction_id`。

> [!NOTE]
>
> `vaulted_token` 仅在 CIT 支付响应中返回。通过钱包存入 vault 的支付工具有意不包含在[检索已注册的支付方式](https://docs.y.uno/reference/payment-methods-direct-workflow/retrieve-enrolled-payment-methods-api.md)中，因此不要依赖客户的支付方式列表来重新找到该令牌：请在 CIT 成功时将其存储（连同您需要的任何显示元数据）。已存储的令牌仍可通过[按 ID 检索已注册的支付方式](https://docs.y.uno/reference/payment-methods-direct-workflow/retrieve-enrolled-payment-method-by-id-api.md)单独解析。请参阅[存储凭证](https://docs.y.uno/zh-hans/docs/payment-features/stored-credentials.md#wallet-originated-tokens-apple-pay-and-google-pay)。

## 商户发起的交易（MIT）

MIT 交易使用 CIT 期间生成的令牌，在后续计费周期中自动处理。

以下示例展示了一个完整的 MIT 请求：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "account_id": "account-id",
  "amount": {
    "currency": "USD",
    "value": 100
  },
  "payment_method": {
    "vaulted_token": "98c16e23-ebdd-4d0f-85bd-e0ba7d2fedf6",
    "detail": {
      "card": {
        "stored_credentials": {
          "reason": "SUBSCRIPTION",
          "usage": "USED"
        }
      }
    },
    "type": "CARD"
  },
  "customer_payer": {
    "id": "customer-id"
  },
  "merchant_order_id": "recurring-order-456",
  "country": "US",
  "description": "Apple Pay recurring payment",
  "workflow": "DIRECT"
}
```

MIT 的关键参数如下：

* **`vaulted_token`**：CIT 响应中返回的令牌；用于在后续计费周期中向客户扣款，而无需重新授权
* **`type: "CARD"`**：存入 vault 的支付工具是一条卡记录。`"APPLE_PAY"` 也可以与 `vaulted_token` 一起使用
* **`detail.card.stored_credentials.usage: "USED"`**：表示这是定期系列中的后续交易
* **`workflow: "DIRECT"`**：服务器到服务器的扣款；不需要结账会话，也不需要 `payment_token`

通过 [webhooks](https://docs.y.uno/zh-hans/docs/webhooks.md) 监控支付状态，以处理边缘情况并向客户发送通知。

## 订阅管理 URL

对于 SDK 定期支付，您必须提供一个订阅管理 URL，供客户管理和取消订阅。请将其包含在您与客户的沟通中。

## 相关文档

* [设置和一次性支付](https://docs.y.uno/zh-hans/docs/wallets/apple-pay/apple-pay-sdk-integration.md)
* [存储凭证](https://docs.y.uno/zh-hans/docs/payment-features/stored-credentials.md)
* [订阅管理](https://docs.y.uno/zh-hans/docs/payment-features/subscriptions.md)
* [Webhooks](https://docs.y.uno/zh-hans/docs/webhooks.md)


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