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

# 创建订阅

> 创建包含计费周期、试用期和已存储支付凭证的定期订阅计划。

> [!NOTE]
>
> **在创建订阅的同时完成首次支付**
>
> 此 endpoint 基于您已持有的 `vaulted_token` 启动订阅。如果客户在注册的同时进行支付，您也可以改为在[创建支付](https://docs.y.uno/zh-hans/reference/payments/create-payment.md)中发送 `subscription` 块：一次调用即可扣款并基于同一笔扣款创建订阅。该方式仅适用于无摩擦的卡支付。请参阅[通过首笔支付开通订阅](https://docs.y.uno/zh-hans/docs/payment-features/subscriptions/start-with-payment.md)。

> [!NOTE]
>
> **在创建订阅时应用促销**
>
> 发送带有 `id` 或 `code` 的 `promotion`，即可应用已附加到该计划的促销。首次扣款将包含该折扣。订阅所在的计划必须已附加该促销。订阅会存储一份自己的促销副本，之后不会再被修改。请参阅[订阅计划促销](https://docs.y.uno/zh-hans/docs/payment-features/subscriptions/promotions.md)。
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> { "promotion": { "id": "8f2d6c1e-3b7a-4c55-9a1e-2f4d8b7c6a10" } }
> ```
>
> 如果计划附加了 `AUTOMATIC` 促销，在该计划上创建订阅时会自动应用。如果请求同时发送了 `promotion`，则以折扣较大者为准；两者不会叠加。

> [!WARNING]
>
> **订阅完成**
>
> `billing_cycles` 和 `availability.finish_at` 字段会相互影响。如果在创建订阅时同时填写了这两个字段，订阅将在到达这两个字段所定义的最近事件（无论是计费周期还是对应的 `finish_at`）时转换为 `COMPLETED` 状态。

> [!WARNING]
>
> **先前 CIT 的凭证用法**
>
> 如果您在创建订阅*之前*创建了一笔 CIT 支付（例如 Apple Pay 或卡支付），并将生成的存储令牌传入订阅，则您**必须**包含 `payment_method.card.usage`，以表明这是首次使用还是后续使用。否则，续订扣款将被视为 CIT，并被服务提供商判定为已拒绝。
>
> 新订阅所需的 payload：
>
> ```json theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
> {
>   "payment_method": {
>     "type": "CARD",
>     "vaulted_token": "{{vaulted_token}}",
>     "card": {
>       "usage": "USED"
>     }
>   }
> }
> ```

## 促销错误

使用 `promotion` 创建订阅时，可能会因以下代码而失败。在任何一种情况下，都不会创建任何内容。

| HTTP | `code` | 触发条件 |
| :- | :- | :- |
| `404` | `PROMOTION_NOT_FOUND` | `promotion` ID 或代码未知，或属于其他账户。 |
| `422` | `PROMOTION_NOT_ATTACHED_TO_PLAN` | 该促销未附加到该计划。 |
| `422` | `PROMOTION_NOT_APPLICABLE` | 无法应用该促销。`reason` 会说明原因，例如 `USAGE_LIMIT_REACHED`、`EXPIRED`，或在您的组织未启用促销时返回 `PROMOTIONS_NOT_ENABLED`。 |
| `503` | `PROMOTION_ENGINE_UNAVAILABLE` | 促销服务未响应。请重试该请求。 |
| `504` | `PROMOTION_ENGINE_TIMEOUT` | 促销服务未及时响应。请重试该请求。 |

附加到计划的 `AUTOMATIC` 促销的处理方式不同。如果它因已停用、已过期或没有剩余使用次数而无法应用，订阅会在不包含该促销的情况下创建，请求仍然成功。当促销服务找不到已附加的促销时，也是如此。只有 `503` 或 `504` 会中止创建。

有关可能的错误结果，请参阅 [HTTP 响应码](https://docs.y.uno/zh-hans/reference/getting-started/response-codes.md)部分。

## 设置退款规则

可以在创建时设置 `refund_rule`，用于配置当之后的取消请求未携带自己的 `refund_amount` 时，`CUSTOM` 退款的金额如何计算：

```json A share of the charged amount theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{ "refund_rule": { "type": "PERCENT", "percent": 50 } }
```

```json A flat amount theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{ "refund_rule": { "type": "FIXED", "amount": { "value": 8000, "currency": "COP" } } }
```

`PERCENT` 和 `FIXED` 互斥：`PERCENT` 规则仅携带 `percent`（0 到 100），`FIXED` 规则仅携带 `amount`。`FIXED` 规则的 `amount.currency` 必须与订阅自身的币种一致。

之后可以在[更新订阅](https://docs.y.uno/zh-hans/reference/subscriptions/update-subscription.md#setting-a-refund-rule)中更改或清除该规则，其说明见[订阅对象](https://docs.y.uno/zh-hans/reference/subscriptions/the-subscription-object.md)。有关其用法，请参阅[取消订阅](https://docs.y.uno/zh-hans/reference/subscriptions/cancel-subscription.md#custom)。仅适用于已启用此功能的组织，请联系 Yuno；对于其他组织，发送的 `refund_rule` 会被静默忽略，且不会存储任何内容。


## OpenAPI

````yaml openapi/zh-hans/subscriptions/create-subscription.json POST /subscriptions
openapi: 3.1.0
info:
  title: subscription
  version: 1.0.2
servers:
  - url: https://api-sandbox.y.uno/v1
    description: Sandbox
  - url: https://api.y.uno/v1
    description: Production (US)
security:
  - sec0: []
    sec1: []
paths:
  /subscriptions:
    post:
      summary: 创建订阅
      operationId: create-subscription
      parameters:
        - in: header
          name: x-idempotency-key
          schema:
            type: string
            default: '{$randomUUID}'
          description: >-
            请求的唯一标识符。每次必须不同（UUID）。请参阅[身份验证](/zh-hans/reference/getting-started/authentication#idempotency)。
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - account_id
                - country
                - payment_method
                - customer_payer
              properties:
                name:
                  type: string
                  description: 订阅计划名称（MAX 255；MIN 3）。
                description:
                  type: string
                  description: 订阅计划描述（MAX 255；MIN 3）。
                account_id:
                  type: string
                  description: 可以使用该订阅计划的账户的唯一标识符（UUID，36 个字符）。
                merchant_reference:
                  type: string
                  description: 订阅计划的标识（MAX 255；MIN 3）。
                soft_descriptor:
                  type: string
                  maxLength: 255
                  description: >-
                    显示在持卡人银行对账单上的账单描述符。设置后，它会保存在订阅上，并传递到订阅引擎生成的每一笔续订支付。长度和格式限制因服务提供商而异（例如，Unlimit
                    截断为 22 个字符，Airwallex 截断为 30 个字符）。Worldpay 不读取该字段，而是根据
                    `payment_description` 生成账单说明。
                country:
                  type: string
                  description: >-
                    订阅所在国家/地区（MAX 2；MIN 2；[ISO
                    3166-1](/zh-hans/reference/country-reference)）。
                amount:
                  type: object
                  description: 指定 `amount` 对象，包含每次订阅支付的金额和所使用的币种。与 `plan_id` 互斥，两者只能发送一个。
                  required:
                    - currency
                    - value
                  properties:
                    currency:
                      type: string
                      description: >-
                        支付所使用的币种（MAX 3；MIN 3；[ISO
                        4217](/zh-hans/reference/country-reference)）。
                    value:
                      type: number
                      description: 订阅每次支付的金额（0.0001 的倍数）。
                      format: float
                plan_id:
                  type: string
                  description: >-
                    要让该客户订阅的[计划](/zh-hans/reference/plans/the-plan-object)的唯一标识符。与
                    `amount` 互斥，两者只能发送一个。设置它时请省略 `trial_period` 和
                    `billing_date`：这两者都继承自计划，如果发送，请求会以 `400 BAD_REQUEST`
                    被驳回。也请省略
                    `frequency`：它同样继承自计划，但无论如何发送都不会被驳回：它会被静默忽略，并被计划的频率覆盖。如果计划有自己的重试配置，也请省略
                    `retries`：订阅会采用计划的重试设置，而无论如何发送的 `retries` 对象都会被忽略。
                additional_data:
                  type: object
                  description: 指定 additional_data 对象。此对象不是必需的。但是，如果您发送此信息，将改善您的用户的支付体验。
                  properties:
                    order:
                      type: object
                      description: 指定订单对象。
                      properties:
                        items:
                          type: array
                          description: 指定该项的对象。
                          items:
                            properties:
                              id:
                                type: string
                                description: 商品的唯一标识符（MAX 255；MIN 3）。
                              name:
                                type: string
                                description: 商品名称（MAX 255；MIN 3）。
                              quantity:
                                type: integer
                                description: 商品数量。
                                format: int32
                              unit_amount:
                                type: number
                                description: 商品单价（0.0001 的倍数）。
                              category:
                                type: string
                                description: 商品的类别。请查看商品类别参考。
                                enum:
                                  - art
                                  - baby
                                  - coupons
                                  - beauty_&_personal_care
                                  - donations
                                  - computing
                                  - books
                                  - grocery_&_gourmet_food
                                  - cameras
                                  - video_games
                                  - television
                                  - car_electronics
                                  - electronics
                                  - automotive
                                  - toys_&_games
                                  - musical_instruments
                                  - handmade
                                  - garden_&_outdoor
                                  - entertainment
                                  - industrial_&_scientific
                                  - fashion
                                  - games
                                  - pet_supplies
                                  - home
                                  - musical
                                  - phones
                                  - services
                                  - learnings
                                  - tickets
                                  - travels
                                  - virtual_goods
                                  - others
                              brand:
                                type: string
                                description: 商品品牌（MAX 255；MIN 3）。
                              sku_code:
                                type: string
                                description: 商品的库存单位（SKU）（MAX 255；MIN 3）。
                              manufacture_part_number:
                                type: string
                                description: 商品的制造商零件编号。
                            type: object
                frequency:
                  type: object
                  description: 指定 `frequency` 对象。定义订阅的计费频率，包括类型和值。
                  required:
                    - type
                  properties:
                    type:
                      type: string
                      description: >-
                        订阅在时间上的间隔类型（DAY、WEEK、MONTH、YEAR）。如果未设置，默认为 MONTH。当
                        `payment_method.type` 为 `PIX_AUTOMATIC` 时，只允许 `value` 为
                        `1` 的 `WEEK`、`MONTH` 和 `YEAR`，其他所有类型和所有其他值都会以 `400
                        INVALID_PARAMETERS` 被驳回。请参阅 [Pix
                        Automático](/zh-hans/docs/payment-features/subscriptions/pix-automatico#accepted-billing-cadences)。
                      enum:
                        - DAY
                        - WEEK
                        - MONTH
                        - YEAR
                    value:
                      type: integer
                      description: 每个间隔之间的值。最小为 1。如果未设置，默认为 1。
                      format: int32
                billing_cycles:
                  type: object
                  description: >-
                    指定 `billing_cycles`
                    对象。定义与订阅关联的扣款次数。如果省略，订阅没有周期上限，会一直计费，直到被取消或到达
                    `availability.finish_at`（如果设置了的话）。
                  properties:
                    total:
                      type: integer
                      description: 订阅的计费周期总数（MIN 1）。小于 1 的值会以 `400` 错误被驳回。
                      format: int32
                      minimum: 1
                customer_payer:
                  type: object
                  description: >-
                    指定用于识别客户的 `customer_payer` 对象。必填。请注意，该对象上的验证错误使用的字段名是
                    `customer_payer.code`，而不是 `customer_payer.id`，例如省略时会返回 `400
                    BAD_REQUEST`（"customer_payer.code field is required"）。
                  properties:
                    id:
                      type: string
                      description: 客户的唯一标识符（UUID，36 个字符）。
                    ip_address:
                      type: string
                      maxLength: 45
                      example: 203.0.113.7
                      description: >-
                        付款人在首次客户发起的支付时的 IP 地址（IPv4 或 IPv6，最多 45
                        个字符）。它会保存在订阅上，并在每次续订时发送；某些支付服务提供商要求商户发起的续订提供该值。可选：空值或缺失的值会被忽略。不是有效
                        IPv4 或 IPv6 地址的值会返回 `400 BAD_REQUEST`（"The
                        customer_payer.ip_address must be a valid IPv4 or IPv6
                        address."）。仅对已启用该功能的组织保存和返回。
                payment_method:
                  type: object
                  description: >-
                    指定 `payment_method` 对象。支持的类型为 `CARD`、`PAYPAL_ENROLLMENT` 和
                    `PIX_AUTOMATIC`，均使用之前已注册的支付方式（`vaulted_token`）
                  required:
                    - type
                  properties:
                    type:
                      type: string
                      description: >-
                        支付方式类型。`PIX_AUTOMATIC` 对巴西 Pix Automático
                        委托扣款，不区分大小写匹配，并限制计费间隔，请参阅 [Pix
                        Automático](/zh-hans/docs/payment-features/subscriptions/pix-automatico)。
                      enum:
                        - CARD
                        - PAYPAL_ENROLLMENT
                        - PIX_AUTOMATIC
                    vaulted_token:
                      type: string
                      description: 存储令牌（UUID，36 个字符）。
                    card:
                      type: object
                      properties:
                        installments:
                          type: integer
                          description: 分期期数（MAX 50；MIN 1）。
                        network_transaction_id:
                          type: string
                          description: Visa/Mastercard 在首次支付的响应中提供的 ID（MAX 256；MIN 1）。
                        usage:
                          type: string
                          description: >-
                            表示此已存储凭证是首次使用（FIRST）还是之前已使用过（USED）。如果在订阅之前创建了 CIT
                            支付，则为必填：没有它，续订扣款会被视为 CIT，并可能被拒绝。
                          enum:
                            - FIRST
                            - USED
                trial_period:
                  type: object
                  description: 指定试用期对象
                  properties:
                    billing_cycles:
                      type: integer
                      description: 试用期包含的周期数。如果未设置，默认为 1（MIN 1）。
                      format: int32
                    amount:
                      type: object
                      description: 试用期要减免的金额
                      required:
                        - currency
                        - value
                      properties:
                        currency:
                          type: string
                          description: >-
                            支付所使用的币种（MAX 3；MIN 3；[ISO
                            4217](/zh-hans/reference/country-reference)）。
                        value:
                          type: number
                          description: 订阅每次支付的金额（0.0001 的倍数）。
                          format: float
                availability:
                  type: object
                  description: 指定 `availability` 对象。根据开始日期和结束日期定义订阅可用的日期区间。
                  properties:
                    start_at:
                      type: string
                      description: >-
                        订阅计划可以开始使用的开始日期。如果未设置，订阅从创建的那一刻起即可使用。必须晚于当前时间：过去的日期会返回
                        `400 BAD_REQUEST`。
                      format: date-time
                    finish_at:
                      type: string
                      description: 订阅计划可以使用的截止日期。如果未定义，订阅没有到期日期。
                      format: date-time
                metadata:
                  type: array
                  description: >-
                    可以附加到对象上的一组键值对。这有助于以结构化的格式存储对象的附加信息。向 metadata
                    发送空值可以取消设置键。您最多可以添加 50 个 metadata 对象。
                  items:
                    properties:
                      key:
                        type: string
                        description: 元数据键（MAX 48）。
                      value:
                        type: string
                        description: 元数据键值（MAX 512）。
                    type: object
                retries:
                  type: object
                  description: >-
                    指定 'retries' 对象。是否需要在 Yuno 中重试被拒绝的交易，以及必要时的金额。使用 `plan_id`
                    时，仅当计划本身没有重试配置时才发送 `retries`。如果计划定义了重试，订阅会采用计划的重试设置，请求中发送的
                    `retries` 会被忽略；但它仍会被验证，因此格式错误的对象会以 `400` 被驳回。`PIX_AUTOMATIC`
                    订阅保留 Pix 通道的固定重试，因此为其选择自己定义了重试的计划时，会以 `400
                    INVALID_PARAMETERS` 被驳回。
                  properties:
                    retry_on_decline:
                      type: boolean
                      description: 首次被拒绝之后是否重试支付。默认为 False。
                    amount:
                      type: integer
                      description: 订阅计划需要完成的重试次数。如果未设置该值或该值大于 6，则默认为 6。（MAX 6）。
                      format: int32
                    strategy:
                      type: string
                      description: >-
                        重试策略。允许的值：DEFAULT（固定重试计划）、SMART（基于机器学习的重试时机，从第二次重试开始应用）或
                        CUSTOM_SCHEDULE（使用您提供的每次尝试计划数组）。
                      enum:
                        - DEFAULT
                        - SMART
                        - CUSTOM_SCHEDULE
                    schedule:
                      type: array
                      description: >-
                        定义每次重试事件的计划策略的对象，对象数量应与定义的重试次数一致。最多 7 次尝试；尝试编号必须从 1
                        开始依次递增，每个 delay_seconds 必须在 1 到 604800（7
                        天）之间。之后可以通过更新订阅替换该计划。
                      items:
                        properties:
                          attempt:
                            type: number
                            description: 重试尝试的编号
                          delay_seconds:
                            type: number
                            description: 指定每次重试之间的秒数。
                        type: object
                    stop_on_hard_decline:
                      type: boolean
                      description: >-
                        为 true 时，在硬拒绝之后，当前计费周期的重试计划会停止。仅此一项时，订阅保持
                        ACTIVE，计费推进到下一个周期；不会取消或暂停任何订阅，也不会发出订阅 webhook。如果
                        cancel_on_exhausted_retries 也为 true，则订阅会被取消。
                    cancel_on_exhausted_retries:
                      type: boolean
                      description: >-
                        为 true 时，一个计费周期的重试结束后仍没有支付成功，订阅就会被取消，而不是保持 ACTIVE
                        并推进到下一个周期。订阅状态变为 CANCELED，cancellation_source 设置为
                        RETRIES_EXHAUSTED，未来的计费停止，并发出一条 SUBSCRIPTION.CANCEL
                        webhook。无论是重试计划用完，还是 stop_on_hard_decline
                        提前结束该周期，都适用。默认为 false，保持现有行为。仅限创建时设置：之后无法更改，更新订阅会以 400
                        驳回不同的值。取消本身是最终的，因此之后重试订阅会被驳回。
                initial_payment_validation:
                  type: boolean
                  description: 标志，用于确定订阅是否应等待首次支付后再继续。默认为 False。
                billing_date:
                  type: object
                  description: 指定 `billing_date` 对象。定义订阅逻辑所使用的日期类型。与 frequency 对象互斥。
                  properties:
                    type:
                      type: string
                      description: >-
                        订阅在时间上采用的 billing_date
                        类型。PREPAID、POSTDATE、DAY。如果未设置，默认使用计划的创建日期。
                    day:
                      type: integer
                      description: '[条件] 当类型为 DAY 时，订阅扣款的每月日期。默认为 1。范围 1 - 31。'
                subscription_agreement_id:
                  type: string
                  description: >-
                    将此订阅关联到使用相同协议 ID 创建的首次支付。用于跟踪、对账和拒付处理。必须与原始支付中
                    `payment_method.detail.card.stored_credentials.subscription_agreement_id`
                    里发送的 `subscription_agreement_id` 完全一致（MAX 255）。
                refund_rule:
                  type: object
                  description: >-
                    配置退款规则，当之后的 CUSTOM 取消请求没有自带 refund_amount
                    时，用它来确定该取消的退款。适用于已启用该功能的组织；请联系 Yuno。
                  properties:
                    type:
                      type: string
                      enum:
                        - PERCENT
                        - FIXED
                      description: PERCENT 将退款确定为已扣款金额的百分比；FIXED 将其确定为固定金额。
                      example: FIXED
                    percent:
                      type: number
                      description: 当 type 为 PERCENT 时必填，且仅在此时允许（0-100）。
                      example: 50
                    amount:
                      type: object
                      description: 当 type 为 FIXED 时必填，且仅在此时允许。
                      properties:
                        value:
                          type: number
                          example: 10000
                        currency:
                          type: string
                          description: 必须与订阅自身的币种一致。
                          example: COP
                promotion:
                  type: object
                  description: >-
                    应用附加到该订阅所创建计划上的促销。`id` 和 `code`
                    只能发送其中一个。促销随订阅开始，并对第一次扣款打折。如果无法应用（它没有附加到该计划、已过期、已停用、尚未开始，或没有剩余使用次数），请求会被驳回，并且不会创建任何内容。如果计划还有自动促销，则第一次扣款采用折扣更大的那一个，折扣相同时以您发送的促销为准。请参阅[订阅计划上的促销](/zh-hans/docs/payment-features/subscriptions/promotions)。
                  properties:
                    id:
                      type: string
                      description: 促销的 ID（UUID）。使用 `id` 或 `code`，不能同时使用。
                    code:
                      type: string
                      description: 带有代码的促销的代码。使用 `id` 或 `code`，不能同时使用。
            examples:
              Subscription:
                value:
                  name: Test Subscription
                  description: Subscription Test
                  merchant_reference: subscription-ref-merchant-AA01
                  soft_descriptor: ACME SUBSCRIPTION
                  account_id: 493e9374-510a-4201-9e09-de669d75f256
                  country: CL
                  amount:
                    currency: CLP
                    value: 15000
                  frequency:
                    type: MONTH
                    value: 1
                  billing_cycles:
                    total: 12
                  customer_payer:
                    id: a1d3b664-e32a-4508-9da1-9ede3e62a60c
                  payment_method:
                    type: CARD
                    vaulted_token: d4aa3586-def2-4705-b7cd-fe064bb764e6
                    card:
                      installments: 3
                  availability:
                    start_at: '2030-01-01T00:00:00Z'
                  trial_period:
                    billing_cycles: 1
                    amount:
                      currency: CLP
                      value: 0
                  metadata:
                    - key: plan
                      value: gold
              PERCENT RULE:
                value:
                  refund_rule:
                    type: PERCENT
                    percent: 50
              FIXED RULE:
                value:
                  refund_rule:
                    type: FIXED
                    amount:
                      currency: COP
                      value: 8000
      responses:
        '201':
          description: '201'
          content:
            application/json:
              examples:
                CREATE SUBSCRIPTION:
                  value:
                    id: 0c7fed3e-ee0d-4d34-9547-778be4ec0798
                    name: Test Subscription
                    account_id: 493e9374-510a-4201-9e09-de669d75f256
                    country: US
                    description: Subscription Test
                    merchant_reference: subscription-ref-merchant-AA01
                    soft_descriptor: ACME SUBSCRIPTION
                    status: ACTIVE
                    amount:
                      currency: USD
                      value: 15000
                    frequency:
                      type: MONTH
                      value: 1
                    billing_cycles:
                      total: 12
                      current: 1
                      next_at: '2024-09-30T12:04:23.265393Z'
                    customer_payer:
                      id: a1d3b664-e32a-4508-9da1-9ede3e62a60c
                    payment_method:
                      type: CARD
                      vaulted_token: d4aa3586-def2-4705-b7cd-fe064bb764e6
                    availability:
                      start_at: '2024-09-30T12:04:23.265393Z'
                      finish_at: null
                    trial_period:
                      billing_cycles: 1
                      amount:
                        value: 0
                        currency: ''
                    metadata: null
                    created_at: '2024-09-30T12:04:23.265372Z'
                    updated_at: '2024-09-30T12:04:23.265372Z'
                    retries:
                      retry_on_decline: false
                      amount: 6
                      strategy: DEFAULT
                      schedule: null
                      stop_on_hard_decline: null
                      cancel_on_exhausted_retries: null
                    additional_data: null
                    initial_payment_validation: false
                    reason: null
                    subscription_agreement_id: null
                    renewal_notification_days: null
                    cancellation_time: null
                    cancellation_source: null
                    ending_time: null
                    pending_plan_change: null
                    current_period_start: '2026-10-23T00:00:00Z'
                    current_period_end: '2026-11-23T00:00:00Z'
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: 0c7fed3e-ee0d-4d34-9547-778be4ec0798
                  name:
                    type: string
                    example: Test Subscription
                  account_id:
                    type: string
                    example: 493e9374-510a-4201-9e09-de669d75f256
                  country:
                    type: string
                    example: US
                  description:
                    type: string
                    example: Subscription Test
                    nullable: true
                  merchant_reference:
                    type: string
                    example: subscription-ref-merchant-AA01
                  soft_descriptor:
                    type: string
                    example: ACME SUBSCRIPTION
                    nullable: true
                  status:
                    type: string
                    example: ACTIVE
                  amount:
                    type: object
                    properties:
                      currency:
                        type: string
                        example: USD
                      value:
                        type: number
                        example: 15000
                        default: 0
                  frequency:
                    type: object
                    properties:
                      type:
                        type: string
                        example: MONTH
                      value:
                        type: integer
                        example: 1
                        default: 0
                      monthly_billing_day:
                        type: integer
                        nullable: true
                        description: >-
                          在 MONTH 频率的订阅上，计费所锚定的每月日期。由
                          RESTART（在更新、计划变更、恢复或重新激活时）设置，或通过发送更新订阅自己的
                          frequency.monthly_billing_day
                          设置。只有在写入之后才会出现；在此之前以及在所有其他频率类型上，该字段不存在（而不是 null）。
                        example: 15
                  billing_cycles:
                    type: object
                    properties:
                      total:
                        type: integer
                        example: 12
                        default: 0
                        nullable: true
                      current:
                        type: integer
                        example: 1
                        default: 0
                      next_at:
                        type: string
                        example: '2024-09-30T12:04:23.265393Z'
                      scheduling_date:
                        type: string
                        description: >-
                          扣款指令交给 Pix 通道的时间，即 `next_at` 减去四天。仅出现在由 Yuno 执行的
                          `PIX_AUTOMATIC` 订阅上，并且仅在该组织启用了四天预约提前期时出现；否则该字段不存在（而不是
                          `null`）。只读。请参阅 [Pix
                          Automático](/zh-hans/docs/payment-features/subscriptions/pix-automatico#the-scheduling-date)。
                        example: '2026-11-27T00:00:00Z'
                      paid:
                        type: integer
                        description: 到目前为止已支付的周期数。与 `current` 不同，`current` 是正在计费的周期。
                  customer_payer:
                    type: object
                    properties:
                      id:
                        type: string
                        example: a1d3b664-e32a-4508-9da1-9ede3e62a60c
                      ip_address:
                        type: string
                        maxLength: 45
                        example: 203.0.113.7
                        description: >-
                          为续订保存的付款人 IP
                          地址。仅在单个订阅的响应（创建、检索、更新、暂停、恢复、重新激活和取消）中返回，并且仅在提供了该地址时返回；列表项和
                          webhook 中从不返回。
                  payment_method:
                    type: object
                    properties:
                      type:
                        type: string
                        example: CARD
                      vaulted_token:
                        type: string
                        example: d4aa3586-def2-4705-b7cd-fe064bb764e6
                      card:
                        type: object
                        properties:
                          installments:
                            type: integer
                            nullable: true
                          network_transaction_id:
                            type: string
                            nullable: true
                          usage:
                            type: string
                            example: FIRST
                        nullable: true
                  availability:
                    type: object
                    properties:
                      start_at:
                        type: string
                        example: '2024-09-30T12:04:23.265393Z'
                      finish_at: {}
                  trial_period:
                    type: object
                    properties:
                      billing_cycles:
                        type: integer
                        example: 1
                        default: 0
                      amount:
                        type: object
                        properties:
                          value:
                            type: number
                            example: 0
                            default: 0
                          currency:
                            type: string
                            example: ''
                  metadata: {}
                  plan_id:
                    type: string
                    description: 仅当订阅关联了计划时出现。
                  plan_assigned_at:
                    type: string
                    description: 仅出现在关联了计划的订阅上。计划被附加的时间，即从计划创建订阅时、迁移到计划时或计划变更时。
                  previous_subscription_id:
                    type: string
                    description: 仅当该订阅由计划变更（将现有订阅切换到另一个计划）创建时出现。
                  current_phase:
                    type: string
                    description: 仅出现在关联了计划的订阅上。
                  billing_phases:
                    type: array
                    description: >-
                      仅出现在其计划包含阶段的、关联了计划的订阅上。只包含前面的 TRIAL 阶段，在创建时生成快照；终止的
                      REGULAR 阶段从不包含在内，因为它的价格没有被固定，而是在每次计费时由计划确定。
                    items:
                      type: object
                      properties:
                        order:
                          type: integer
                        type:
                          type: string
                          description: 始终为 TRIAL，终止的 REGULAR 阶段从不出现在该数组中。
                        name:
                          type: string
                        amount:
                          type: object
                          properties:
                            currency:
                              type: string
                            value:
                              type: number
                        frequency:
                          type: object
                          properties:
                            type:
                              type: string
                            value:
                              type: integer
                        start_cycle:
                          type: integer
                        end_cycle:
                          type: integer
                  subscription_agreement_id:
                    type: string
                    example: sa_6af2dfcd-44c0-4f16-a331-8bed3ed9c9fa
                    nullable: true
                  created_at:
                    type: string
                    example: '2024-09-30T12:04:23.265372Z'
                  updated_at:
                    type: string
                    example: '2024-09-30T12:04:23.265372Z'
                  current_period_start:
                    type: string
                    nullable: true
                    description: >-
                      订阅当前所处计费周期的开始时间，比 `current_period_end`
                      早一个计费间隔。在试用期或任何其他计划阶段内，它遵循该阶段的计费间隔。处于终态的订阅（`CANCELED` 或
                      `COMPLETED`）保留其最后的时间窗口，而不会变为 null。仅对没有周期性计费间隔的订阅为 Null。始终与
                      current_period_end 一起返回。
                    example: '2023-01-16T20:00:00.912480Z'
                  current_period_end:
                    type: string
                    nullable: true
                    description: >-
                      订阅当前所处计费周期的结束时间。等于 billing_cycles.next_at。始终与
                      current_period_start 一起返回。
                    example: '2023-02-16T20:00:00.786342Z'
                  billing_date:
                    type: object
                    nullable: true
                    description: 仅出现在按固定日期（而不是按频率）计费的订阅上；与 `frequency` 互斥。
                    properties:
                      type:
                        type: string
                        example: DAY
                      day:
                        type: integer
                        example: 2
                  retries:
                    type: object
                    nullable: true
                    description: >-
                      定期扣款被拒绝时所采用的重试策略。请参阅[重试](/zh-hans/docs/payment-features/subscriptions/retries)。
                    properties:
                      retry_on_decline:
                        type: boolean
                        description: 被拒绝的扣款是否会重试。
                        example: true
                      amount:
                        type: integer
                        description: 一个计费周期可以重试的次数。上限为您所在环境的重试计划长度（生产环境为 6）。
                        example: 4
                      strategy:
                        type: string
                        description: >-
                          每次重试的时间如何确定：`DEFAULT`、`SMART` 或
                          `CUSTOM_SCHEDULE`。请将其视为开放式字段，并妥善处理无法识别的值。
                        example: DEFAULT
                      schedule:
                        type: array
                        nullable: true
                        description: >-
                          每次尝试的计划，仅当 `strategy` 为 `CUSTOM_SCHEDULE` 时设置；否则为
                          `null`。
                        items:
                          type: object
                      stop_on_hard_decline:
                        type: boolean
                        nullable: true
                        description: 为 true 时，硬拒绝会停止当前计费周期的重试。
                      cancel_on_exhausted_retries:
                        type: boolean
                        nullable: true
                        description: >-
                          为 true 时，一个周期的重试结束后仍没有支付成功，订阅就会被取消，同时
                          `cancellation_source` 设置为 `RETRIES_EXHAUSTED`。
                      profile:
                        type: string
                        description: >-
                          订阅遵循的固定重试阶梯，用来替代可配置的计划。始终为
                          `PIX_AUTOMATIC`。该字段和下面三个字段仅出现在由 Yuno 执行的
                          `PIX_AUTOMATIC` 订阅上；在所有其他支付方式上，它们不存在（而不是 `null`）。请参阅
                          [Pix
                          Automático](/zh-hans/docs/payment-features/subscriptions/pix-automatico#the-retry-ladder)。
                        example: PIX_AUTOMATIC
                      max_attempts:
                        type: integer
                        description: Pix 阶梯执行的重试次数。始终为 3，与这些订阅所报告的 `amount` 一致。
                        example: 3
                      min_gap_hours:
                        type: integer
                        description: >-
                          始终为
                          24，即阶梯各扣款日期（`D`、`D+1`、`D+2`、`D+3`）之间的间隔，而不是各发出尝试之间的间隔。
                        example: 24
                      until:
                        type: string
                        description: >-
                          阶梯停止的时间，即 `billing_cycles.next_at` 加 7 天。每次续订时随
                          `next_at` 一起变动。
                      stopped:
                        type: boolean
                        description: 仅当订阅处于 PAST_DUE 状态或有待处理的 cancel_scheduled 时出现。
                      attempts_made:
                        type: integer
                        description: 仅当订阅处于 PAST_DUE 状态或有待处理的 cancel_scheduled 时出现。
                      outcome:
                        type: string
                        description: >-
                          RECOVERED、EXHAUSTED 或 ABANDONED。仅当订阅处于 PAST_DUE
                          状态或有待处理的 cancel_scheduled 时出现。
                      next_retry_at:
                        type: string
                        description: 仅当订阅处于 PAST_DUE 状态或有待处理的 cancel_scheduled 时出现。
                  additional_data:
                    type: object
                    nullable: true
                    description: >-
                      创建时发送的可选订单补充数据，原样回显。完整结构请参阅[订阅对象](/zh-hans/reference/subscriptions/the-subscription-object)。
                  initial_payment_validation:
                    type: boolean
                    description: 订阅是否等待首次支付成功后才激活。默认为 `false`。
                    example: false
                  reason:
                    type: string
                    nullable: true
                    description: 订阅当前状态的自由格式原因（如果有记录）；否则为 `null`。
                    example: merchant request
                  renewal_notification_days:
                    type: integer
                    nullable: true
                    description: >-
                      在下一个计费日期之前多少天发送 `subscription.close_to_renewal`
                      webhook。`null` 表示不发送续订通知。
                    example: 3
                  payments:
                    type: array
                    items:
                      type: string
                      example: 5104911d-5df9-229e-8468-bd41abea1a4s
                  cancellation_time:
                    type: string
                    nullable: true
                    description: 订阅被取消的时间。仅在订阅达到 `CANCELED` 后设置；否则为 `null`。
                    example: '2023-12-16T20:46:54.786342Z'
                  cancellation_source:
                    type: string
                    nullable: true
                    description: >-
                      触发取消的原因：`MERCHANT`、`SYSTEM`、`PLAN_CHANGE` 或
                      `RETRIES_EXHAUSTED`。仅在订阅达到 `CANCELED` 后设置；否则为
                      `null`。请将其视为开放式字段，并妥善处理无法识别的值。
                    example: MERCHANT
                  ending_time:
                    type: string
                    nullable: true
                    description: 订阅完成或过期的时间。仅在订阅达到 `COMPLETED` 后设置；否则为 `null`。
                    example: '2024-12-16T20:46:54.786342Z'
                  phases:
                    type: array
                    description: >-
                      所关联计划的阶段定义，与计划声明的一致，包括终止的 `REGULAR`
                      阶段。仅出现在其计划包含阶段的、关联了计划的订阅上。这是计划自己的阶梯，而不是该订阅者的快照：要查看创建时为该订阅固定下来的内容，请使用
                      `billing_phases`。
                    items:
                      type: object
                      properties:
                        order:
                          type: integer
                        name:
                          type: string
                        type:
                          type: string
                          description: '`TRIAL` 或 `REGULAR`。'
                        duration:
                          type: object
                          nullable: true
                          description: 阶段持续多长时间。在终止的 `REGULAR` 阶段上为 `null`，该阶段一直持续到订阅结束。
                          properties:
                            type:
                              type: string
                            value:
                              type: integer
                        frequency:
                          type: object
                          nullable: true
                          description: 阶段的计费频率。在终止的 `REGULAR` 阶段上为 `null`，该阶段按计划自身的频率计费。
                          properties:
                            type:
                              type: string
                            value:
                              type: integer
                        amount:
                          type: object
                          nullable: true
                          description: 阶段价格。在终止的 `REGULAR` 阶段上为 `null`，其价格在每次计费时由计划确定。
                          properties:
                            currency:
                              type: string
                            value:
                              type: number
                        total_payments:
                          type: integer
                          nullable: true
                        country_prices:
                          type: array
                          description: 按国家/地区覆盖的阶段价格，阶段没有覆盖时为空。
                          items:
                            type: object
                            properties:
                              country:
                                type: string
                              amount:
                                type: object
                                properties:
                                  currency:
                                    type: string
                                  value:
                                    type: number
                  current_phase_end:
                    type: string
                    nullable: true
                    description: >-
                      由 `current_phase`
                      指定的阶段移交给下一个阶段的时间，对于处于试用期的订阅，即切换到常规价格的时间。它是该阶段所涵盖的最后一个计费周期的结束时间，因此在试用期的最后一个周期，它等于
                      `current_period_end`。对于没有计划的订阅以及已离开阶段阶梯的订阅，为 Null。
                    example: '2023-03-16T20:00:00.786342Z'
                  pending_plan_change:
                    type: object
                    nullable: true
                    description: >-
                      计划在下一个计费周期生效的变更，没有待处理的变更时为 null。使用更新订阅上的 `plan_change`
                      块可以预定一个变更。
                    properties:
                      plan_id:
                        type: string
                        description: 目标计划的标识符。
                        example: 1904911d-5df9-429e-8488-ad41abea1a4d
                      plan_name:
                        type: string
                        description: 目标计划的名称。
                        example: Pro
                      direction:
                        type: string
                        enum:
                          - UPGRADE
                          - DOWNGRADE
                        description: 目标计划是升级还是降级。仅供参考。
                        example: UPGRADE
                      effective:
                        type: string
                        enum:
                          - NEXT_BILLING_CYCLE
                        description: 变更生效的时间。
                        example: NEXT_BILLING_CYCLE
                      phases_behavior:
                        type: string
                        enum:
                          - START_FROM_REGULAR
                          - HONOR_PHASES
                        description: 目标计划包含阶段时会发生什么。
                        example: START_FROM_REGULAR
                      applies_at:
                        type: string
                        description: 变更将在其上生效的计费事件，即订阅的下一个计费日期。
                        example: '2023-02-16T20:00:00.786342Z'
                      requested_at:
                        type: string
                        description: 变更被预定的时间。
                        example: '2023-01-20T10:12:31.786342Z'
                  refund_rule:
                    type: object
                    description: >-
                      已存储的退款规则，当取消请求没有自带 refund_amount 时，用它来确定 CUSTOM
                      取消的退款。仅在配置了规则时出现；否则该字段被省略（而不是 null）。适用于已启用该功能的组织；请联系 Yuno。
                    properties:
                      type:
                        type: string
                        enum:
                          - PERCENT
                          - FIXED
                        description: PERCENT 将退款确定为已扣款金额的百分比；FIXED 将其确定为固定金额。
                        example: FIXED
                      percent:
                        type: number
                        description: 当 type 为 PERCENT 时必填，且仅在此时允许（0-100）。
                        example: 50
                      amount:
                        type: object
                        description: 当 type 为 FIXED 时必填，且仅在此时允许。
                        properties:
                          value:
                            type: number
                            example: 10000
                          currency:
                            type: string
                            description: 必须与订阅自身的币种一致。
                            example: COP
                  pause_until:
                    type: string
                    description: >-
                      订阅预定自动恢复的时间。仅出现在当前带有时长（暂停时发送了 pause_cycles 或
                      pause_until）而处于暂停状态的订阅上；在所有其他读取中，该字段不存在（而不是 null）。
                    example: '2026-10-15T15:54:22.780166Z'
                  cancel_scheduled:
                    type:
                      - object
                      - 'null'
                    description: 没有待处理的取消时为 null。
                    properties:
                      mode:
                        type: string
                        example: AFTER_CYCLES
                      after_cycles:
                        type: integer
                        example: 3
                      at:
                        type: string
                      requested_at:
                        type: string
                      past_due_behavior:
                        type: string
                        example: EXHAUST_RETRIES
                  refund:
                    type:
                      - object
                      - 'null'
                    description: 当 refund 为 NONE 或被省略时为 null。出现在取消响应中，计算完成后的每次后续读取中也会出现。
                    properties:
                      mode:
                        type: string
                        example: PRORATED
                      amount:
                        type: object
                        properties:
                          currency:
                            type: string
                            example: USD
                          value:
                            type: number
                            example: 20
                      unused_days:
                        type: integer
                        example: 20
                      period_days:
                        type: integer
                        example: 30
                      basis:
                        type: object
                        properties:
                          billing_cycle:
                            type: integer
                            example: 4
                          charged_amount:
                            type: object
                            properties:
                              currency:
                                type: string
                                example: USD
                              value:
                                type: number
                                example: 30
                          payment_id:
                            type: string
                            description: 对于没有已捕获支付的 $0 阶段报价，为 null。
                          charged_at:
                            type: string
                            description: 对于没有已捕获支付的 $0 阶段报价，为 null。
                      execution:
                        type: string
                        example: MERCHANT
                      quoted_at:
                        type: string
                  unpaid_cycle:
                    type: object
                    description: 仅当当前计费周期处于 PAST_DUE 状态且尚未结清时出现。
                    properties:
                      cycle_number:
                        type: integer
                      amount:
                        type: object
                        properties:
                          currency:
                            type: string
                          value:
                            type: number
                      attempts:
                        type: integer
                      last_failure_code:
                        type: string
        '400':
          description: '400'
          content:
            application/json:
              examples:
                Result:
                  value:
                    code: INVALID_REQUEST
                    messages:
                      - Invalid request.
                  summary: Result
                PIX AUTOMATICO CADENCE NOT SUPPORTED:
                  value:
                    code: INVALID_PARAMETERS
                    messages:
                      - >-
                        Pix Automático only supports weekly, monthly, quarterly,
                        half-yearly or yearly frequencies with value 1.
                INLINE YEAR WITHOUT A PLAN:
                  value:
                    code: BAD_REQUEST
                    messages:
                      - YEAR is invalid for frequency.type field
                PLAN NOT FOUND:
                  value:
                    code: PLAN_NOT_FOUND
                    messages:
                      - Plan not found.
                  summary: The plan_id does not resolve to a plan on this account.
                REFUND RULE CURRENCY MISMATCH:
                  value:
                    code: REFUND_RULE_CURRENCY_MISMATCH
                    messages:
                      - >-
                        refund_rule.amount.currency USD must match the
                        subscription currency COP.
                  summary: >-
                    A FIXED refund_rule must be denominated in the
                    subscription's own currency.
                REFUND RULE PERCENT OUT OF RANGE:
                  value:
                    code: BAD_REQUEST
                    messages:
                      - refund_rule.percent must be between 0 and 100.
                  summary: >-
                    Same refund_rule validator as Update Subscription (captured
                    there, row 154); the message text is shared.
      deprecated: false
components:
  securitySchemes:
    sec0:
      type: apiKey
      in: header
      name: public-api-key
      x-default: <Your public-api-key>
    sec1:
      type: apiKey
      in: header
      name: private-secret-key
      x-default: <Your private-secret-key>

````

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