Hi.
I have set up a payment using Stripe. So, I use:
@if ($errors->any())
@foreach ($errors->all() as $error)
<div>{{$error}}</div>
@endforeach
and
@if (Session::has('success'))
<div class="alert alert-success text-center">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<p>{{ Session::get('success') }}</p>
</div>
@endif
errors area to be appeared but when I do the submit I get no payment and no error to explain me what happen so I can fix the issue.
My ProductController.php
\Stripe\Stripe::setApiKey('');
// Token is created using Stripe Checkout or Elements!
// Get the payment token ID submitted by the form:
if ( isset($_POST['stripeToken']) ){
$token = $_POST['stripeToken'];
}
try {
$charge = \Stripe\Charge::create([
'amount' => $cart->totalPrice * 100,
'currency' => 'usd',
'description' => Carbon::now().' '.$request->input('cart-name'),
'source' => $request->input('stripeToken'),
]);
} catch(\Stripe\Exception\CardException $e) {
$request->session()->flash('fail-message', 'Your payment was declined.');
return redirect()->route('checkout');
} catch (\Stripe\Exception\RateLimitException $e) {
$request->session()->flash('fail-message', 'To many requests to the API.');
return redirect()->route('checkout');
} catch (\Stripe\Exception\InvalidRequestException $e) {
$request->session()->flash('fail-message', 'Invalid parameters.');
return redirect()->route('checkout');
} catch (\Stripe\Exception\AuthenticationException $e) {
$request->session()->flash('fail-message', 'There are problems with authentication.');
return redirect()->route('checkout');
} catch (\Stripe\Exception\ApiConnectionException $e) {
$request->session()->flash('fail-message', 'There is a problem with the network.');
return redirect()->route('checkout');
} catch (\Stripe\Exception\ApiErrorException $e) {
$request->session()->flash('fail-message', 'There is a problem with the API.');
return redirect()->route('checkout');
} catch (Exception $e) {
$request->session()->flash('fail-message', 'We don\'t know what happened.');
return redirect()->route('checkout');
}
Mail::send('shop.order_confirmation', [
'user' => $user,
'products' => $cart->items,
'totalPrice' => $cart->totalPrice,
], function($message) use ($user) {
$message->to($user->email);
$message->from("@gmail.com");
$message->subject("Your order confirmation");
$message->bcc("@gmail.com");
}
);
Session::forget('cart');
return redirect()->route('product.index')->with('success', 'Successfully purchased products! | You will receive an oder confirmation at your email');
}