#cnguyen - subscription rebill
1 messages · Page 1 of 1 (latest)
Yes, it sounds like you would want to check the Invoice's billing_reason property https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
To make sure we are aligned on terms, by "rebill" do you mean the subscription cycling or an invoice created some other way?
I have a subscription (rebill by month). And I update the statement_descriptor with a random one on the invoice.created event. So, for the first month, I set a statement descriptor.
For the 2nd and next months, I would like to keep this statement descriptor and not generated a new random one.
So, when I have the invoice.created event for the 2nde time (and more), I would like to know that it's the 2nd (and more) rebills for this subscription and keep the initial statement descriptor that I generated for the 1rst invoice
My idea is to "list all invoices" with subscription id and customer id (maybe I just need the subscription id ? if it's specific to the customer). Then check if there is already one and take his statement descriptor. But not sure if it's the fastest way. @proud pond
I think that could work. Otherwise, billing_reason would probably be what you need. On the first Invoice, it will be subscription_create and for every subsequent cycle it will be subscription_cycle
It also may make sense to set this statement descriptor as metadata on the subscription itself if you are going to set it once and re-use it thereafter. That could be easier to look up again
Or you can record it in your own DB's record of the subcription
For now, I do stripe.invoices.update to update the statement descriptor. Sounds good like that ?
And about the subscription cycle, I understand but I have to get back the previous statement descriptor no ?
And if yes, how ? My only way is the invoice list ?
HI I'm stepping in for @proud pond
Let me catch up a bit
If you already have the ID of the subscription you are interested in, you can get the subscription.latest_invoice to find the most recent invoice and get the statement descriptor. However, I think @proud pond 's idea of storing your initial statement descriptor in your own DB and then re-using it when billing_reason is subscription_cycle makes the most sense.
On the invoice.create event, I have the subscription ID. So it's good. When you speak about the subscription.lastest_invoice, at each event/moment ? Or you speak when I fetch the invoice list ?
I am still trying to understand when you are trying to make these changes. Are you actively listing invoices periodically or are you waiting for webhook events?
For now, I listen the invoice.created event. And on this event, I update the statement descriptor. The goal is to generated the PI with the right descriptor.
Then, for the next rebill, on the invoice.created event, I want to check if it's the first or 2nde invoice for this subscription (so , if it's a rebill), and, if it's a rebill, I want to take the statement descriptor set on the 1rst invoice to keep the same one for the 2nde invoice
In that case, checking billing_reason should do what you need, but I would store the custom statement descriptor as related to the subscription.
But... how do you get the previous statement descriptor ?
Since the Invoice will have a subscription ID so you can easily look up the statement descriptor by the ID in you own DB
I can check the billing reason to know that is a rebill ok. But if I'm in the 2nd, 3rd, etc... rebill, what is the best way to get back the statement descriptor ? Fetch the invoices by subscription id ?
And if I don't use my own DB but Stripe plz
But I think I find the answer. I will list all the invoice and take the last one. Thank you.
The subscription id is specific to one customer and one product ? Or I have to add the both parameters => subscription_id and customer_id for the stripe.invoices.list
When you list invoices, you can filter by subscription ID so that should be able to reduce the amount of invoices you need to step through.
It's sorted by creation date with the most recent invoice first: https://stripe.com/docs/api/invoices/list
The subscription id is specific to one customer and one product ? Or I have to add the both parameters => subscription_id and customer_id for the stripe.invoices.list