#ldream-subscriptions

1 messages · Page 1 of 1 (latest)

main ore
#

Hi there!

silent forum
#

hello!

main ore
#
  1. 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.
#
  1. 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?
silent forum
#

just to clarify, this is the timeline:

  1. customer purchases subscription (invoice finalized right away)
  2. [Month 1] customer uses product
  3. 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
  4. 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

main ore
#

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.created webhook 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 calling stripe.invoiceItems.create and setting the existing invoice ID.
    https://stripe.com/docs/api/invoiceitems/create#create_invoiceitem-invoice
silent forum
#

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 -

main ore
#

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).

silent forum
#

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

main ore
#

Both will work, it's completely up to you.

silent forum
#

ah i see. this is super helpful. thank you!

main ore
#

Happy to help 🙂