BA
Better Authβ€’3mo ago
Duki

How can I change the interval of a user's active plan?

Let's say a user first buys a subscription with a monthly interval. They now decide that they want to pay yearly, since that one has a discount. How can I change that user's subscription interval from monthly to yearly? Is there a function provided by BA, or do I have to do this manually with stripe's sdk?
18 Replies
Draco
Dracoβ€’3mo ago
Pretty sure the BA stripe plugin re-exports most if not all of the stripe sdk client n stuff Also I'm a bit hazy on Stripe, but for all the stripe-based services like polar and lemonsqueezy, you need to switch plans to switch the interval, you can't just change the interval like that, so you'd create separate plans for each of the monthly/weekly/yearly variants you'd have Yeah, I just rechecked, you can't just change the interval on a stripe plan You have to make products/subs for each interval
Duki
DukiOPβ€’3mo ago
So you mean in Product Catalogue I should have new products for each plan and interval instead of 2 prices within one product, like I have here?
No description
Duki
DukiOPβ€’3mo ago
Cause right now, my "Basic" plan has these 2 prices. I thought that was the correct way to setup a subscription plan that has 2 different intervals.
No description
Duki
DukiOPβ€’3mo ago
Because in my stripe auth config I have the 2 prices defined like this, as it says in the docs for my "Basic" plan
{
name: 'basic',
priceId: 'price_[...]',
annualDiscountPriceId: 'price_[...]',
},
{
name: 'basic',
priceId: 'price_[...]',
annualDiscountPriceId: 'price_[...]',
},
Draco
Dracoβ€’3mo ago
How's your better-auth stripe plugin set up?
Duki
DukiOPβ€’3mo ago
export const stripePlugin = stripe({
stripeClient: stripeBackendClient,
stripeWebhookSecret: STRIPE_WEBHOOK_SECRET,
createCustomerOnSignUp: true,
subscription: {
enabled: true,
plans: [
{
name: 'basic',
priceId: 'price_1RFVZWPL1qjk3NmrTduzFHok',
annualDiscountPriceId: 'price_1RFVwGPL1qjk3NmrEhBSQqRY',
},
{
name: 'pro',
priceId: 'price_1RFW8APL1qjk3NmrTLh8hbJl',
annualDiscountPriceId: 'price_1RFW8fPL1qjk3NmrMPMQ4gjW',
freeTrial: {
days: 14
}
},
{
name: 'lifetime',
priceId: 'price_1RFVb1PL1qjk3NmrOIYJ2tYV'
},
]
}
});
export const stripePlugin = stripe({
stripeClient: stripeBackendClient,
stripeWebhookSecret: STRIPE_WEBHOOK_SECRET,
createCustomerOnSignUp: true,
subscription: {
enabled: true,
plans: [
{
name: 'basic',
priceId: 'price_1RFVZWPL1qjk3NmrTduzFHok',
annualDiscountPriceId: 'price_1RFVwGPL1qjk3NmrEhBSQqRY',
},
{
name: 'pro',
priceId: 'price_1RFW8APL1qjk3NmrTLh8hbJl',
annualDiscountPriceId: 'price_1RFW8fPL1qjk3NmrMPMQ4gjW',
freeTrial: {
days: 14
}
},
{
name: 'lifetime',
priceId: 'price_1RFVb1PL1qjk3NmrOIYJ2tYV'
},
]
}
});
Draco
Dracoβ€’3mo ago
The docs show this:
await client.subscription.upgrade({
plan: "pro",
successUrl: "/dashboard",
cancelUrl: "/pricing",
annual: true, // Optional: upgrade to an annual plan
referenceId: "org_123" // Optional: defaults to the current logged in user ID
seats: 5 // Optional: for team plans
});
await client.subscription.upgrade({
plan: "pro",
successUrl: "/dashboard",
cancelUrl: "/pricing",
annual: true, // Optional: upgrade to an annual plan
referenceId: "org_123" // Optional: defaults to the current logged in user ID
seats: 5 // Optional: for team plans
});
Think if you just change the annual: true thing, it should switch which version of the plan you get Since you have the annualDiscountPriceId set up Proration settings should probably be in the stripe dashboard if you're talking about that stripe should handle the price differences
Duki
DukiOPβ€’3mo ago
I tried that, but then I get the error that the user is already subscribed to that plan.
Draco
Dracoβ€’3mo ago
Hmm Also usually most platforms have you cancel the monthly, or let it end before switching to yearly Is that behaviour usually possible with the stripe sdk?
Duki
DukiOPβ€’3mo ago
tbh, I have no idea πŸ™ˆ I never used stripe before, was hoping BA would make my life easier πŸ˜‚
Draco
Dracoβ€’3mo ago
Well, as far as i remembered, it couldn't Also you have noooooooo idea just how much easier the ba plugin makes it😭 Especially the createCustomerOnSignUp, and the webhook things But yeah, usually that's what you're supposed to do Also I'm pretty sure the ba plugin fully re-exports the Stripe client, so there's probably not alot of things that aren't possible with it
Duki
DukiOPβ€’3mo ago
Ah I found the docs on stripe. It is a bit of a hassle to change the interval https://docs.stripe.com/billing/subscriptions/billing-cycle#changing
Setting the subscription billing cycle date
Learn how to set the billing date for subscriptions.
Duki
DukiOPβ€’3mo ago
Does it tho? Where do you see that api?
Draco
Dracoβ€’3mo ago
I guess you could try the openapi plugin, it'll expose all the routes ba uses, but no, I'm talking from experience, i don't actually know if that's 100% the same, but when shifting my polar and stripe projects to ba, all the same things were available as usual wuth their own sdks No, i wouldn't recommend that, it will cause alot of edge cases, also this doesn't change your plan, this changes only the billing cycle date Aka if your user has a monthly subscription, this article only shows you how to change what day his month renews on Not moving it to yearly
Duki
DukiOPβ€’3mo ago
hmm, I see Some question to that btw, since you mentioned creating customer on signup. I got the same config enabled and experienced some issues I explained here. Are u using a secondary storage in your auth configs too (i for example use redis)? And if so, are you also experincing this issue? https://discord.com/channels/1288403910284935179/1363601316202680432
Draco
Dracoβ€’3mo ago
Hmm, well, I'm using the official convex adapter (not the ba one) as my main db, so i don't really need a secondary storage, although seeing the thread and the issue, I'd say maybe you wanna manually set up a few hooks to also update your redis store?
Draco
Dracoβ€’3mo ago
Stripe | Better Auth
Stripe plugin for Better Auth to manage subscriptions and payments.
Draco
Dracoβ€’3mo ago
onCustomerCreate

Did you find this page helpful?