#dorian_subscription-upgrade
1 messages ¡ Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- dorian6730_best-practices, 2 days ago, 11 messages
- dorian6730_best-practices, 2 days ago, 18 messages
- dorian_subscription-webhook-events, 2 days ago, 11 messages
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1256010914130296904
đ Have more to share? Add details, code, screenshots, videos, etc. below.
dorian_subscription-upgrade
@finite stump I recommend reading https://docs.stripe.com/billing/subscriptions/upgrade-downgrade#changing that explains this
Thanks @fossil blaze but that is more complex I think for my scenarion than simply deleting the existing items and replacing.
Is there any harm in just deleting all of them and replacing wiht new?
yeah I was trying to avoid going deep because it's super subtle
What do you mean by "delete all of them" exactly?
The quantities and/or prioces may change on my items. It will be complex for me to figure out the changes relative to the existing. It would be simpler to just delete all the line items and repalce them with new ones. Just like I created new items when I created the subscription. This is what I am doing in my own database - just delete the existing line items and repalcing with new.
yeah sorry I understand what you mean conceptually. But how do you plan to delete all existing line items? Like what code did you have in mind exactly?
Call GET /v1/subscriptions/:id which returns all the items and their IDs. Then call POST /v1/subscriptions/:id with items.delete for each ID.
Then call POST /v1/subscriptions/:id again to add the new items
gotcha, that's what I wanted to have you say. This is impossible. You'd end up with a Subscription that doesn't have any items which doesn't work.
What you can do instead though is
- Retrieve the Subscription https://docs.stripe.com/api/subscriptions/retrieve
- Update the Subscription and pass
itemsas an array of 2 separate lists: all the old SubscriptionItems to delete and all the new Prices to add.
So imagine you have a Subscription sub_ABC with 3 Subscription Items:
- si_123 on Price A
- si_def on Price B
- si_xyz on Price C
Now you want to switch that Subscription to Price B, D, N. But you don't want to bother tracking if they already have B (which they do) you just want to "replace" the list of Prices to B/D/N.
So what you pass is this:
items: [
// Delete all existing SubscriptionItems you got when retrieving the Subscription
{id: 'si_123', deleted: true},
{id: 'si_def', deleted: true},
{id: 'si_xyz', deleted: true},
// Add all the new Prices you want
{price: 'B', quantity: 1},
{price: 'D', quantity: 1},
{price: 'N', quantity: 1},
]