[stripe-api-discuss] creating Invoice and adding invoice line items

901 views
Skip to first unread message

Marian Gheata

unread,
Oct 27, 2022, 12:08:32 PM10/27/22
to Stripe API Discussion
Hello Stripe Team Members.

I am sorry for my English.
I did the following for creating invoice.



invoice = stripe.Invoice.create(
                customer=customer.id,
                collection_method="send_invoice",
                days_until_due=30,
                currency="usd"
)

stripe.InvoiceItem.create(
                customer=customer.id,
                price=price.id,
                invoice=inovoice.id
            )

But it returns following error message.

stripe.error.InvalidRequestError: Request req_XjQwuETRlcX5pW: Nothing to invoice for customer



I am at a critical juncture in using stripe and any quick help would be very much appreciated.

Remi J.

unread,
Oct 27, 2022, 12:37:04 PM10/27/22
to api-d...@lists.stripe.com
Hello Marian,

Creating an empty Invoice on a Customer, which is what your first call does, requires being on the most recent API version [1] which is 2022-08-01. This API version introduced a major change to the Invoice API that stops requiring having a "pending InvoiceItem" on the Customer before Invoice creation.

You are getting this error because your code or (your Stripe account) is on an older API version and doesn't support this feature yet. You should force the most recent API version when you make those calls as documented here [2]. Alternatively, you can use the `pending_invoice_items_behavior` parameter [3] and pass the value `exclude` to create an empty Invoice on your older API version like this:

invoice = stripe.Invoice.create(
  customer=customer.id,
  collection_method="send_invoice",
  days_until_due=30,
  currency="usd",
  pending_invoice_items_behavior="exclude"
)

Hope this helps!
Best,
Remi


--
To unsubscribe from this group and stop receiving emails from it, send an email to api-discuss...@lists.stripe.com.
Reply all
Reply to author
Forward
0 new messages