Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe - Additional Invoice Item included on recurring payment

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

like image 983
silver Avatar asked Feb 27 '14 22:02

silver


People also ask

How do Stripe recurring payments work?

Recurring chargesAutomatically invoicing customers and attempting payments when new billing cycles start. When payments fail, Stripe retries them using the Smart Retries feature.

Does Stripe send invoice for subscription?

Stripe automatically creates an invoice for subscriptions at the end of each billing cycle. To create a one-off invoice for a non-recurring price, read the Invoicing docs. Stripe finalizes and sends the invoice in 1 hour. Before the invoice is finalized, you can edit it.

Can a customer have multiple subscriptions Stripe?

Multiple subscriptions for a customerYou can simultaneously create multiple subscriptions for a single customer. This capability is useful when you want to make it possible for your customers to subscribe to multiple products with separate intervals.

How do I make a partial payment invoice on Stripe?

Make a partial payment, select Take part payment. Enter the amount of the payment and then click Charge. The invoice status is updated to Part Paid.


2 Answers

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
like image 125
Alex Avatar answered Sep 28 '22 10:09

Alex


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.

like image 34
Igor Almeida Avatar answered Sep 28 '22 10:09

Igor Almeida