11

I am having a problem adding invoice item on subscription and currently banging my head on the wall.

I've created an Invoice Item on stripe and I’d like the Invoice Item to be included on the recurring payment

Here’s my code, it adds an invoice item on first invoice but not on the next invoice.

$new_customer = Stripe_Customer::create(array(
    'card' => $card,
    'email' => $email,)
);
Stripe_InvoiceItem::create(array(
    'customer' => $new_customer['id'],
    'amount' => $additiona_charges,
    'currency' => 'gbp',
    'description' => 'Addtional Cities'
));
$new_customer->updateSubscription(array('plan' => $selected_plan, 'prorate' => true));

On my current set-up. I have additional custom charges based on customer selection upon subscription thats way I need to add additional charges on recurring payment.

Its something like this

Plan

1 Cookie - 99GBP  / Per month
2 Cookies - 199GBP / Per month
3 Cookies - 300GBP / Per month

Additional Charges - Invoice Items

-With Candle - +20GBP // must be included on recurring payment.
-With Icecream - +26GBP // must be included on recurring payment.
-With Cheese - +28GBP // must be included on recurring payment.
-With Ketchup - +30 //  must be included on recurring payment.
-With Poison (for your X) -  +50 //  must be included on recurring payment.

I hope someone could help. Thanks so much

Cheers Kenn

Community
  • 1
  • 1
silver
  • 4,433
  • 1
  • 18
  • 30
  • I'm also working on something similar - I have an open support ticket with them to clarify this process. Will answer this question whenever i get a response – Alex Apr 07 '14 at 15:15
  • Trying to do the same thing today and now got an answer .+1 for a good question with clear details. – Alive to die - Anant Jun 28 '23 at 13:45

2 Answers2

17

I have a support question open with Stripe, so will update as / if necessary.

However, I have just re-read the documentation on metered billing

The account balance and invoice items are simply one-time adjustments to your customer's account, so they won't be automatically applied each month.
If your service uses metered billing or needs to add custom amounts for taxes or other dynamic costs, then you will need to create invoice items every month.

It continues ....

To get started, just use webhooks to listen for the invoice.created event. Whenever an invoice is open for modification, your webhook endpoint can create an invoice item that references the existing invoice's ID. We'll automatically pull this amount into the invoice total before charging your customer.

So, it seems we'll need to create a web hook handler in order to re-add these invoice items each month.

According to the documentation on invoices

Once an invoice is created, payment is automatically attempted. Note that the payment, while automatic, does not happen exactly at the time of invoice creation. If you have configured webhooks, the invoice will wait until one hour after the last webhook is successfully sent (or the last webhook times out after failing).

That allows us to create a web hook, in order to modify the invoice, prior to payment being attempted.

My suggested InvoiceCreatedWebhook process

  1. Listen for the body of the invoice.created event - the full body looks like this
  2. Retrieve your customer from your database. In this example, our stripe customer id is cus_00000000000000
  3. Assuming you have somehow recorded the additional items against your customer, create invoice items, and apply them to the invoice by setting the invoice property - in this example id in_00000000000000
Alex
  • 37,502
  • 51
  • 204
  • 332
  • I think adding the invoice items from your webhook event handling code is the best general solution. If you only have a few plans/variants, you could also create all possible permutations as separate plans in Stripe. E.g., you'd have the "1 Cookie w/ Ice Cream" plan, the "2 Cookies w/ Ice Cream" plan, etc. That could get ugly quick if you increase your number of plans and options, though. – Derek Kurth Sep 22 '14 at 21:51
2

How about just creating the extras as additional plans and subscribing the client to those plans as well? So he would be subscribed to the 1 cookie plan + ice-cream plan as an example. You sure can have the same customer subscribed to multiple plans.

  • 1
    Problem is every subscription has a separated billing cycle. You have two different payments in two different moments. – dmoreno May 26 '17 at 06:40
  • I second that. What OP describes seems to fit the additional subscription items perfectly. https://stripe.com/docs/api#subscription_items – Ivan Kurmanov Jul 25 '17 at 10:44