Reputation: 1
I'm relatively new to working with Stripe, and I've recently revamped our Stripe implementation at my workplace. As part of this overhaul, I'm now saving all subscription plan data for our users, including relevant details. We offer two plans: Basic and Premium. Now, we're looking to display a user's subscription history, which might look something like this:
For users after the Stripe revamp, this is relatively straightforward, as I'm storing all the necessary data in our database. However, my challenge is with users who subscribed before the Stripe revamp. I need to retrieve their subscription history and plan journey in chronological order.
Could anyone please provide guidance on how to obtain a user's subscription history and plan journey using Stripe APIs, especially for users whose data predates our revamp?
I attempted to retrieve payment intents and, subsequently, all related invoices and subscriptions to reconstruct a user's subscription history. However, the issue I encountered is that the price IDs from the invoice line items are not presented in the exact chronological order of a user's journey, and there appears to be no straightforward way to sort them.
Upvotes: 0
Views: 1227
Reputation: 1079
I think the best way to do that is to list all Invoices
by Subscription
ID which then returns a list sorted by creation date, with the most recently created invoices appearing first.
You can also use the auto-pagination feature to get all the invoices.
Based on the billing_reason
you can reconstitute the history of the changes, and you can retrieve the Invoice Line Items
to check with price(s) was used for that period.
Upvotes: 0