#ldream-subscriptions
1 messages · Page 1 of 1 (latest)
hello!
- Will this add invoice items to the draft invoice or to the next subscription cycle after the freshly created one?
The first invoice of new subscription doesn't have a draft state, so they cannot be changed. So the invoice item will be added to the next invoice created by the subscription.
- Is there a better / recommended way to implement this kind of overage charging - something around listening to draft invoice webhooks?
When do you know you'll need to add additional charges to the subscription? Before the subscription is created, just after, at any time?
just to clarify, this is the timeline:
- customer purchases subscription (invoice finalized right away)
- [Month 1] customer uses product
- At the end of month 1, we want to charge the user an overage based on how much they have used. at this point we listen to new subscriptions that are created
- If the user has an overage charge, we create the invoice item
For question 1 - does it get added to the invoice for Month 2 (which should be in draft mode at the point of #4 firing)? Or month 3's
For question 2 - we only know at the end of the subscription period
Got it! Then you have 2 options:
- When you detect that there should be an overcharge, call
stripe.invoiceItems.create. These items will be pulled in the next invoice created by the subscription. - Or listen to the
invoice.createdwebhook event. When you receive it the invoice is in draft status and can be updated, so there you can add an extra invoice item by callingstripe.invoiceItems.createand setting the existing invoice ID.
https://stripe.com/docs/api/invoiceitems/create#create_invoiceitem-invoice
ah with the first option:
since we only know there is an overcharge at the end of their Month 1 subscription, if we call stripe.invoiceItems.create at the point where there is already a draft invoice for Month 2, will that get added to the Month 2 invoice or Month 3? (we are not specifying the invoice id
According the api docs -
If you call stripe.invoiceItems.create and pass a draft invoice ID in the invoice parameter, the item will be added to the draft invoice.
If you don't set this field, the item will be added to the next invoice created (so if there's already a draft invoice, it will be included in the next invoice).
ah.. fair fair. that makes a lot of sense!
between the two ways of doing things - is the webhook the recommended way? or both are quite stable
Both will work, it's completely up to you.
ah i see. this is super helpful. thank you!
Happy to help 🙂