I was doing some research on how upgrading subscriptions works on Stripe. Stripe's default system is to charge the customer for the proration cost ...
For further actions, you may consider blocking this person and/or reporting abuse
Just a heads up for anyone else that gets erratic behavior with this code:
All line items seem to match the select statement, so it returns whatever line item happens to be first in the array. It seems that order is random. So sometimes you end up getting the pro-rated amount the customer needs to pay, while other times, you get the "unused amount" on the current subscription period, which is basically the discount amount itself.
I think the official Stripe Docs had this same code, but this part has since been removed. They don't provide an alternative, but one way would be to look for the line item with "Remaining time on" in the description.
I haven't thoroughly tested, but this seems to work more reliably:
👆 This returns the 'unused amount'. So if a customer is halfway through a $25/mo period, this would be about $12.50
It looks through all the line items, selects just the negative amounts, and adds them all up. Usually this is just one line item, but in theory it could be multiple.
👆 This is pretty simple. It's the total amount (including any taxes) the customer were to pay. So continuing the $25/mo example, with let's say a $200/year annual plan, this would be about $200 - $12.50 (see above) = $187.50
Hey Risa! This was helpful.
I wanted to clarify something in the above though in regards to upgrading a customer with proration disabled.
My understanding is that disabling proration will not prevent the customer from being charged on the next invoice - rather it would pro-rate the amount they will be charged and that amount would find it's way onto the next invoice.
See Stripe docs
Did you find something different and maybe I'm misinterpreting the documentation?
Thanks mate! 😀
Thanks for the comment :)
Full disclosure, I haven’t used Stripe since I wrote this, so let me refresh my memory and get back to you!
Regarding the part of the docs you quoted - I believe this is expected behaviour.
Let me illustrate with the example plans I used in the post ($5/month standard plan and $10/month premium plan).
What would happen normally in Stripe:
What we’re trying to achieve in the gist:
When they say “the customer is billed the full amount for the new plan”, I think they just mean the customer gets billed normally for the upcoming month, i.e. $10 for October.
The fact that no proration is applied to the next billing cycle’s invoice is also tested in my gist, in the final assertion (JPY 1,000 is the monthly price for the premium plan).
Hope this makes sense! Please let me know if I’m misinformed/you need more clarifications.
Legend! Thanks for such a thorough reply. The proration stuff all makes sense, it's that last point that gets me which is what will show on the final invoice? I want exactly the outcome you describe.
So I think I need to get off this board and prototype this functionality today ;) Thanks again for the post 💪
Update: Confirmed the approach works 🥳
Good luck, let me know if it works! :)
Thank you, Risa, for the thorough write-up!
My problem was somewhat different, but I used some of the ideas from here to end up with my solution. I didn't really have the confidence to just manually add in my own proration lines but it turns out it's not an issue if you understand what you're doing (which was easier with your help).
If you end up needing to support SCA you might find yourself following a similar approach. There's little documentation on this since it's very new and I had to contact Stripe support just for the idea (which might obvious in hindsight).
This article is exactly what I needed! Thanks!
Happy to be of help :)
Thank you, so helpful.
Thanks, happy to hear it!
Nice solution! By the way, how to you handle downgrade cenarios?
Thanks and sorry, just saw this!
I haven't looked into downgrades, but I believe the default behaviour is to prorate the customer in the next invoice, just like upgrades (i.e. the customer gets refunded for the portion of the original plan that they didn't use).
I'm not sure about anything beyond what the docs say, so it might be good to contact Stripe's customer support for details.