Lito
Lito

Reputation: 1332

Set billing cycle date on Stripe checkout session create (or update subscription with a new billing_cycle_anchor)

I'm creating a SaaS with 4 subscription plans: 1 free and 3 paid.

Users can stay in the Free Plan always as they want, but when a user change to a paid subscription, I want to set same billing date as previous Free Plan and only pay (at billing cycle end) from current date to previous free plan end date. I'm using the checkout session create API endpoint, I don't want to use the subscription create API endpoint because I need to control a lot of more things.

For example:

  1. User singup at 15-02 with the Free Plan, then the next Free Plan renew is at 15-03.
  2. At 20-02 user update subscription to a Paid one, then I redirect to checkout Stripe screen using the checkout Session Create API URL. Problem: The Checkout Session Create endpoint does not allow to set the billing_cycle_anchor timestamp. Then the subscription billing cycle will be 20-02 / 20-03.
  3. I receive the subscription create notification at backend webhook.
  4. I want to update the subscription to set the correct billing cycle (15-02 / 15-03), then the user will pay on 15-03 the difference from 20-02 and 15-03 and at 15-03 the subscription will be renewed to 15-04.

There are any way to do it without trials or subscription schedules?

Thanks!

UPDATE 1: Maybe I can cancel the subscription on webhook and create a new subscription with the correct billing_cycle_anchor? It's a "right-way" solution?

Upvotes: 0

Views: 2016

Answers (2)

xyres
xyres

Reputation: 21834

billing_cycle_anchor can be set via the Checkout session since since 26 April, 2023. See docs.

Example in JSON pseudo-code:

{
    "mode": "subscription",
    "subscription_data": {
        "billing_cycle_anchor": 1682985600
    }
}

Upvotes: 1

orakaro
orakaro

Reputation: 1981

It sounds like you want to do a proration update. It should be done via the regular Subscription API, in other words, you can't do it with just the Checkout API, and also shouldn't cancel and recreate the Subscription as you mentioned.

When it's not necessary for Subscription Schedule, it's still more "right" to use the regular Subscription Update API. Stripe has a comprehensive guide on their Doc and their API Reference that worth checking out.

By default, we prorate subscription changes. For example, if a customer signs up on May 1 for a ¥100 price, she'll be billed ¥100 immediately. If on May 15 she switches to a ¥200 price, then on June 1 she'll be billed ¥250 (¥200 for a renewal of her subscription, plus a ¥50 prorating adjustment for half of the previous month's ¥100 difference). Similarly, a downgrade will generate a credit to be applied to the next invoice. We also prorate when you make quantity changes.

Upvotes: 1

Related Questions