Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rubenochoa's avatar

No errors and not payment

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');
    }   
0 likes
4 replies
bobbybouwmann's avatar

You flash something to the session key named fail-message however, you don't list it somewhere. Try this

@if (Session::has('fail-message'))
    <div class="alert alert-danger text-center">
        <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
        <p>{{ Session::get('fail-message') }}</p>
    </div>
@endif
rubenochoa's avatar

Forgot to mension that. I did it and I get no error

bobbybouwmann's avatar
Level 88

Are you redirected? Is the email sent?

You catch so many exceptions, if something goes wrong you must see it! Have you tried replacing setting the session with just a dd('error message'). There might be a double redirect why you don't see the error message in your view or there might be a mistake in your view

rubenochoa's avatar

I did that: I renamed error-messages as error-message1,2,3,4,5,6,7 and that was my fault. So sorry, this was a silly mistake.

Thank you very much for your time.

Please or to participate in this conversation.