rubenochoa

rubenochoa

Member Since 1 Month Ago

Experience Points
2,120
Total
Experience

2,880 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
3
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
2,120 XP
May
23
1 week ago
Activity icon

Replied to Issue About An Error

@snapey i am still learning laravel.

Activity icon

Replied to Issue About An Error

@snapey i do not get it very well that you said. You mean that i must not include the function inside the Auth::attempt?

Activity icon

Started a new Conversation Issue About An Error

Hi. Something wrong happens. I get no error while i am trying just to submit sign in.

At usercontroller

 if (Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')])){
            $user = User::where('email', '=', Input::get('email'))->first();
                if ($user === null) {
                    $request->session()->flash('usernotexist', 'User does not exist!');
                    return back();
                }
               else if (User::where('email', '=', Input::get('email'))->exists()) {
                    $request->session()->flash('userexist', 'User exist');
                    return back();
                }
             $remember_me = $request->has('remember_me') ? true : false; 
            if(Session::has('oldUrl')){
                $oldUrl = Session::get('oldUrl');
                Session::forget('oldUrl');
                return redirect()->to(Session::get('oldUrl'));
            }
            return redirect()->route('product.index');
        }
        return redirect()->back();

signin.blade.php


  <div class="form">
    <form action="">
      <h1>Sign in</h1>
      @if(count($errors) > 0)
    <div class="alert alert-danger">
        @foreach ($errors->all() as $error)
        <p>{{ $error }}</p>
        @endforeach
    </div>
    @endif
    @if(session('success'))
    <div class="alert alert-success">
        {{ session('success')}}
    </div>
    @endif
    @if(session('error'))
    <div class="alert alert-danger">
        {{ session('error')}}
    </div>
    @endif
    @if(session('userdelete'))
    <div class="alert alert-success">
        {{ session('userdelete')}}
    </div>
    @endif    
         @if (Session::has('usernoexist'))
            <div class="alert alert-danger  text-center">
               <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                <p>{{ Session::get('no_user') }}</p>
               </div>
               @endif 
    <form action="{{ route('user.signin') }}" method="post">
      <input type="email" name="" id="email" placeholder="Enter email"><br>
      <input type="password" name="" id="password" placeholder="Enter password"><br>
      <input type="checkbox" onclick="confirmfunction()">Show Password
            <script>
                function confirmfunction() {
                    var x = document.getElementById("password");
                    if (x.type === "password") {
                      x.type = "text";
                    } else {
                      x.type = "password";
                    }
                  }
            </script>
      <input type="submit" value="Sign In" value="Sign in" class="signin"> <br>
      {{ csrf_field() }}<br><br>        
          <label for="remember_me">
              <input type="checkbox" name="remember_me" id="remember_me" value="1">Remember Me
          </label>     
    </form> 
      <p><a href="{{ route('password.request')}}">Forget password?</a></p><hr>
      <p class="signup">Do not have an account? <a href="{{ route('user.signup') }}">Sign up instead!</p>
  </div>
</body>
</html>
May
21
1 week ago
Activity icon

Started a new Conversation Pay On Delivery | Best Method

I am working on checkout. If a user does not choose to pay by card but pay on delivery, so i did this:

PostController:

 public function payondelivery(){                
                Mail::send('shop.order_confirmation2', [
                    'user' => Auth()->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");
                    }
                );          
            return redirect()->route('product.index')->with('success', 'Successfully purchased products! | You will receive an oder confirmation at your email');
    }

route:

 Route::post('/order_confirmation2', [
            'uses' => '[email protected]',
            'as' => 'payondelivery'
        ]);  

order_confirmation2.blade.php

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Shipping informations</title>
</head>

