Sending an invoice with one invoice item works fine, but things get a bit hairy when I try an send an invoice with many invoice items.
At times multiple invoices gets sent correctly, but often one of the invoice items is missing in the invoice, but get's included in the next invoice. Or at times I will get an error message of: Error: Nothing to invoice for customer
, even thought I had just ran stripe.invoiceItems.create
. Has anyone else ran into this issue?
To create multiple invoice items I have logic like this:
await req.body.items.map(item => {
const unitAmount = (item.wholesale_price + (item.shipping_amount/item.quantity) + (item.s_h/item.quantity));
stripe.invoiceItems.create({
unit_amount: unitAmount,
currency: 'usd',
customer: stripe_cus_id,
description: item.description,
quantity: item.quantity
}, function(err, invoiceItem) {
if(err) {
console.error(err);
} else {
console.log(`CREATED: ${item.description}`);
}
});
});
Then I send the invoice like so:
const invoice = await stripe.invoices.create({
customer: stripe_cus_id,
billing: 'send_invoice',
days_until_due: 15
});