#bioworkflows - invoice flows
1 messages · Page 1 of 1 (latest)
You can check customer cus_N5UI6exndaZSWt
invoice item ii_1MOmQdDccGCU5vwk858K64hp and invoice in_1MOmQdDccGCU5vwktiRvTOGr
Usually that will happen when the Invoice has not been paid, but in this case it's likely because a zero-dollar invoice was created and immediately finalized before the Invoice Item was created.
As you can see, the customer has enough invoice credit balance, I create an invoice item first, then I create an invoice and immediately finalize it. Is my calling sequence wrong
for order_item in self.items.all():
stripe.InvoiceItem.create(
customer=self.user.customer.id,
price = order_item.stripe_price.id,
)
invoice = stripe.Invoice.create(customer=self.user.customer.id)
stripe.Invoice.finalize_invoice(invoice.id)
So it looks to me that the Invoice is unaware of the InviceItem maybe due to database timing issue.
Can I programmatically add invoice items to invoices?
You can, but the problem is that Stripe will auto-finalize zero dollar invoices unless you specify auto_advance=false when creating the Invoice.
The invoice is created empty, and finalize_invoice is responsible for locating all InvoiceItem belonging to the Customer, right? Let me check what auto-advance means.
ok, I did not specify auto-advance, so finalize_invoice will set its status to finalized, which is actually intended as long as the invoice can include all the InvoiceItems I created.
Right now, the invoice is finalized without any InvoiceItem.
I see pending_invoice_items_behavior, which says its default behavior is exclude, meaning that the creation of the invoice will not include any pending InvoiceItem, should be explicitly specify pending_invoice_items_behavior="include"? This piece of code has been working most of the time so I am confused here.
Ahhhh, okay. I forgot about that field. I'm not sure if that behaves as expected on zero-dollar invoices. Are you able to do a quick repro to check? Happy to do it for you if not
I am reading https://stripe.com/docs/invoicing/integration now. I think in my case it is safer to create Invoice first, then create InvoiceItem while passing Invoiceas a parameter. This will make sure InvoiceItem will be included in Invoice. My previous code relies on the behavior of pending_invoice_items_behavior and is unsafe.
Let us change my code and see if it can fix the problem.
Thanks.