<body>
    <div class="col-md-4 col-md-offset-4">
        <div class="cart">
            <p>You choose to pay on delivery</p>
            <div class="container">
                <h2>Shipping informations</h2>
                <table class="table">
                    <thead>
                        <tr>
                            <th>Firstname</th>
                            <th>Lastname</th>
                            <th>City</th>
                            <th>Address</th>
                            <th>Zip</th>
                            <th>Vat number</th>
                            <th>Phone</th>

                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ Auth::user()->name }}</td>
                            <td>{{ Auth::user()->surname }}</td>
                            <td>{{ Auth::user()->city }}</td>
                            <td>{{ Auth::user()->address }}</td>
                            <td>{{ Auth::user()->zip }}</td>
                            <td>{{ Auth::user()->vatnumber }}</td>
                            <td>{{ Auth::user()->phone }}</td>
                        </tr>
                    </tbody>
                </table>

            </div>
        </div>
        <hr>
        <h2>My Orders</h2>
        @foreach ($products as $product)
        <li class="list-group-item">
            <span class="badge badge-secondary">Quantity: {{ $product['qty'] }}</span><br>
            <span class="badge badge-secondary">Item: {{ $product['item']['title'] }}</span><br>
            <span class="badge badge-secondary">Price: ${{ $product['price'] }}</span>
        </li>
        @endforeach
    </div>
</body>

</html>

and at checkout.blade.php i am using link under the form of the payment by cart

<label><a href="{{ route('payondelivery')}}">Pay on Delivery</a></label>

Is this the best method to do it? What do you think?

Activity icon

Replied to Missing Required Parameters For [Route: Password.reset]

@michaloravec cause i want to send email to users.

Activity icon

Started a new Conversation Missing Required Parameters For [Route: Password.reset]

Hello. I am trying to work on Forgot your password.

I am guess by that error that i must use , $user at a href and also

"{{ route('password.reset', ['token' => $token]) }}"

but none of this solutions works.

I have the following in my route:

Route::get('/password/reset/{token}/{email}', 'Auth\[email protected]')->name('password.reset');

Also at signin.blade.php

<a href="{{ route('password.reset')}}"> Forgot your password?</a>

At ForgotPasswordController.php

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;


class ForgotPasswordController extends Controller
{
    protected function sendResetLinkFailedResponse(Request $request, $response)
    {
        return back()->withErrors(
            ['email' => trans($response)]
        )->withInput($request->only('email'));
    }
}

At auth/passwords/reset

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ __('Reset Password') }}</div>

                <div class="card-body">
                    <form method="POST" action="{{ route('password.update') }}">
                        @csrf

                        <input type="hidden" name="token" value="{{ $token }}">

                        <div class="form-group row">
                            <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ $email ?? old('email') }}" required autocomplete="email" autofocus>

                                @error('email')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">

                                @error('password')
                                    <span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
                                @enderror
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Reset Password') }}
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

