#tymm
1 messages ยท Page 1 of 1 (latest)
๐ Hi there, Happy to help!
As the error mentions, Nothing to invoice for customer...
An invoice cannot be generated for the specified customer as there are no pending invoice items. Check that the correct customer is being specified or create any necessary invoice items first.
https://stripe.com/docs/error-codes#invoice-no-customer-line-items
hmm weird can u help me to check my code instead.. pretty sure i've put something into it
InvoiceCreateParams createParams = InvoiceCreateParams
.builder()
.setCustomer(customer.getId())
.setCollectionMethod(InvoiceCreateParams.CollectionMethod.SEND_INVOICE)
.setDaysUntilDue(1L)
.setAutoAdvance(false)
.build();
Invoice invoice = Invoice.create(createParams);
for (Map.Entry<String, Object> item : stripeProductQuantity.entrySet()) {
InvoiceItem.create(
InvoiceItemCreateParams
.builder()
.setCustomer(customer.getId())
.setPrice(item.getKey())
.setQuantity(Long.valueOf(item.getValue().toString()))
.setInvoice(invoice.getId())
.build()
);
}
return invoice.finalizeInvoice();
Thanks for sharing your code,
You should start creating the InvoiceItems before creating the Invoice.
When creating the invoice, add this param also pending_invoice_items_behavior=include
https://stripe.com/docs/api/invoices/create#create_invoice-pending_invoice_items_behavior
so i just omit setInvoice() in InvoiceItemCreateParams?
from the doc it's suggesting to create invoice before invoiceitem, maybe i have understood it incorrectly, or maybe u need to update ur doc abit ๐
https://stripe.com/docs/invoicing/integration
Sorry, taking over here. Let me catch-up
Indeed, those docs reflect the behaviour which changed as of the new API version: https://stripe.com/docs/upgrades#:~:text=The pending_invoice_items_behavior parameter,now exclude.
You're still on the older API version though, 2020-08-27, so the behaviour differs and that you should create the Invoice Items first
Alternatively you can pass pending_invoice_items_behavior: 'exclude' when creating the invoice first: https://stripe.com/docs/api/invoices/create#create_invoice-pending_invoice_items_behavior
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.