> ## 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 时不会产生收费，也不会按比例计费或退款。
> 订阅继续按现有时间表计费；新计划的价格从
> 下一个续订日期起适用。

## 两种行为，一个 endpoint

具体采用哪种行为取决于订阅是否已关联计划。

| 订阅 | 结果 | 响应中的 `id` |
| - | - | - |
| 未关联计划 | 原地附加到该计划 | 不变 |
| 已关联计划 | 被取消，并由目标计划上的新订阅替代 | **新的**：旧 `id` 位于 `previous_subscription_id` 中 |

在替代的情况下，原订阅最终处于 `CANCELED` 状态，
`cancellation_source` 为 `PLAN_CHANGE`，替代订阅继承原订阅
剩余的计费周期及其下一个续订日期：替代订阅的 `availability.start_at` 和
`billing_cycles.next_at` 都等于原订阅的 `next_at`，其
`billing_cycles.current` 从 `1` 重新开始。如果该续订日期已经过去（例如
长期暂停的订阅），替代订阅会改为在大约一分钟后开始，
并立即计费。

> [!NOTE]
>
> **计划变更时的促销**
>
> 对于已关联计划的订阅，原订阅的促销会结束，`end_reason` 为 `CANCELED`，并且不会转移到替代订阅。替代订阅会获得新计划的 `AUTOMATIC` 促销（如果该计划有）。未关联计划的订阅会如上表所示原地附加：不会替代或取消任何内容，也不会添加自动促销。如需保留已关联计划的订阅的当前促销，请改用 `promotion_behavior` 设为 `KEEP` 的计划变更。请参阅[更新订阅](https://docs.y.uno/zh-hans/reference/subscriptions/update-subscription.md)和[订阅计划促销](https://docs.y.uno/zh-hans/docs/payment-features/subscriptions/promotions.md#plan-changes)。

> [!WARNING]
>
> **在计划到计划的变更后存储返回的 `id`**
>
> 替代订阅是另一个不同的订阅。如果您继续使用旧的 `id`，后续调用将
> 作用于已取消的订阅。

## Webhooks

计划到计划的变更会发出三个事件：

* 针对替代订阅的 `subscription.create`。
* 针对原订阅的 `subscription.cancel`，带有 `cancellation_source: PLAN_CHANGE`。请勿
  将其计为流失。
* 针对替代订阅的 `subscription.plan_changed`，并设置了 `previous_subscription_id`。

附加的情况不会发出上述任何事件。它唯一的 webhook 是状态变更，并且仅在
计划的阶梯在本次调用中将订阅提升为 `TRIALING` 时发出。

## 跳过目标计划的试用

如果目标计划定义了试用或引导阶段，订阅默认会采用整个阶梯，
这意味着订阅者可以在试用中途更改计划并获得一次新的试用。

将 `skip_trial` 设为 `true` 可防止这种情况。替代订阅从第一次收费起就按目标计划的常规
价格计费，其状态保持 `ACTIVE`，而不会变为 `TRIALING`。

```json Change plan without granting a new trial theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
{
  "plan_id": "1904911d-5df9-429e-8488-ad41abea1a4d",
  "skip_trial": true
}
```

`skip_trial` 默认为 `false`，且仅适用于计划到计划的变更。对未关联计划的订阅发送
`skip_trial: true` 会返回 `400`；`false` 与
省略该标志等效，在任何情况下都会被接受。对于没有阶段的计划，它不会产生
任何影响。

> [!NOTE]
>
> **`phases` 仍然描述计划**
>
> 使用 `skip_trial: true` 时，响应中仍会列出目标计划的 `phases`：该数组
> 描述的是 *计划*，而不是此订阅将被如何计费。订阅层级的
> 信号是 `status`（保持 `ACTIVE`，而不会变为 `TRIALING`），以及 `current_phase` 和 `billing_phases` 的
> **缺失**：这两个键会从响应中省略，而不是
> 作为 `null` 返回，因此请检测其是否缺失，而不是检测 `null`。默认的变更会返回这两个
> 已填充的字段。

## 改为保留相同的 `id`

[更新订阅](https://docs.y.uno/zh-hans/reference/subscriptions/update-subscription.md) 中的 `plan_change` 对象
会 **原地** 更改订阅的计划：`id` 永远不变，不会取消任何内容，
也不会触发 `subscription.cancel` webhook。两种机制都不会立即收费，并且无论哪种方式
都不会按比例计费或退款。它们的区别在于订阅记录会发生什么：

| | 记录 | 下一次收费 |
| - | - | - |
| 此 endpoint，计划到计划 | 新的 `id`；原订阅保持 `CANCELED` | 原订阅的下一次续订，按新计划的价格 |
| 带有 `effective: NEXT_BILLING_CYCLE` 的 `plan_change` | 续订前保持不变，`id` 相同 | 下一次续订，按新计划的价格 |
| 带有 `effective: IMMEDIATE` 的 `plan_change` | 在本次调用中转移到新计划，`id` 相同 | `billing_cycle_behavior: KEEP`（默认值）保留下一次收费日期；`RESTART` 将其重新锚定为当前时刻加上新计划的频率 |

如果您要为已关联计划的订阅更改计划并希望保留其 `id`，
请优先使用带有 `effective: IMMEDIATE` 的 `plan_change`，而不是此 endpoint。

`plan_change` 并不是通用的替代方案：它要求订阅已关联
计划，并且处于 `ACTIVE` 或 `TRIALING` 状态。为没有计划的订阅附加计划，或者
从 `CREATED` 或 `PAUSED` 状态更改计划，只能通过此 endpoint 完成。

出于向后兼容的原因，两者的试用默认行为不同：

| | 默认行为 |
| - | - |
| 此 endpoint | 采用目标计划的阶段（`skip_trial: false`） |
| 更新订阅中的 `plan_change` | 跳过这些阶段（`phases_behavior: "START_FROM_REGULAR"`） |

只要试用行为对您很重要，请显式设置 `skip_trial` 或 `phases_behavior`。

## 重复调用

当订阅处于可接受的状态时，重新提交其 **当前** 计划是一个
幂等的空操作，会返回 `200` 且订阅保持不变，包括您
只更改 `skip_trial` 的情况，以及该计划此后已被取消的情况。

计划到计划的变更不能在同一个 `subscription_id` 上重复执行。一旦成功，
原订阅即处于 `CANCELED` 状态，因此向该 `id` 重新提交会返回 `400` `INVALID_STATE`
（`The subscription status CANCELED does not support plan changes.`），而不是重放
第一次的结果。请将该错误视为变更已经生效的确认，并将任何
后续调用指向替代订阅的 `id`。

如果调用超时，请使用 `GET /v1/subscriptions/{subscription_id}` 进行核对，而不是
盲目重试：变更生效后，原订阅会携带 `cancellation_source: PLAN_CHANGE`，
替代订阅则是 `previous_subscription_id` 等于该
`id` 的订阅。在原订阅仍可更改时发送的进行中重试是安全的：只要 `skip_trial` 不变，
该重试就会被去重。不同的 `skip_trial` 值属于
不同的操作。

## 要求

订阅不能处于 `CANCELED` 或 `COMPLETED` 状态，这两种状态会返回 `400` `INVALID_STATE`
（`The subscription status <STATUS> does not support plan changes.`）。此 endpoint 接受
`CREATED` 和 `PAUSED` 状态的订阅，而更新订阅中的 `plan_change` 对象
不接受。

两种情况都要求计划处于 `ACTIVE` 状态并属于该订阅的账户，并且
对于以 `frequency.execution: MERCHANT` 计费的订阅，两者均不可用。

**为没有计划的订阅附加计划** 还要求计划的计费节奏
与订阅的一致，并且解析得到的价格使用订阅的币种。
订阅不能处于试用期，不能已有计费阶段，不能使用
`billing_date`，也不能使用 `VARIABLE` 金额。

订阅从其下一个未计费的周期开始采用目标计划的阶段阶梯，并且该
阶梯必须能容纳在订阅剩余的计费周期之内。如果阶梯以覆盖当前进行中周期的
`TRIAL` 阶段开始，`ACTIVE` 订阅会在本次调用中变为 `TRIALING`；
`CREATED` 和 `PAUSED` 订阅不会以这种方式被提升。`skip_trial` 无法
阻止这种情况，因为它是仅适用于计划到计划变更的标志。

**从一个计划更改为另一个计划** 还要求订阅至少
剩余一个计费周期，并且其可用时间窗口不会在下一次续订之前结束。
如果目标计划限制了 `allowed_payment_methods`，则必须接受该订阅的支付方式类型，
并且订阅必须有一个已存储的支付方式。
目标计划的计费节奏和价格按该计划上的定义适用。

如果订阅有一个待处理的预定变更，本次调用会将其丢弃，且不会发出
`subscription.plan_change_canceled` webhook；替代订阅以
`pending_plan_change: null` 开始。

## 错误

| HTTP | `code` | 触发条件 |
| - | - | - |
| `404` | `PLAN_NOT_FOUND` | 目标计划不存在，或未关联到此账户。 |
| `400` | `INVALID_STATE` | 订阅的状态不支持计划变更；目标计划未处于有效状态；或可用时间窗口在下一次续订之前结束。 |
| `400` | `BAD_REQUEST` | 对未关联计划的订阅发送了 `skip_trial: true`；没有剩余的计费周期；订阅以 `frequency.execution: MERCHANT` 计费。 |
| `400` | `INCORRECT_PAYMENT_METHOD_TYPE` | 目标计划限制了 `allowed_payment_methods`，而订阅的支付方式类型不在列表中。 |
| `400` | `INVALID_PARAMETERS` | 订阅为 `PIX_AUTOMATIC`，而目标计划定义了自己的重试；Pix Automático 保持 Pix 通道的固定重试。 |
| `400` | `PAYMENT_METHOD_NOT_FOUND` | 订阅没有已存储的支付方式。 |

在此处重新提交订阅的当前计划是返回 `200` 的空操作。通过
[更新订阅](https://docs.y.uno/zh-hans/reference/subscriptions/update-subscription.md) 中的 `plan_change` 对象表达相同意图
则会被驳回，返回 `422` `SAME_PLAN`。


## OpenAPI

````yaml openapi/zh-hans/subscriptions/change-subscription-plan.json POST /subscriptions/{subscription_id}/plan
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/{subscription_id}/plan:
    post:
      summary: 更改订阅计划
      description: >-
        将订阅转移到某个订阅计划上。


        如果订阅还不在任何计划上，它会就地附加到计划，并保留其
        `id`。如果它已经在某个计划上，它会被取消，并由目标计划上的**新**订阅替代；响应返回的是替代订阅，其
        `previous_subscription_id` 指向被替代的订阅。


        在这两种情况下，变更都在订阅的**下一次续订**时生效：现在不会产生扣款，也不会按比例计费或退款。
      operationId: change-subscription-plan
      parameters:
        - name: subscription_id
          in: path
          description: 订阅的唯一标识符。
          schema:
            type: string
            format: uuid
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - plan_id
              properties:
                plan_id:
                  type: string
                  format: uuid
                  description: 要将订阅转移到的计划的唯一标识符。
                  examples:
                    - 1904911d-5df9-429e-8488-ad41abea1a4d
                skip_trial:
                  type: boolean
                  default: false
                  description: >-
                    仅适用于计划之间的变更。为 `true`
                    时，替代订阅不会沿用目标计划的试用阶段或入门阶段：它从第一次扣款起就按该计划的常规价格计费，状态保持为
                    `ACTIVE`，而不是变为
                    `TRIALING`。使用它可以防止订阅者通过切换计划重复获得试用。在不在任何计划上的订阅上发送 `true` 会返回
                    `400`；`false` 和省略该标志等效，并且始终被接受。
                  examples:
                    - true
      responses:
        '200':
          description: '200'
          content:
            application/json:
              examples:
                Default (adopts the target plan's trial):
                  value:
                    id: 8f11a2b0-6c1d-4a77-9f3e-2b5c8d0e91aa
                    name: sub_001
                    account_id: 2404911d-5df9-429e-8488-ad41abea1a4b
                    country: US
                    description: streaming service
                    merchant_reference: 001_marzo_23
                    status: TRIALING
                    amount:
                      currency: USD
                      value: 12100
                    frequency:
                      type: MONTH
                      value: 1
                    billing_cycles:
                      total: 8
                      current: 1
                      next_at: '2024-01-16T20:46:54.786342Z'
                    customer_payer:
                      id: 3t04911d-5df9-429e-8488-ad41abea1a2c
                    payment_method:
                      type: CARD
                      vaulted_token: 6104911d-5df9-429e-8488-ad41abea1a4b
                      card:
                        installments: null
                        network_transaction_id: null
                        usage: FIRST
                    availability:
                      start_at: '2024-01-16T20:46:54.786342Z'
                      finish_at: null
                    retries:
                      retry_on_decline: false
                      amount: 6
                      strategy: DEFAULT
                      schedule: null
                      stop_on_hard_decline: null
                      cancel_on_exhausted_retries: null
                    metadata:
                      - key: sub_ext_id
                        value: AA001
                    additional_data: null
                    trial_period: null
                    initial_payment_validation: false
                    reason: null
                    subscription_agreement_id: null
                    soft_descriptor: null
                    renewal_notification_days: null
                    cancellation_time: null
                    cancellation_source: null
                    ending_time: null
                    created_at: '2023-12-16T20:46:54.786342Z'
                    updated_at: '2023-12-16T20:46:54.786342Z'
                    plan_id: 1904911d-5df9-429e-8488-ad41abea1a4d
                    plan_assigned_at: '2023-12-16T20:46:54.786342Z'
                    previous_subscription_id: 7304911d-5df9-429e-8488-ad41abea1a4c
                    phases:
                      - order: 1
                        name: Intro
                        type: TRIAL
                        duration:
                          type: MONTH
                          value: 2
                        frequency:
                          type: MONTH
                          value: 1
                        amount:
                          value: 5000
                          currency: USD
                        total_payments: 2
                        country_prices: []
                      - order: 2
                        name: Regular
                        type: REGULAR
                        duration: null
                        frequency: null
                        amount: null
                        total_payments: null
                        country_prices: []
                    current_phase: TRIAL
                    billing_phases:
                      - order: 1
                        type: TRIAL
                        name: Intro
                        amount:
                          value: 5000
                          currency: USD
                        frequency:
                          type: MONTH
                          value: 1
                        start_cycle: 1
                        end_cycle: 2
                    pending_plan_change: null
                'skip_trial: true':
                  value:
                    id: 9c2d4e6f-1a3b-4c5d-8e7f-0a1b2c3d4e5f
                    name: sub_001
                    account_id: 2404911d-5df9-429e-8488-ad41abea1a4b
                    country: US
                    description: streaming service
                    merchant_reference: 001_marzo_23
                    status: ACTIVE
                    amount:
                      currency: USD
                      value: 12100
                    frequency:
                      type: MONTH
                      value: 1
                    billing_cycles:
                      total: 8
                      current: 1
                      next_at: '2024-01-16T20:46:54.786342Z'
                    customer_payer:
                      id: 3t04911d-5df9-429e-8488-ad41abea1a2c
                    payment_method:
                      type: CARD
                      vaulted_token: 6104911d-5df9-429e-8488-ad41abea1a4b
                      card:
                        installments: null
                        network_transaction_id: null
                        usage: FIRST
                    availability:
                      start_at: '2024-01-16T20:46:54.786342Z'
                      finish_at: null
                    retries:
                      retry_on_decline: false
                      amount: 6
                      strategy: DEFAULT
                      schedule: null
                      stop_on_hard_decline: null
                      cancel_on_exhausted_retries: null
                    metadata:
                      - key: sub_ext_id
                        value: AA001
                    additional_data: null
                    trial_period: null
                    initial_payment_validation: false
                    reason: null
                    subscription_agreement_id: null
                    soft_descriptor: null
                    renewal_notification_days: null
                    cancellation_time: null
                    cancellation_source: null
                    ending_time: null
                    created_at: '2023-12-16T20:46:54.786342Z'
                    updated_at: '2023-12-16T20:46:54.786342Z'
                    plan_id: 1904911d-5df9-429e-8488-ad41abea1a4d
                    plan_assigned_at: '2023-12-16T20:46:54.786342Z'
                    previous_subscription_id: 7304911d-5df9-429e-8488-ad41abea1a4c
                    phases:
                      - order: 1
                        name: Intro
                        type: TRIAL
                        duration:
                          type: MONTH
                          value: 2
                        frequency:
                          type: MONTH
                          value: 1
                        amount:
                          value: 5000
                          currency: USD
                        total_payments: 2
                        country_prices: []
                      - order: 2
                        name: Regular
                        type: REGULAR
                        duration: null
                        frequency: null
                        amount: null
                        total_payments: null
                        country_prices: []
                    pending_plan_change: null
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: 7304911d-5df9-429e-8488-ad41abea1a4c
                  name:
                    type: string
                    example: sub_001
                  description:
                    type: string
                    example: streaming service
                    nullable: true
                  account_id:
                    type: string
                    example: 2404911d-5df9-429e-8488-ad41abea1a4b
                  country:
                    type: string
                    description: 订阅所在国家/地区（ISO 3166-1 alpha-2）。
                    example: US
                  merchant_reference:
                    type: string
                    example: 001_marzo_23
                  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: 12100
                        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: 10
                        default: 0
                        nullable: true
                      current:
                        type: integer
                        example: 2
                        default: 0
                      next_at:
                        type: string
                        example: '2023-02-16T20:00:00.786342Z'
                      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` 是正在计费的周期。
                  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
                  customer_payer:
                    type: object
                    properties:
                      id:
                        type: string
                        example: 3t04911d-5df9-429e-8488-ad41abea1a2c
                  payment_method:
                    type: object
                    properties:
                      type:
                        type: string
                        example: CARD
                      vaulted_token:
                        type: string
                        example: 6104911d-5df9-429e-8488-ad41abea1a4b
                      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-01-16T00:00:00.786342Z'
                      finish_at:
                        type: string
                        example: '2024-05-26T20:00:00.786342Z'
                        nullable: true
                  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 时出现。
                  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: ''
                    nullable: true
                  metadata:
                    type: array
                    items:
                      type: object
                      properties:
                        key:
                          type: string
                          example: sub_ext_id
                        value:
                          type: string
                          example: AA001
                    nullable: true
                  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
                  subscription_agreement_id:
                    type: string
                    example: sa_6af2dfcd-44c0-4f16-a331-8bed3ed9c9fa
                    nullable: true
                  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'
                  plan_id:
                    type: string
                    description: 仅当订阅关联了计划时出现。
                    example: 00000000-0000-4000-8000-000000000001
                  plan_assigned_at:
                    type: string
                    description: 仅出现在关联了计划的订阅上。计划被附加的时间，即从计划创建订阅时、迁移到计划时或计划变更时。
                    example: '2023-12-16T20:46:54.786342Z'
                  previous_subscription_id:
                    type: string
                    description: 仅当该订阅由计划变更（将现有订阅切换到另一个计划）创建时出现。
                    nullable: true
                  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:
                    type: string
                    description: 仅出现在关联了计划的订阅上。
                    example: REGULAR
                  current_phase_end:
                    type: string
                    nullable: true
                    description: >-
                      由 `current_phase`
                      指定的阶段移交给下一个阶段的时间，对于处于试用期的订阅，即切换到常规价格的时间。它是该阶段所涵盖的最后一个计费周期的结束时间，因此在试用期的最后一个周期，它等于
                      `current_period_end`。对于没有计划的订阅以及已离开阶段阶梯的订阅，为 Null。
                    example: '2023-03-16T20:00:00.786342Z'
                  billing_phases:
                    type: array
                    description: >-
                      仅出现在其计划包含阶段的、关联了计划的订阅上。只包含前面的 TRIAL 阶段，在创建时生成快照；终止的
                      REGULAR 阶段从不包含在内，因为它的价格没有被固定，而是在每次计费时由计划确定。`current_phase:
                      "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
                  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'
                  created_at:
                    type: string
                    example: '2023-12-16T20:46:54.786342Z'
                  updated_at:
                    type: string
                    example: '2023-12-16T21:00:54.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_STATE
                    messages:
                      - >-
                        The subscription status <STATUS> does not support plan
                        changes.
                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.
                SUBSCRIPTION NOT FOUND:
                  value:
                    code: SUBSCRIPTION_NOT_FOUND
                    messages:
                      - Subscription not found.
                  summary: >-
                    No subscription resolves for the subscription_id on this
                    account. Returned as 400, not 404.
        '404':
          description: '404'
          content:
            application/json:
              examples:
                Result:
                  value:
                    code: PLAN_NOT_FOUND
                    messages:
                      - >-
                        The target plan does not exist or is not linked to this
                        account.
      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.