调至内容部分
创建账户
或
登录
Stripe 文档徽标
/
询问人工智能
创建账户
登录
开始
付款
销售收入
平台和交易市场
资金管理
开发人员资源
概览
Billing
概览关于 Billing API
订阅
    概览
    订阅的运作机制
    开始
    快速开始
    规划集成
    构建集成
    用例
    关于订阅
    启用开单模式
    订阅事件定义
    资格
    订阅账单
    订阅计划
    经常性定价模型
    强客户认证 (SCA)
    设置订阅
    配置收取方法
    嵌入价格表
    设置数量
    设置计费周期
    管理订阅
    将订阅迁移到 Stripe
    订阅多个项目
    回溯订阅
    设置试用期
    处理延期付款的订阅
    使用优惠券
    修改订阅
      更改价格
      取消订阅
      暂停收款
      管理分摊
      管理新的更新
    管理订阅支付方式
    分析
开账单
基于用量的计费
报价
客户管理
用其他产品计费
收入恢复
自动化
测试您的集成
税务
概览
使用 Stripe Tax
管理合规
报告
概览
选择报告
配置报告
Reports API
多账户报告
收入确认
数据
概览模式
自定义报告
Data Pipeline
数据管理
首页销售收入SubscriptionsModify subscriptions

Pending updates

Learn how to handle payment failures when updating subscriptions.

Updating a subscription generates a new invoice when:

  • The subscription requires payment for the first time, such as the end of a trial period.
  • The billing period changes.
  • Changing the subscription causes a proration and proration_behavior=always_invoice.

By default, Stripe applies updates regardless of whether payment on the new invoice succeeds. If payment fails, rolling back the updates is a manual process. You need to create a new invoice, prorate items on the invoice, and then initiate payment again. However, with the pending updates feature, you can make changes to subscriptions only if payment succeeds on the new invoice.

开始前

You can use pending updates if the subscription’s collection_method is charge_automatically or when the subscription’s payment method is either a card or Link.

Update the subscription
Server-side

You can use pending updates with the update subscription, create subscription item, and update subscription item calls. When you make the update, set payment_behavior=pending_if_incomplete. The example below adds a new price to a subscription. Because proration_behavior=always_invoice, an invoice is created and payment is attempted when the update is made.

Command Line
curl
Ruby
Python
PHP
Java
Node
Go
.NET
No results
curl https://api.stripe.com/v1/subscriptions/sub_49ty4767H20z6a \ -u
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:
\ -d "payment_behavior"="pending_if_incomplete" \ -d "proration_behavior"="always_invoice" \ -d "items[0][id]"="si_09IkI4u3ZypJUk5onGUZpe8O" \ -d "items[0][price]"="price_CBb6IXqvTLXp3f"

If payment succeeds, the subscription is updated. If payment fails, the Subscription object that’s returned contains a pending_update hash with the changes:

{ "id": "sub_49ty4767H20z6a", "object": "subscription", "application_fee_percent": null, "pending_update": { "expires_at": 1571194285, "subscription_items": [ { "id": "si_09IkI4u3ZypJUk5onGUZpe8O", "price": "price_CBb6IXqvTLXp3f" } ] }, }

Handle failed payments
Client-side

After making the update, check the pending_update hash on the subscription or listen for the customer.subscription.updated event in your webhook. A populated pending_update hash means the payment failed and your subscription update isn’t applied.

Build logic to handle payment failures due to card declines and customer authentication requests:

  • For card declines, attach a new payment method to the customer. Then use the pay endpoint to pay the invoice that the update generates.
  • For customer authentication, follow the requires action flow.

A successful payment immediately applies the changes in the pending_update hash and updates the invoice to paid.

If payment fails again, the pending_update hash remains on the subscription with the original expiry date and no changes are applied.

可选Cancel or change pending updates
Server-side

Supported attributes for pending updates

Pending updates only support attributes that control proration behavior or generate new invoices.

The update subscription endpoint supports the following attributes:

  • expand
  • payment_behavior
  • proration_behavior
  • proration_date
  • billing_cycle_anchor
  • items
    • price
    • quantity
  • trial_end
  • trial_from_plan
  • add_invoice_items

The create subscription item and update subscription item endpoints support the following attributes:

  • expand
  • payment_behavior
  • proration_behavior
  • proration_date
  • price
  • quantity

Expired updates

If you don’t take any action after an update fails, Stripe voids the invoice and discards the update after it expires.

A pending update’s expired_at time matches the first occurrence of either the trial end or the earliest items.current period end. This applies if either time is within 23 hours of the update request. Otherwise, the expiration is 23 hours from the update request.

Stripe also automatically voids the invoice and removes the pending update if any of the following occurs:

  • The subscription reaches a billing threshold.
  • A subscription schedule linked to the subscription transitions to a new phase.

Pending updates events

Use webhooks to listen for the following events related to pending updates:

EventPurpose
customer.subscription.updatedReceive notifications for subscriptions, checking for the pending_updates hash and resolving payment failures if needed.
customer.subscription.pending_update_appliedReceive notifications when pending updates are applied so that you can take further actions like upgrading, downgrading, provisioning, or deprovisioning services.
customer.subscription.pending_update_expiredReceive notifications when pending updates expire or are automatically voided, and if needed, try the update request again.

Pending updates and subscription schedules

You can use both pending updates and subscription schedules to manage subscriptions. A schedule phase change discards a pending update and voids the associated invoice. Retry the update request after the phase transition if needed.

Metered items

If a subscription includes metered items, Stripe bills any outstanding usage on the pending update invoice. However, if the pending update expires before payment, Stripe discards this usage, which prevents any subsequent invoices from billing for them.

If the pending update removes a metered price, Stripe disregards any usage reported between the pending update’s creation and the resulting invoice payment. You can’t bill for that usage. However, if billing_mode=flexible is on the subscription, Stripe bills for usage when removing a metered price.

此页面的内容有帮助吗?
是否
  • 需要帮助?联系支持。
  • 加入我们的早期使用计划。
  • 查看我们的更改日志。
  • 有问题?联系销售。
  • LLM? Read llms.txt.
  • Powered by Markdoc