php artisan make:notification ResetPassword:

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class ResetPassword extends Notification
{
    use Queueable;
    public $token;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($token)
    {
        $this->token = $token;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->line('You are receiving this email because we received a password reset request for your account.')
            ->action('Reset Password', url(config('app.url').route('password.reset', [$this->token, encrypt($notifiable->email)], false)))
            ->line('If you did not request a password reset, no further action is required.');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

May
17
2 weeks ago
Activity icon

Replied to Cannot Send Message Without A Sender Address

I get it now. Thank you for everything @michaloravec

Activity icon

Replied to Cannot Send Message Without A Sender Address

'from' => [
        'from' => ['address' => '[email protected]', 'name' => null],
Activity icon

Started a new Conversation Cannot Send Message Without A Sender Address

Hello everyone. This is an old issue but i search everywhere but no results. It was an old error and solved and now it gets back... I know i have to edit .env file so here is mine:

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=25
MAIL_USERNAME=****
MAIL_PASSWORD=****
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=****
MAIL_FROM_NAME="${APP_NAME}"

tried to use other ports but the error exists... Try to change also example.env but...

At mail.php at address i set my email.

May
16
2 weeks ago
Activity icon

Replied to Controller Not Found

Now I undestand it better. Thank you.

Activity icon

Replied to Controller Not Found

yes with command php artisan make:controller --resource ResetPasswordController also without --resource

Activity icon

Replied to Controller Not Found

The strange thing is that is already at Auth folder.

Activity icon

Replied to Controller Not Found

Now I get Class Auth\ResetPasswordController does not exist

Activity icon

Started a new Conversation Controller Not Found

I am focus working on Forgot your password issue. when I am searching for routing with php artisan route:list command i get C:\MAMP\htdocs\Laravel\shopping-cart\vendor\laravel\framework\src\Illuminate\Container\Container.php:805 ReflectionException::("Class App\Http\Controllers\Auth\ResetPasswordController does not exist") I have tried to use get and post at web.php but the command always gets me this error. Also at auth/passwords i am using confirm, reset, email blade

web.php:

Route::get('/password/reset/{token}/{email}', 'Auth\[email protected]')->name('auth.passwords.reset');

ResetPasswordController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ResetPasswordController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('auth.password.reset');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
    public function showResetForm(Request $request, $token = null)
    {
        return view('auth.passwords.reset')->with(
            ['token' => $token, 'email' => decrypt($request->email)]
        );
    }
}

May
11
3 weeks ago
Activity icon

Started a new Conversation Missing Required Parameters For Editprofile Page

I have created a blade named editrprofile. I am using two functions(get and patch). Everything works fine but when I do save an error appears: missing required parameters that does not allowed to be redirected.

  public function edit(User $user)
    {   
        $user = Auth()->user();        
        return view('user.editprofile', compact('user'));
    }

    public function update(User $user)
    { 
        $this->validate(request(), [                        
            'phone' => 'numeric',
            'name' => 'max:12',
            'surname' => 'max:13',
            'city' => 'max:12',
            'address' => 'max:25',
            'zip' => 'numeric|min:5',
            'vatnumber' => 'nullable|regex:/[0-9]{10}/'
            
        ]);                        
            $user->phone = request('phone');
            $user->name = request('name');       
            $user->surname = request('surname');
            $user->city = request('city');
            $user->address = request('address');
            $user->zip = request('zip');
            $user->vatnumber = request('vatnumber');

        $user->save();
        return redirect()->route('user.editprofile')->with('usersaved', 'Account has been updated!');        
        return back();
    }   
Activity icon

Awarded Best Reply on Registration Fail At Mailverification

I found out what it was, just an environment variable that was null: MAIL_FROM_ADDRESS = null. I just put my email here.

Activity icon

Replied to Registration Fail At Mailverification

I found out what it was, just an environment variable that was null: MAIL_FROM_ADDRESS = null. I just put my email here.

May
06
3 weeks ago
Activity icon

Replied to Registration Fail At Mailverification

Neither and is very strange......I always get email verification.

Activity icon

Replied to Registration Fail At Mailverification

Unfortunaly there is another reason. This was my posting typo here

Activity icon

Started a new Conversation Registration Fail At Mailverification

When I am sign up a user I am usually get an email verification but now it is strange that error says: Cannot send message without a sender address

Having the Mail.php

'from' => [
        'from' => ['address' => [email protected]', 'name' => null],
Activity icon

Replied to User Not Exist At Login

Thank you again @michaloravec

Activity icon

Replied to Sql Status Issue.

Not let me with this errors:

The cardname field is required.
The name field is required.
The surname field is required.

random informations i put:

Card name: jonathan jones name: ruben surname: ochoa

Activity icon

Replied to User Not Exist At Login

Thank you very much. This solved but no message appeared when I use an random email and password.

Activity icon

Replied to Sql Status Issue.

Wrong way I said. The correct way is that:

 $order = new Order();
                $order->cart = serialize($cart);                
                $order->cardname = $request->input('cardname');                
                $order->payment_id = $charge->id;

                $request->validate([
                    'cardname' => 'required',
                    'name' => 'required|max:12',
                    'surname' => 'required|max:13',
                ]);
Activity icon

Replied to Sql Status Issue.

The it was my fault. You mean that way?

$this->validate($request, [
            'email' => 'email|required|unique:users',
            'password' => 'required|string|min:6|confirmed|regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#[email protected]$%^&*-]).{6,}$/',
            'password_confirmation' => 'required|min:6',
            'phone' => 'required|regex:/[0-9]{10}/',
            'name' => 'required|max:12',
            'cardname' => 'required|max:12',                  
            'surname' => 'required|max:13',
            'city' => 'required|max:12',
            'address' => 'required|max:25',
            'zip' => 'required|numeric|min:5',
            'vatnumber' => 'nullable|regex:/(01)[0-8]{8}/'
        ]);   
           
        $user = new User([
            'email' => $request->input('email'),
            'password' => bcrypt($request->input('password')),
            'token' => str_random(35),
            'phone' => $request->input('phone'),
            'cardname' => $request->input('cardname'),
            'name' => $request->input('name'),
            'surname' => $request->input('surname'),
            'city' => $request->input('city'),
            'address'=> $request->input('address'),
            'zip' => $request->input('zip'),
            'vatnumber' => $request->input('vatnumber')
        ]);  
Activity icon

Started a new Conversation User Not Exist At Login

I know this is an old issue but is exist yet with version 7

I am using

if (User::where('email', '=', Input::get('email'))->exists()) {
            $request->session()->flash('no_user', 'warning: message.');
            return redirect()->route('user.signin');         
}

I get `Class 'Illuminate\Support\Facades\Input' not found

Activity icon

Replied to Sql Status Issue.

If I do that then caedname will be just null at database and required already did it at input form of cardname

Activity icon

Replied to Sql Status Issue.

Thank you very much. I do not want to post another discussion with the same topic so i get an error of cardname that can not be null.

Activity icon

Replied to Sql Status Issue.

As string or text?

Activity icon

Started a new Conversation Sql Status Issue.

Hello, I have a cart object in my order table field

Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->integer('user_id');           
            $table->text('address');
            $table->string('card-name');            
            $table->text('phone');            
            $table->string('payment_id');
        });

and at productController Charge::create function I am using:

		$order = new Order();
 	        $order->cart = serialize($cart);                
                $order->cardname = $request->input('cardname');
                $order->surname = $request->input('surname');                
                $order->phone = $request->input('phone');
    
                $order->payment_id = $charge->id;
    
                Auth::user()->orders()->save($order);

When I do the payment I get an error :SQLSTATE[42S22]: Column not found: 1054 Unknown column 'cart' in 'field list' (SQL: insert into `orders` (`cart`, `cardname`, `surname`, `phone`, `payment_id`, `user_id`, `updated_at`, `created_at`) values ("O:8:\"App\\Cart\":3:{s:5:\"items\";a:1:{i:1;a:3:

Activity icon

Awarded Best Reply on Collect Card Information

This problem solved by creating order migration during $charge = \Stripe\Charge::create([ function

Activity icon

Replied to Collect Card Information

This problem solved by creating order migration during $charge = \Stripe\Charge::create([ function

May
05
4 weeks ago
Activity icon

Started a new Conversation Collect Card Information

Days, months and hours I am trying to figure out how can I use according to stripe documentation(https://stripe.com/docs/js/tokens_sources/create_source_data) the collecting of name card when i see at payments, the information of a payment at my account. As you can see at https://imgur.com/rUkMRMv & https://imgur.com/hu2HCK4 .

stripe
  .createSource({
    type: 'ideal',
    amount: 1099,
    currency: 'eur',
    owner: {
      name: 'Jenny Rosen',
    },
    redirect: {
      return_url: 'https://shop.example.com/crtA6B28E1',
    },
  })
  .then(function(result) {
    // Handle result.error or result.source
  });

At view

<div class="row">
                        <div class="col-md-12 mb-3">
                            <label for="card-name">Cart Name</label>
                            <input type="text" id="card_name" class="form-control" required>
                            <label for="firstName">Enter Card Details</label>
                            <div id="card-element">
                                <!-- A Stripe Element will be inserted here. -->
                            </div>
                        </div>
                    </div>

ProductController

$charge = \Stripe\Charge::create([
                    'amount' => $cart->totalPrice * 100,                    
                    'currency' => 'usd',
                    'description' => Carbon::now().' '.$request->input('card-name'),
                    'source' => "tok_mastercard",
                ]); 

Thank you!

Activity icon

Replied to Trying To Get Property 'email' Of Non-object

$user= Auth::user works but why the error says non object of email?

Thank you very much both of you!

Activity icon

Started a new Conversation Trying To Get Property 'email' Of Non-object

There is something strange happen there... This post has previous issues and solved and also worked. Issues like, undefined variables.

Now when I am loggin and I am trying to do a payment that send order confirmation I get:

"Trying to get property 'email' of non-object"

Mail::send('shop.order_confirmation', [
                'user' => $user = Auth::user()->user,
                'products' => $cart->items,
                'totalPrice' => $cart->totalPrice,
            ], function($message) use ($user) {
                    $message->to($user->email);
                    $message->from("[email protected]");
                    $message->subject("Your order confirmation");
                    $message->bcc("[email protected]");
                }
            );

The strange thing is that I am loggin and also an exist user, why it gets me error that email is non-object?

May
04
4 weeks ago
Activity icon

Started a new Conversation Invalid Parameters At Exception Handling

Hello, An issue happened when recently inserted the data as card name, address, postcode etc and pressing submit using Stripe.

This is the checkout.js:

// Create a Stripe client.
var stripe = Stripe('');

// Create an instance of Elements.
var elements = stripe.elements();

// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
   base: {
      color: '#32325d',
      fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
      fontSmoothing: 'antialiased',
      fontSize: '16px',
      '::placeholder': {
         color: '#aab7c4'
      }
   },
   invalid: {
      color: '#fa755a',
      iconColor: '#fa755a'
   }
};

// Create an instance of the card Element.
var card = elements.create('card', 
{
   style: style,
   hidePostalCode:true
});

// Add an instance of the card Element into the `card-element` <div>.
card.mount('#card-element');

// Handle real-time validation errors from the card Element.
card.addEventListener('change', function(event) {
   var displayError = document.getElementById('card-errors');
   if (event.error) {
      displayError.textContent = event.error.message;
   } else {
      displayError.textContent = '';
   }
});

// Handle form submission.
var form = document.getElementById('payment-form');
form.addEventListener('complete-orders', function(event) {
   event.preventDefault();

   var options = {
      name: document.getElementById('card-name').value,
      address_line1: document.getElementById('card-address').value,
      address_city: document.getElementById('card-city').value,
      address_state: document.getElementById('card-province').value,
      address_zip: document.getElementById('card-postcode').value,
   };

   document.getElementById('card-city').disable = true;

   stripe.createToken(card, options).then(function(result) {
      if (result.error) {
         // Inform the user if there was an error.
         var errorElement = document.getElementById('card-errors');
         errorElement.textContent = result.error.message;
         document.getElementById('card-city').disable = false;
      } else {
         // Send the token to your server.
         stripeTokenHandler(result.token);
      }
   });
});

// Submit the form with the token ID.
function stripeTokenHandler(token) {
   // Insert the token ID into the form so it gets submitted to the server
   var form = document.getElementById('payment-form');
   var hiddenInput = document.createElement('input');
   hiddenInput.setAttribute('type', 'hidden');
   hiddenInput.setAttribute('name', 'stripeToken');
   hiddenInput.setAttribute('value', token.id);
   form.appendChild(hiddenInput);

   // Submit the form
   form.submit();
}

First I thought that I did not include the inputs:

<label for="card-name">Cart Name</label>
                            <input type="text" id="card_name" class="form-control" required>
                            <label for="card-address">Address</label>
                            <input type="text" id="card_name" class="form-control" required>
                            <label for="card-city">City</label>
                            <input type="text" id="card_name" class="form-control" required>
                            <label for="card-province">Province</label>
                            <input type="text" id="card_province" class="form-control" required>
                            <label for="card-postcode">Postcode</label>
                            <input type="text" id="card_postcode" class="form-control" required>

but that was not the issue. I did everything but I get: Invalid parameters.

I am using the correct secret and public key.

May
03
4 weeks ago
Activity icon

Replied to No Errors And Not Payment

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.

Activity icon

Replied to No Errors And Not Payment

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

Activity icon

Started a new Conversation 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');
    }   
May
02
1 month ago
Activity icon

Replied to About Stripe Payment Issues

The post has been updated.

May
01
1 month ago
Activity icon

Replied to About Stripe Payment Issues

@randy_johnson First of all thank you very for your time to answer me. In case of want to see at stripe only the cart-name I will just use

name: document.getElementById('card-name').value,
<label for="cart-name">Cart Name</label>
<input type="text" id="card-cvc" class="form-control" required>

right?

Activity icon

Started a new Conversation About Stripe Payment Issues

Hello. First at

"source" => 'tok_mastercard', // obtained with Stripe.js

if i do this

$request->input('stripeToken');

I get "Must provide source or customer"

Second, how can I see the card name at stripe.com dushboard? I am using:

            @extends('layouts.master')

            @section('title')
            Laravel Shopping Cart
            @endsection

            @section('content') 
            <style type="text/css">
                .panel-title {
                display: inline;
                font-weight: bold;
                }
                .display-table {
                    display: table;
                }
                .display-tr {
                    display: table-row;
                }
                .display-td {
                    display: table-cell;
                    vertical-align: middle;
                    width: 61%;
                }
            </style>           
                    <h1>Checkout</h1>
                    <h4>Your Total: ${{ $total }}</h4>                    
                    <div class="row">
                        <div class="col-md-4 m-auto">
                            <div class="panel panel-default credit-card-box">
                                <div class="panel-heading display-table" >
                                    <div class="row display-tr" >
                                        <h3 class="panel-title display-td" >Payment Details</h3>
                                        <div class="display-td" >                            
                                            <img class="img-responsive pull-right" src="http://i76.imgup.net/accepted_c22e0.png">
                                        </div>
                                    </div>                    
                                </div>
                                <div class="panel-body">
                  
                                    @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
                  
                                    <form role="form" action="{{ route('checkout') }}" method="post" class="require-validation"
                                                                     data-cc-on-file="false"
                                                                    data-stripe-publishable-key="{{ env('') }}"
                                         
                                                                    id="payment-form">
                                        @csrf
                  
                                        <div class='form-row row'>
                                            <div class='col-xs-12 form-group required'>
                                                <label class='control-label'>Name on Card</label> <input
                                                    class='form-control' size='4' type='text'>
                                            </div>
                                        </div>
                  
                                        <div class='form-row row'>
                                            <div class='col-xs-12 form-group card required'>
                                                <label class='control-label'>Card Number</label> <input
                                                    autocomplete='off' class='form-control card-number' size='20'
                                                    type='text'>
                                            </div>
                                        </div>
                  
                                        <div class='form-row row'>
                                            <div class='col-xs-12 col-md-4 form-group cvc required'>
                                                <label class='control-label'>CVC</label> <input autocomplete='off'
                                                    class='form-control card-cvc' placeholder='ex. 311' size='4'
                                                    type='text'>
                                            </div>
                                            <div class='col-xs-12 col-md-4 form-group expiration required'>
                                                <label class='control-label'>Expiration Month</label> <input
                                                    class='form-control card-expiry-month' placeholder='MM' size='2'
                                                    type='text'>
                                            </div>
                                            <div class='col-xs-12 col-md-4 form-group expiration required'>
                                                <label class='control-label'>Expiration Year</label> <input
                                                    class='form-control card-expiry-year' placeholder='YYYY' size='4'
                                                    type='text'>
                                            </div>
                                        </div>
                  
                                        <div class='form-row row'>
                                            <div class='col-md-12 error form-group hide'>
                                                <div id="charge-error" class="alert alert-danger{{ !Session::has('error') ? 'hidden' : ''  }}">
                                                    {{ Session::get('error') }}
                                                </div>
                                            </div>
                                        </div>
                  
                                        <div class="row">
                                            <div class="col-xs-12">
                                                <button class="btn btn-primary btn-lg btn-block" type="submit">Pay Now</button>
                                            </div>
                                        </div>
                                          
                                    </form>
                                </div>
                            </div>        
                        </div>
                    </div>
                      
                </div>                                             
                @endsection
@section('scripts')   
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript" src="{{URL::to('js/checkout.js')}}"></script>
@endsection

ProductController.php

public function postCheckout(Request $request)
    {
        if (!Session::has('cart')) {
            return redirect()->route('shop.shoppingCart');
        }
        $oldCart = Session::get('cart');
        $cart = new Cart($oldCart);
        
        \Stripe\Stripe::setApiKey('');
        \Stripe\Charge::create ([
                "amount" => $cart->totalPrice * 100,
                "name" => $request->name,
                "currency" => "usd",
                "source" => 'tok_mastercard', // obtained with Stripe.js
                "description" => "Test payment from itsolutionstuff.com." 
            ]);
        
            $order = new Order();
            $order->cart = serialize($cart);
            

            $order->payment_id = $charge->id;

            Auth::user()->orders()->save($order);
            $user = Auth::user();            ;  
                                
            Mail::send('shop.order_confirmation', [
                'user' => $user,
                'products' => $cart->items,
                'totalPrice' => $cart->totalPrice,
            ], function($message) use ($user) {
                    $message->to($user->email);
                    $message->from("[email protected]");
                    $message->subject("Your order confirmation");
                    $message->bcc("[email protected]");
                }
            );     
            
            Session::flash('success', 'Successfully purchased products!');    

         
            return redirect()->route('checkout')->with('error', $e->getMessage());
        

        Session::forget('cart');
        return redirect()->route('product.index')->with('success', 'Successfully purchased products!');
    }    

Checkout.js

$(function() {
    var $form         = $(".require-validation");
  $('form.require-validation').bind('submit', function(e) {
    var $form         = $(".require-validation"),
        inputSelector = ['input[type=email]', 'input[type=password]',
                         'input[type=text]', 'input[type=file]',
                         'textarea'].join(', '),
        $inputs       = $form.find('.required').find(inputSelector),
        $errorMessage = $form.find('div.error'),
        valid         = true;
        $errorMessage.addClass('hide');
 
        $('.has-error').removeClass('has-error');
    $inputs.each(function(i, el) {
      var $input = $(el);
      if ($input.val() === '') {
        $input.parent().addClass('has-error');
        $errorMessage.removeClass('hide');
        e.preventDefault();
      }
    });
  
    if (!$form.data('cc-on-file')) {
      e.preventDefault();
      Stripe.setPublishableKey($form.data('stripe-publishable-key'));
      Stripe.createToken({
        number: $('.card-number').val(),
        cvc: $('.card-cvc').val(),
        exp_month: $('.card-expiry-month').val(),
        exp_year: $('.card-expiry-year').val()
      }, stripeResponseHandler);
    }
  
  });
  
  function stripeResponseHandler(status, response) {
        if (response.error) {
            $('.error')
                .removeClass('hide')
                .find('.alert')
                .text(response.error.message);
        } else {
            // token contains id, last4, and card type
            var token = response['id'];
            // insert the token into the form so it gets submitted to the server
            $form.find('input[type=text]').empty();
            $form.append("<input type='hidden' name='stripeToken' value='" + token + "'/>");
            $form.get(0).submit();
        }
    }
  
});
Apr
30
1 month ago
Activity icon

Replied to Mail::send But Not Send.

Pff that was hard...for me.

Thank you very much.

Activity icon

Started a new Conversation Mail::send But Not Send.

I am very confusing about this issue. First of all here is my ProductController:

<?php

namespace App\Http\Controllers;

use App\Cart;
use App\Product;
use App\Order;
use Illuminate\Http\Request;

use App\Http\Requests;
use Session;
use Auth;
use Stripe\Charge;
use Stripe\Stripe;
use Mail;

class ProductController extends Controller
{
    public function getIndex()
    {
        $products = Product::all();
        return view('shop.index', ['products' => $products]);
    }

    public function getAddToCart(Request $request, $id)
    {
        $product = Product::find($id);
        $oldCart = Session::has('cart') ? Session::get('cart') : null;
        $cart = new Cart($oldCart);
        $cart->add($product, $product->id);

        $request->session()->put('cart', $cart);
        return redirect()->route('product.index');
    }

    public function getCart()
    {
        if (!Session::has('cart')) {
            return view('shop.shopping-cart');
        }
        $oldCart = Session::get('cart');
        $cart = new Cart($oldCart);
        return view('shop.shopping-cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]);
    }

    public function getCheckout()
    {
        if (!Session::has('cart')) {
            return view('shop.shopping-cart');
        }
        $oldCart = Session::get('cart');
        $cart = new Cart($oldCart);
        $total = $cart->totalPrice;
        return view('shop.checkout', ['total' => $total]);
    }

    public function getReduceByOne($id){
        $oldCart = Session::has('cart') ? Session::get('cart') : null;
        $cart = new Cart($oldCart);
        $cart->reduceByOne($id);
        if (count($cart->items) > 0){
            Session::put('cart', $cart);
        } else{
            Session::forget('cart');
        } 
        return redirect()->route('product.shoppingCart');
    }

    public function getRemoveItem($id){
        $oldCart = Session::has('cart') ? Session::get('cart') : null;
        $cart = new Cart($oldCart);
        $cart->removeItem($id);
        if (count($cart->items) > 0){
            Session::put('cart', $cart);
        } else{
            Session::forget('cart');
        }       
        return redirect()->route('product.shoppingCart');
    }
  

    public function postCheckout(Request $request)
    {
        if (!Session::has('cart')) {
            return redirect()->route('shop.shoppingCart');
        }
        $oldCart = Session::get('cart');
        $cart = new Cart($oldCart);

        Stripe::setApiKey('');
        try {
            $charge = Charge::create(array(
                "amount" => $cart->totalPrice * 100,
                "currency" => "usd",
                "source" => 'tok_mastercard', // obtained with Stripe.js
                "description" => "Test Charge"
            ));
            $order = new Order();
            $order->cart = serialize($cart);
            $order->address = $request->input('address');
            $order->name = $request->input('name');
            $order->surname = $request->input('surname');
            $order->city = $request->input('city');
            $order->zip = $request->input('zip');
            $order->phone = $request->input('phone');

            $order->payment_id = $charge->id;

            Auth::user()->orders()->save($order);
            $user = Auth::user(); 
            $products = Product::all();  
                                
            Mail::send(
                'shop.order_confirmation',
                ['user' => $user],
                function($message) use ($user){
                    $message->to($user->email);
                    $message->subject($user->name, "Your order confirmation");
                    $message->bcc("[email protected]");
                    return view('shop.order_confirmation', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]); 
                    Session::flash('success', 'Successfully purchased products!'); 
                }
            );          
                  

        } catch (\Exception $e) {
            return redirect()->route('checkout')->with('error', $e->getMessage());
        }

        Session::forget('cart');
        return redirect()->route('product.index')->with('success', 'Successfully purchased products!');
    }    
}

First error was undefined variable products and I called all products by

$products= Product::All() and solved.

Second error is undefined variable totalPrice and I did this:

 return view('shop.order_confirmation', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]);

and everythinkg was worked but...I get no email...So I moved the above line after mail::send() and another error was undefined totalPrice..

I know this issue have second post about it but I am in a big confusion...

Apr
29
1 month ago
Activity icon

Replied to Undefined Variable At View

I found it at the ProductController. I used for other functions

return view('shop.shopping-carr', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]); 

so it will be the same for order_confirmation.