Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top