Issue
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!
Solution
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.
Answered By - John1984
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.