Danis
Danis

Reputation: 2110

Stripe: Add invoice item to invoice

I'm having a problem to adding invoice item in monthly invoice. Here is my billing implementation.

After getting an invoice.created webhook from the Stripe, I calculate the extra payment amount and trying to update the current invoice, by adding invoice item. Here is the code:

stripe.invoiceItems.create({
   'customer': 'cus_00000000',
   'amount': 2000,
   'currency': 'usd',
   'description': 'additional fee'
}, function (error, invoice) {
   if (error) {
     throw new Error('Error creating invoice item');
   }
   return Promise.resolve(invoice);
});

As the result Stripe creates an Invoice item, and adds it to the next upcoming invoice. The issue is, that I need to add the extra payment line to the current created invoice. My question is, is there any way to update pending invoice, not the upcoming.

Upvotes: 7

Views: 6645

Answers (1)

koopajah
koopajah

Reputation: 25622

When you create the invoice item via the API, you can pass the optional invoice parameter which tells Stripe which invoice to attach the invoice item to. If you don't pass one, it will simply stay pending until the future invoice.

Since you want to add it to the invoice that was just created, make sure to pass that invoice's id in the invoice parameter:

stripe.invoiceItems.create({
   'customer': 'cus_00000000',
   'amount': 2000,
   'currency': 'usd',
   'description': 'additional fee',
   'invoice': 'in_1234'
}, function (error, invoice) {
   if (error) {
     throw new Error('Error creating invoice item');
   }
   return Promise.resolve(invoice);
});

Upvotes: 10

Related Questions