dj-stripe / dj-stripe

dj-stripe automatically syncs your Stripe Data to your local database as pre-implemented Django Models allowing you to use the Django ORM, in your code, to work with the data making it easier and faster.
https://dj-stripe.dev
MIT License
1.56k stars 474 forks source link

Invoice assignmet for IIs missing #2016

Closed patroqueeet closed 4 months ago

patroqueeet commented 5 months ago

Describe the bug Create pending line item for invoice manually in stripe in advance for upcoming subscription invoice ( inv not created yet)). Once Stripe sends the Invoice.created event, the LineItem().invoice_item.invoice stays empty. As we are creating the invoice pdf based on invoice.subscription.line_items plus invoice.invoice_items the latter ones are missing in our invoice pdf.

To Reproduce I tried to reproduce it. But doing an api_retrieve() and then sync_from_stripe_data() fixes this issue for the objects. Cannot replay the web hook call.

Software versions

arnav13081994 commented 5 months ago

@patroqueeet Finally was able to reproduce this in the following scenario:

1) Create a subscription with 1 or more recurring Price objects 2) After the upcoming invoice is created (and the invoice.created event is fired), update the subscription to also include a one time price object. 3) The invoice now will not have the invoice_item object associated with it.

Please note that in case the subscription is created with a recurring and a one time price, everything works as expected. It is only when the subscription gets updated with a one time object that this issue is observed. I'm just curious about the following:

1) Why are you updating subscriptions? This might be indicative of a deeper issue in the way the code is structured. 2) Why are you not using the hosted Invoices? I think they can also be whitelisted but I am not sure about that.

patroqueeet commented 5 months ago

re 1) customers buy a SaaS service but then they are requesting some manual additional service. instead of creating a fresh invoice we add a pending invoice item in the stripe UI to be charged along the next subscription based invoice. re 2) our system was created, when stripe did not have this feature and as of now we don't want stripe to appear in our customer communication. so all forms, emails, pdfs are managed and created on our side.