Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get next billing date from Laravel Cashier

I have subscribed a user to a subscription plan through Laravel's Cashier package. I now want to display the date the user will next be billed, however this doesn't appear to be an available through the Billable trait.

How do I get the next billing date? Thanks!

like image 563
John1984 Avatar asked Jan 10 '17 19:01

John1984


1 Answers

The solution is to use the asStripeCustomer method:

// Retrieve the timestamp from Stripe
$timestamp = $user->asStripeCustomer()["subscriptions"]->data[0]["current_period_end"];

// Cast to Carbon instance and return
return \Carbon\Carbon::createFromTimeStamp($timestamp)->toFormattedDateString();

Note that I've only tested this with a user who has a single subscription - data[0].

You may need to alter this code for multiple subscriptions or if the user has cancelled and started another subscription.

like image 148
John1984 Avatar answered Sep 27 '22 19:09

John1984