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, updates are applied 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.
Caution
Pending updates aren’t supported when the subscription’s collection_method is send_
or when bank debits are used as the payment method for the subscription.
Update the subscriptionServer-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_
. The example below adds a new price to a subscription. Because proration_
, an invoice is created and payment is attempted when the update is made.
If payment succeeds, the subscription is updated. If payment fails, the Subscription
object that’s returned contains a pending_
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" } ] }, }
Handling failed paymentsClient-side
After making the update, check the pending_
hash on the subscription. If you want to be notified automatically, you can build a webhook that listens for the customer.
event. If the pending_
hash is populated, the payment failed and the subscription will continue to cycle as if no update request was made.
Payments often fail because the payment method is declined or because they require customer authentication. You should build logic to handle both of these scenarios.
Use the instructions for payment failures to handle card declines. You need to attach a new payment method to the customer and then use the pay endpoint to pay the invoice that the update generates.
Use the customer action instructions to handle customer authentication. This walks the user through the authentication process and then pays the invoice.
A successful payment:
- Immediately applies the changes in the
pending_
hash.update - Updates the invoice to
paid
.
If payment fails again, the pending_
hash remains on the subscription with the original expiry date and no changes are applied.
See also
Details on the lifecycle, webhooks, and supported attributes when using pending updates: