Your subscription is already set up in Stripe?
Nov 20, 2019
3
Level 2
Stripe payment with Laravel
Hello everyone, I have a little problem.I am trying to implement Stripe payment gateway using Laravel Cashier.I setup all the things, but something went wrong.
public function store(Request $request)
{
$stripeToken = $request->get('stripe_token');
$user = User::findOrFail(auth()->user()->id);
$plan = 'enterprise';
$user->newSubscription('main', $plan)->trialDays(5)->create($stripeToken);
}
I try to make a simple payment, but the payment is successful and still get this error.
The payment is canceled
Thanks in advice!
Level 67
Not to do with your problem, but...
$user = User::findOrFail(auth()->user()->id);
Why do you requery the database to get what you already have, which is the current user? Just use auth()->user(), which is the current logged in user instance.
$stripeToken = $request->get('stripe_token');
$plan = 'enterprise';
auth()->user()->newSubscription('main', $plan)->trialDays(5)->create($stripeToken);
That will eliminate 1 query on that page which wasn't necessary.
1 like
Please or to participate in this conversation.