In this video we are going to learn about Checkout With Stripe.
So let see how can we checkout with stripe option.
For integration of stripe, we will use Cartalyst stripe-laravel package.
So first of all lets install this package.
So lets open the google and here.
Search Cartalyst stripe-laravel.
Now just click on link on page you can see the installation guide.
So lets follow these steps.
In first step lets add the cartalyst/stripe-laravel package inside the composer.json file.

And go to the project and lets open the composer.json file
And inside the require array write the package.


\"cartalyst/stripe-laravel\": \"^13.0\"


And now go to the command prompt and lets run the command


composer update


Now lets configure this package in app.php file.
So go to the config directory and from here open app.php file
And inside the providers array just paste here


Cartalyst\\Stripe\\Laravel\\StripeServiceProvider::class,


Now copy this and paste inside the aliases array


'Stripe' => Cartalyst\\Stripe\\Laravel\\Facades\\Stripe::class,



Now lets create an account on stripe
So go to the stripe.com
Now click on start now
Enter email id you name
Select your country entry any password
And click on create account
Alright
I have already created an account so I am going to login
So click on sign in now enter the email and password and click on continue
Now click on home link
And here you can see the Test API keys, and Live API keys
For testing purpose we use Test API kyes
And once all testing are done then we use this live api keys
Alright
So now lets reveal this test key and copy this
Now open env file and here lets add here stripe secret key

STRIPE_KEY=sk_test_51IfLWvGRFb8TqOPoEEZxZZWmnNwjAUlyvhtUuytY4G0qW2fsCP5EuXYTM6OVSjH3KnnH1WQBMhcBNEuB6N7ZNgA7008p18tNjn


And go to the env file and paste here.
Now go to the checkout-component.blade.php view file.
And inside checkout page lets create a form for accepting card details.
So inside the payment-method div add the following code.

<h4 class=\"title-box\">Payment Method</h4>
@if($paymentmode == 'card')
<div class=\"wrap-address-billing\">
@if(Session::has('stripe_error'))
<div class=\"alert alert-danger\" role=\"alert\">{{Session::get('stripe_error')}}</div>
@endif
<p class=\"row-in-form\">
<label for=\"card-no\">Card Number:</label>
<input type=\"text\" name=\"card-no\" value=\"\" placeholder=\"Card Number\" wire:model=\"card_no\">
@error('card_no') <span class=\"text-danger\">{{$message}}</span> @enderror
</p>

<p class=\"row-in-form\">
<label for=\"exp-month\">Expiry Month:</label>
<input type=\"text\" name=\"exp-month\" value=\"\" placeholder=\"MM\" wire:model=\"exp_month\">
@error('exp_month') <span class=\"text-danger\">{{$message}}</span> @enderror
</p>

<p class=\"row-in-form\">
<label for=\"exp-year\">Expiry Year:</label>
<input type=\"text\" name=\"exp-year\" value=\"\" placeholder=\"YYYY\" wire:model=\"exp_year\">
@error('exp_year') <span class=\"text-danger\">{{$message}}</span> @enderror
</p>

<p class=\"row-in-form\">
<label for=\"cvc\">CVC:</label>
<input type=\"password\" name=\"cvc\" value=\"\" placeholder=\"CVC\" wire:model=\"cvc\">
@error('cvc') <span class=\"text-danger\">{{$message}}</span> @enderror
</p>
</div>
@endif


Now go to the CheckoutComponent.php class file and crate properites here
public $card_no;
public $exp_month;
public $exp_year;
public $cvv;

Now inside the updated method add the following code.

if($this->paymentmode == 'card')
{
$this->validateOnly($fields,[
'card_no' => 'required|numeric',
'exp_month' => 'required|numeric',
'exp_year' => 'required|numeric',
'cvc' => 'required|numeric'
]);
}

And inside the placOrder method add the following line of code.

if($this->paymentmode == 'card')
{
$this->validate([
'card_no' => 'required|numeric',
'exp_month' => 'required|numeric',
'exp_year' => 'required|numeric',
'cvc' => 'required|numeric'
]);
}

Now add the code for stripe payment


if($this->paymentmode == 'cod')
{
$this->makeTransaction($order->id,'pending');
$this->resetCart();
}
else if($this->paymentmode == 'card')
{
$stripe = Stripe::make(env('STRIPE_KEY'));

try{
$token = $stripe->tokens()->create([
'card' => [
'number' => $this->card_no,
'exp_month' => $this->exp_month,
'exp_year' => $this->exp_year,
'cvc' => $this->cvc
]
]);

if(!isset($token['id']))
{
session()->flash('stripe_error','The stripe token was not generated correctly!');
$this->thankyou = 0;
}

$customer = $stripe->customers()->create([
'name' => $this->firstname . ' ' . $this->lastname,
'email' =>$this->email,
'phone' =>$this->mobile,
'address' => [
'line1' =>$this->line1,
'postal_code' => $this->zipcode,
'city' => $this->city,
'state' => $this->province,
'country' => $this->country
],
'shipping' => [
'name' => $this->firstname . ' ' . $this->lastname,
'address' => [
'line1' =>$this->line1,
'postal_code' => $this->zipcode,
'city' => $this->city,
'state' => $this->province,
'country' => $this->country
],
],
'source' => $token['id']
]);

$charge = $stripe->charges()->create([
'customer' => $customer['id'],
'currency' => 'USD',
'amount' => session()->get('checkout')['total'],
'description' => 'Payment for order no ' . $order->id
]);

if($charge['status'] == 'succeeded')
{
$this->makeTransaction($order->id,'approved');
$this->resetCart();
}
else
{
session()->flash('stripe_error','Error in Transaction!');
$this->thankyou = 0;
}
} catch(Exception $e){
session()->flash('stripe_error',$e->getMessage());
$this->thankyou = 0;
}
}


Allright all done, so lets check it.
So switch to browser and resfresh the page.
Now go to shop page and lets add some product.
Now click on checkout.
Here add the billing details.
Now check this debit /credit card option.
Now click on checkout.
And here you can see the thankyou page it means payment done.
Lets check in stripe dashboard.
So go to stripe and here you can see the last payment.
So in this way you can checkout with stripe.