#bioworkflows - invoice flows

1 messages · Page 1 of 1 (latest)

sleek hingeBOT
brisk coral
#

You can check customer cus_N5UI6exndaZSWt

#

invoice item ii_1MOmQdDccGCU5vwk858K64hp and invoice in_1MOmQdDccGCU5vwktiRvTOGr

pearl sparrow
#

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.

brisk coral
#

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?

pearl sparrow
#

You can, but the problem is that Stripe will auto-finalize zero dollar invoices unless you specify auto_advance=false when creating the Invoice.

brisk coral
#

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.

pearl sparrow
#

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

brisk coral
#

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.

Learn how to create and send an invoice with code.

#

Let us change my code and see if it can fix the problem.

#

Thanks.