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

# 本地价格和税费（Stripe Billing）

> 通过托管的支付链接或 Lite SDK，以客户的币种并按其地址的税费收取 Stripe Billing 订阅的首次支付

当您使用 [Stripe Billing](https://docs.y.uno/zh-hans/docs/payment-features/subscriptions/stripe-billing.md) 作为订阅系统时，Yuno 可以在首次支付前以客户的本地币种显示价格，并加上其地址对应的税费。支付获得批准后，Yuno 会在 Stripe 中创建订阅，并在其首张发票中计入该税费。续订由 Stripe 以您价格的币种开具账单，并由 Yuno 扣款。

您可以选择客户的付款方式：

* **托管的支付链接：** Yuno 托管整个页面。您只需创建链接。
* **Lite SDK：** 您在自己的页面中渲染 checkout，并从您的 backend 获取税费报价。

> [!WARNING]
>
> **按组织启用**
>
> 本地价格（FX 报价）和税费收取默认关闭。请联系您的技术客户经理或关键客户经理启用这些功能，先在 sandbox 中启用，再在生产环境中启用。您的账户还需要完成 [Stripe Billing onboarding](https://docs.y.uno/zh-hans/docs/payment-features/subscriptions/stripe-billing.md#prerequisites)，并在您的 Stripe 账户中启用 Stripe Tax。

## 工作原理

1. **您使用 `external_subscription` 创建链接或结账会话**：其中包括 Stripe 客户和要销售的价格。此时 Yuno 尚未在 Stripe 中创建任何内容。
2. **客户看到本地价格。** 如果客户所在国家有已发布的汇率，页面会以本地币种打开并显示汇率，客户可以在价格币种和本地币种之间来回切换。仅转换 USD 价格。
3. **客户提供账单地址。** 始终要求提供国家。美国和加拿大还要求提供邮政编码。企业可以添加其名称和税号，以获得企业待遇（例如欧盟的反向征税）。
4. **Yuno 通过 Stripe Tax 获取税费报价**，每当国家、邮政编码或税号变化时都会重新报价，并显示总额。税费报价的有效期为 30 分钟；超过后，页面会在扣款前重新报价。
5. **客户支付报价总额**，以所选币种通过您的路由完成支付。
6. **Yuno 在 Stripe 中创建订阅：** 包括客户、价格、作为默认支付方式的卡，以及标记为已付款并包含报价税费的首张发票。被拒绝的支付不会在 Stripe 中创建任何内容。

## 开始之前

* **使用 USD 价格**（如果您使用本地价格）：FX 报价仅从 USD 转换。
* 在您收取税费的地区完成 **Stripe Tax 税务登记**。没有登记时，Stripe 会返回不适用任何税费。要向欧盟消费者收取 VAT，Stripe 需要 OSS 登记。
* 为买家准备一个 **Yuno 客户**（`customer_payer.id`）：Yuno 根据其国家选择本地币种。

## 选项 1：托管的支付链接

使用 `local_pricing`、`tax_collection` 和 `external_subscription` 创建链接。请参阅[创建支付链接](https://docs.y.uno/reference/payment-links/create-payment-link.md)。

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "account_id": "<your_account_id>",
  "description": "Pro plan, monthly",
  "country": "US",
  "amount": { "currency": "USD", "value": 29 },
  "payment_method_types": ["CARD"],
  "one_time_use": true,
  "customer_payer": { "id": "<yuno_customer_id>" },
  "local_pricing": true,
  "tax_collection": true,
  "external_subscription": {
    "provider": "STRIPE_BILLING",
    "customer_id": "cus_RplXYZ",
    "items": [{ "price": "price_1QwAbc", "quantity": 1 }]
  }
}
```

* `amount.value` 必须是各价格的小计，以价格的币种计算（价格乘以数量后相加）。否则，链接可以打开，但客户付款时支付会因 `TAX_QUOTE_INVALID` 被拒绝。
* 本地币种首先取自客户的国家，其次取自其账单地址的国家。没有国家时，链接会以价格的币种打开。
* `local_pricing` 和 `tax_collection` 相互独立：您可以只使用其中一个。
* 收取税费的链接从不应用[促销](https://docs.y.uno/zh-hans/docs/payment-features/promotions)。

将响应中的 `checkout_url` 发送给客户。页面可能显示的错误列在[托管 checkout 错误](https://docs.y.uno/reference/payment-links/hosted-checkout-errors.md)中。

## 选项 2：Lite SDK

1. **使用 `tax_collection: true` 和 `external_subscription`（`customer_id` 和 `items`）创建结账会话。** 请参阅[创建结账会话](https://docs.y.uno/zh-hans/reference/checkout-sessions/create-checkout-session.md)。
2. **使用 `onBillingAddressChanged` 启动 checkout。** 账单信息变化时 SDK 会调用它；您的 backend 通过[创建税费报价](https://docs.y.uno/reference/taxes/create-tax-quote.md)获取税费报价，然后由您返回总额。请参阅[含税 checkout](https://docs.y.uno/docs/sdks/lite-web/payment.md#checkouts-with-taxes)。
3. **在 `createPayment` 中创建支付**，将报价总额作为 `amount`，并提供 `vault_on_success: true`、`customer_payer.id`、`external_subscription.customer_id`，以及在 `additional_data.order.taxes` 中为报价的每一行添加一个条目，每个条目都带有 `source: YUNO_TAX_QUOTE` 和最新的 `tax_quote_id`。请参阅[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)。

每个税费条目复制报价中的一行，并将该行的 `taxable_amount` 作为 `tax_base`：

```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
"additional_data": {
  "order": {
    "taxes": [
      {
        "type": "SALES_TAX",
        "tax_base": 12.00,
        "value": 1.07,
        "percentage": 8.875,
        "source": "YUNO_TAX_QUOTE",
        "tax_quote_id": "txq_2a8a493dcc5c4230b4cf8d9359fd200a"
      }
    ]
  }
}
```

要在您自己的页面中显示本地价格，请使用[创建 FX 报价](https://docs.y.uno/reference/fx-rates/create-fx-quote.md)获取报价，并在报价过期前收取本地金额。

## 在 sandbox 中测试

* 使用已启用 Stripe Tax 且至少有一个税务登记的 Stripe 测试账户，例如纽约：邮政编码为 `10001` 的买家需缴纳 8.875% 的销售税。
* 位于未登记国家的买家会得到 `NO_TAX`。
* 在 Stripe 中检查结果：一个以价格币种计价的新订阅，以及已付款且包含税费的首张发票。

## 须知

* **报价会过期。** 税费报价有效期为 30 分钟，FX 报价有效至其 `expires_at`。过期的报价绝不会被扣款：页面会重新报价，由客户确认新的总额。
* **续订以价格的币种计费。** 本地价格仅适用于首次支付。
* **退款。** 首次支付的退款会在 Stripe 中为其发票添加一张贷项通知单。订阅仍保持有效：如果不应再向客户扣款，请在 Stripe 中取消订阅。
* **税号。** 客户提供的税号会保存在 Stripe 客户上，因此后续发票会保持企业待遇。


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