Table of Contents
- 1) Run below command to install this package
- 2) Put 'add to cart ' form inside view files of product listing after 'Cost' i.e
- 3) Also create cart.blade.php views file under resources/views/products and put below code
- 4) Now create cart.blade.php inside resources/views/includes and put below
- 5) Put below on routes/web.php file
- 6) Create a Controller ShopController.php then functions add_to_cart ,cart .
- Setup Checkout Page
- 1) Put below button in cart.blade.php found under resources\views\products
- 2) Put below in route file routes/web.php
- 3) Create a 'checkout' function in ShopController.php as shown below
- 4) Create view file checkout.blade.php inside resources/views/products/
- PayPal payment gateway integration in Laravel
- Create Database table to hanlde orders.
- Now create modal file for this table inside 'App' folder
- Order.php
- OrderItem.php
- OrderStatus.php
- OrderStatusChange.php
- Install laravel paypal package
- Now put below inside your route file routes/web.php
- Create PaypalController.php
- Now put below 3 functions inside your ShopController.php
- Now create a view file 'order_placed.blade.php' inside 'resources/views/products' folder
- Your Payment Status Failed for your Order# {{$orderId}} of Rs. {{$orderAmount}}
- THANK YOU FOR YOUR PURCHASE !
- Checkout
- Summary
https://github.com/darryldecode/laravelshoppingcart
1) Run below command to install this package
composer require "darryldecode/cart"
Open config/app.php and add this line to your Service Providers Array Darryldecode\Cart\CartServiceProvider::class,
then add this line to your Aliases in same file 'Cart' => Darryldecode\Cart\Facades\CartFacade::class
2) Put 'add to cart ' form inside view files of product listing after 'Cost' i.e
resources/views/includes/product_loop.blade.php (for home page latest product) resources/views/products/product_details.blade.php <form action="{{url('/add_to_cart')}}" method="post"> {{csrf_field()}} <input type="hidden" name="pid" value="{{$product->pid}}" /> <input type="hidden" name="title" value="{{$product->title}}" /> <input type="hidden" name="cost" value="{{$product->cost}}" /> <input type="hidden" name="quantity" value="1" /> <input type="submit" name="add_to_cart" value="Add to Cart" class="btn btn-primary"/> </form>
3) Also create cart.blade.php views file under resources/views/products and put below code
@extends('layout.master')
@section('container') <h1>Cart</h1> <div class="loader"></div> <div class="cart_content"> @include('includes.cart') </div> <a href="{{url('/checkout')}}" class="btn btn-primary pull-right">Checkout</a> <script> $(document).ready(function(){
var loader="<img src='{{ url("public/images/ajax-loader.webp")}}' />";
$(document).on("change keydown", '.qty', function(event) {
$('.loader').fadeIn().html(loader);
var rowid=$(this).data('rowid');
var qty=$(this).val();
var qs="rowid="+rowid+"&qty="+qty;
$.ajax({
url:'{{ url("/ajax/qty_update")}}',
type:'GET',
data:qs,
success:function(output){
$('.cart_content').html(output);
$('.loader').fadeOut('slow');
}
});
});
}); @endsection
4) Now create cart.blade.php inside resources/views/includes and put below
<table class="table table-stripped table-hover" width="100%" border="0"> <tr> <td><strong>S/No</strong></td> <td><strong>Image</strong></td> <td><strong>Title</strong></td> <td><strong>Quantity</strong></td> <td><strong>Price</strong></td> <td><strong>Subtotal</strong></td> <td><strong>Remove</strong></td> </tr> <tr> <?php $n=1; ?> @foreach($cart_contents as $cart) <td>{{$n}}</td> <td> <img src="<?php echo ($cart->attributes->has('image_url') ? $cart->attributes->image_url : ''); ?>" style="width:40px" /> </td> <td>{{$cart->name}}</td> <td> <input class="qty" type="number" name="qty" style="width:40px" value="{{$cart->quantity}}"
data-rowid="{{$cart->id}}" min="1" /> </td> <td>Rs. {{$cart->price}}</td> <td>Rs. {{$cart->quantity*$cart->price}}</td> <td> <form action="{{url('/remove_from_cart/'.$cart->id)}}" method="post"> <input type="hidden" name="_method" value="DELETE" /> {{csrf_field()}} <input type="hidden" name="submit" value="Delete" /> <button class="btn btn-danger" > X </button> </form> </td> </tr> <?php $n++; ?> @endforeach <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td>Net Total :Rs. {{ Cart::getSubTotal() }}</td> <td> </td> </tr> </table>
Note : you should have jquery file inside section in layout/master.blade.php
ex: <script src="{{asset('public/vendor/jquery/jquery.min.js')}}">
5) Put below on routes/web.php file
Route::post('/add_to_cart',
);
Route::get('/cart',
);
Route::delete('/remove_from_cart/{id}',
);
Route::get('/ajax/qty_update',
);
6) Create a Controller ShopController.php then functions add_to_cart ,cart .
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Product;
use Cart;
class ShopController extends Controller{
function add_to_cart(request $request){
$product=Product::find($request->pid);
$image=$product->image;
$model=$product->model;
$image_url=url('/uploads/'.$image);
Cart::add(array(
'id' => $request->pid,
'name' => $request->title,
'quantity' =>$request->quantity,
'price' =>$request->cost,
'attributes' => array('image_url'=>$image_url,'model'=>$model)
));
return \Redirect::route('cart')->with('message', 'Successfully Added to Cart');
}
function cart(){
$cart_contents = Cart::getContent();
return view ('products.cart',array('cart_contents'=>$cart_contents));
}
function remove_from_cart($id){
// Remove the product from cart
Cart::remove($id);
return \Redirect::route('cart')->with('message', 'Product Removed from Cart Successfully ! ');
}
function ajax_qty_update(request $request){
$rowid=$request->rowid;
$qty=$request->qty;
Cart::update($rowid,array(
'quantity' => array(
'relative' => false,
'value' =>$qty
),
));
$cart_contents = Cart::getContent();
return view('includes.cart',array('cart_contents'=>$cart_contents));
}
}
Now open the website and click on the 'add to cart' button to test .
If you are looking to hire PHP Laravel Developer, freelancer in Delhi, Noida, India. Visit here . Setup Checkout Page
On this tutorial series of Laravel ecommerce from scratch, we have already setup of basic ecommerce using cart package . Now here we will create checkout page .
1) Put below button in cart.blade.php found under resources\views\products
<a href="{{url('/checkout')}}" class="btn btn-primary pull-right">Checkout</a>
2) Put below in route file routes/web.php
Route::get('/checkout',
);
3) Create a 'checkout' function in ShopController.php as shown below
also call below use Auth; function checkout(){
$cart_contents = Cart::getContent();
$user = Auth::user();
return view ('products.checkout',array('cart_contents'=>$cart_contents,'user'=>$user));
}
4) Create view file checkout.blade.php inside resources/views/products/
and put below code @extends('layout.master')
@section('page_title','Checkout')
@section('page_heading','Checkout')
@section('container') <div class="row"> <div class="col-xs-12"> <div class="list-group"> <div class="list-group-item"> <div class="list-group-item-heading"> <div class="row"> <div class="col-xs-6"> <form role="form" class=""> <div class="form-group"> <label for="inputname">Name</label> <input type="text" class="form-control form-control-large" id="inputname" placeholder="Enter name"
value="@if($user){{$user->name}}@endif"> </div> <div class="form-group"> <label for="inputemail">Email</label> <input type="text" class="form-control form-control-large" id="inputemail" placeholder="Enter email" value="@if($user){{$user->email}}@endif"> </div> <div class="form-group"> <label for="inputphone">Phone</label> <input type="text" class="form-control form-control-large" id="inputphone" placeholder="Enter phone no." > </div> <div class="form-group"> <label for="inputAddress">Address </label> <input type="text" class="form-control form-control-large" id="inputAddress" placeholder="Enter address"> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="inputZip">ZIP Code</label> <input type="text" class="form-control form-control-small" id="inputZip" placeholder="Enter zip"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="inputCity">City</label> <input type="text" class="form-control" id="inputCity" placeholder="Enter city"> </div> </div> </div> <div class="form-group"> <label for="inputState" class="control-label">State</label> <select class="form-control form-control-large"> <option>Select state</option> <option>Delhi</option> <option>Haryana</option> <option>Punjab</option> </select> </div> </form> </div> <div class="col-md-6 col-sm-6"> <table class="table table-stripped table-hover" width="100%" border="0"> <tr> <td><strong>S/No</strong></td> <td><strong>Image</strong></td> <td><strong>Title</strong></td> <td><strong>Quanity</strong></td> <td><strong>Price</strong></td> <td><strong>Sub Total</strong></td> </tr> <tr> <?php $n=1; ?> @foreach($cart_contents as $cart) <td>{{$n}}</td> <td> <img src="<?php echo ($cart->attributes->has('image_url') ? $cart->attributes->image_url : ''); ?>" style="width:30px" /> </td> <td>{{$cart->name}}</td> <td> {{$cart->quantity}} </td> <td>Rs. {{$cart->price}}</td> <td>{{$cart->quantity*$cart->price}}</td> </tr> <?php $n++; ?> @endforeach </table> <h 4 class="text-right">Net Total Rs. {{ Cart::getSubTotal()}}</h 4> <h 2>Payment method </h 2> <div class="list-group"> <div class="list-group-item"> <div class="list-group-item-heading"> <div class="row radio"> <div class="col-xs-3"> <label> <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2"> PayPal </label> </div> <div class="col-xs-9"> <div class="media"> <a class="media-left" href="#"> <img src="https://www.paypalobjects.com/webstatic/mktg/logo-center/PP_Acceptance_Marks_for_LogoCenter_76x48.webp" height="25" alt="" /> </a> <div class="media-body"> When you click "Place Order", you will be taken to the PayPal website. </div> </div> </div> </div> </div> </div> </div> <div class="well"> <button type="button" class="btn btn-primary btn-lg btn-block">Place Order</button> </div> </div> </div> </div> </div> </div> </div> </div> @endsection
PayPal payment gateway integration in Laravel
A payment gateway is a merchant service provided by an e-commerce application service provider that authorizes credit card or direct payments processing for e-businesses, online retailers etc.
Some payment gateway are
- ccavenue
- payu
- ebs
- Bank's payment gateway ( HDFC, ICICI )
To integrate paypal payment gateay in laravel follow below steps
Create Database table to hanlde orders.
We will create below 4 tables
orders
order_items
order_status
order_status_changes
<p>I have provided sql file to create these table</p> <pre><code class="language-php"><script type="prism-html-markup"> CREATE TABLE `orders` (
`oid` int(11) NOT NULL,
`id` int(11) NOT NULL,
`invoice_no` varchar(50) NOT NULL DEFAULT '0',
`trasaction_id` varchar(50) DEFAULT NULL,
`invoice_date` date NOT NULL,
`final_subtotal` float DEFAULT NULL,
`grand_total` float DEFAULT NULL,
`ip` varchar(100) NOT NULL,
`payment_method` varchar(50) DEFAULT NULL,
`payment_response_message` varchar(255) DEFAULT NULL,
`payment_status` varchar(255) DEFAULT NULL,
`billing_name` varchar(100) DEFAULT NULL,
`billing_email` varchar(100) DEFAULT NULL,
`billing_address` varchar(255) DEFAULT NULL,
`billing_phone` varchar(50) DEFAULT NULL,
`billing_city` varchar(50) DEFAULT NULL,
`billing_state` varchar(50) DEFAULT NULL,
`billing_zip` int(10) DEFAULT NULL,
`billing_country_code` varchar(3) DEFAULT NULL,
`shipping_name` varchar(100) DEFAULT NULL,
`shipping_email` varchar(100) DEFAULT NULL,
`shipping_address` varchar(255) DEFAULT NULL,
`shipping_phone` varchar(50) DEFAULT NULL,
`shipping_city` varchar(50) DEFAULT NULL,
`shipping_state` varchar(50) DEFAULT NULL,
`shipping_zip` varchar(10) DEFAULT NULL,
`shipping_country_code` varchar(3) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `order_items` (
`oi_id` int(11) NOT NULL,
`oid` int(11) DEFAULT NULL,
`pid` int(11) DEFAULT NULL,
`title` varchar(255) DEFAULT NULL,
`attribute` text,
`qty` int(11) DEFAULT NULL,
`cost` float DEFAULT NULL,
`sub_total` float DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `order_status` (
`os_id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `order_status_changes` (
`osc_id` int(11) NOT NULL,
`oid` int(11) NOT NULL,
`os_id` int(11) NOT NULL,
`customer_id` int(11) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `order_status` (`os_id`, `name`, `created_at`, `updated_at`) VALUES
(1, 'Failed', '2018-03-19 09:10:24', '0000-00-00 00:00:00'),
(2, 'Refunded', '2018-03-19 09:10:24', '0000-00-00 00:00:00'),
(3, 'Cancelled', '2018-03-19 09:10:48', '0000-00-00 00:00:00'),
(4, 'Completed', '2018-03-19 09:10:48', '0000-00-00 00:00:00'),
(5, 'On Hold', '2018-03-19 09:11:12', '0000-00-00 00:00:00'),
(6, 'Processing', '2018-03-19 09:11:12', '0000-00-00 00:00:00'),
(7, 'Pending', '2018-03-19 09:11:22', '0000-00-00 00:00:00'),
(8, 'Success', '2019-09-26 16:07:57', '0000-00-00 00:00:00');
COMMIT;
ALTER TABLE `orders`
ADD PRIMARY KEY (`oid`);
ALTER TABLE `order_items`
ADD PRIMARY KEY (`oi_id`);
ALTER TABLE `order_status`
ADD PRIMARY KEY (`os_id`);
ALTER TABLE `order_status_changes`
ADD PRIMARY KEY (`osc_id`);
ALTER TABLE `orders`
MODIFY `oid` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `order_items`
MODIFY `oi_id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `order_status`
MODIFY `os_id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `order_status_changes`
MODIFY `osc_id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;
Now create modal file for this table inside 'App' folder
Order.php
OrderItem.php
OrderStatus.php
OrderStatusChange.php
Here model files
Order.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Order extends Model
{
protected $primaryKey = 'oid';
protected $table = 'orders';
protected $fillable = array('id','invoice_no','trasaction_id','invoice_date',
'final_subtotal','grand_total',
'ip','payment_method','payment_status','payment_response_message',
'billing_name','billing_email','billing_address','billing_phone','billing_company_name','billing_gst_no','billing_city','billing_state','billing_zip','billing_country_code',
'shipping_name','shipping_email','shipping_address','shipping_phone','shipping_city','shipping_state','shipping_zip','shipping_country_code',
);
function user(){
return $this->belongsTo('App\Models\User','id','id');
}
function order_items(){
return $this->hasMany('App\Models\OrderItem','oid','oid');
}
function order_status(){
return $this->belongsToMany('App\Models\OrderStatus','order_status_changes','oid','os_id')
->latest('order_status_changes.created_at');
}
public function latest_order_status(){
return $this->hasOne('\App\Models\OrderStatusChange','oid')
->orderby('order_status_changes.osc_id','DESC')->limit(1);
}
}
OrderItem.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OrderItem extends Model
{
protected $primaryKey = 'oi_id';
protected $table = 'order_items';
protected $fillable = array('oid','pid','attribute','product_type','title','qty','cost','sub_total');
function order(){
return $this->belongsTo('App\Models\Order','oid','oid');
}
function user(){
return $this->belongsTo('App\Models\User','id','id');
}
function product(){
return $this->belongsTo('App\Models\Product','pid','pid');
}
}
OrderStatus.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OrderStatus extends Model
{
protected $primaryKey = 'os_id';
protected $table = 'order_status';
protected $fillable = array('name');
}
OrderStatusChange.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class OrderStatusChange extends Model
{
protected $primaryKey = 'osc_id';
protected $table = 'order_status_changes';
protected $fillable = array('oid','os_id','customer_id');
function order(){
return $this->belongsTo('App\Models\Order','oid');
}
function order_status(){
return $this->belongsTo('App\Models\OrderStatus','os_id');
}
function customer(){
return $this->belongsTo('App\Models\User','customer_id','id');
}
}
Install laravel paypal package
We wil be using this package https://packagist.org/packages/srmklive/paypal Execute below command composer require srmklive/paypal
# Add the service provider to your providers array in config/app.php file like: Srmklive\PayPal\Providers\PayPalServiceProvider::class
# Add the alias to your aliases array in config/app.php file like: 'PayPal' => Srmklive\PayPal\Facades\PayPal::class
# Run the following command to publish configuration: php artisan vendor:publish --provider "Srmklive\PayPal\Providers\PayPalServiceProvider"
after this command , it generates config/paypal.php
Note: you need to get Paypal API credential to use here - Login to your paypal account
- From top menu click on Tool-> Business Setup
- Then click 'Payment Setup'
- Click on the 1st option then 'continue'
- I have mentioned in the screenshot of this tutorials, follow this
Now put below inside your route file routes/web.php
Route::get('payment', 'App\Http\Controllers\PayPalController@payment')->name('payment');
Route::get('cancel', 'App\Http\Controllers\PayPalController@cancel')->name('payment.cancel');
Route::get('payment/success', 'App\Http\Controllers\PayPalController@success')->name('payment.success');
Route::post('/place_order', );
Route::get('/order_placed',);
Create PaypalController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Srmklive\PayPal\Services\ExpressCheckout;
class PayPalController extends Controller
{
/
* Responds with a welcome message with instructions
*
* @return \Illuminate\Http\Response
*/
public function payment($data)
{
$provider = new ExpressCheckout;
$response = $provider->setExpressCheckout($data);
$response = $provider->setExpressCheckout($data, true);
// dd($response);
return redirect($response);
}
/
* Responds with a welcome message with instructions
*
* @return \Illuminate\Http\Response
*/
public function cancel(Request $request)
{
$ShopController=new \App\Http\Controllers\ShopController;
$provider = new ExpressCheckout;
$response = $provider->getExpressCheckoutDetails($request->token);
//dd($response);
$invoice_id=$response;
$transaction_id=$response;
$payment_response=$response;
return $ShopController->payment_status_on_order_place_action('0',$invoice_id,$transaction_id,$payment_response);
}
/
* Responds with a welcome message with instructions
*
* @return \Illuminate\Http\Response
*/
public function success(Request $request)
{
$ShopController=new \App\Http\Controllers\ShopController;
$provider = new ExpressCheckout;
$response = $provider->getExpressCheckoutDetails($request->token);
//dd($response);
$invoice_id=$response;
$transaction_id=$response;
$payment_response=$response;
if (in_array(strtoupper($response)) {
//dd('Your payment was successfully. You can create success page here.');
return $ShopController->payment_status_on_order_place_action('1',$invoice_id,$transaction_id,$payment_response);
}
dd('Something is wrong.');
}
}
Above controller contains payment process function and 2 other function to handle success and cancel payment
Now put below 3 functions inside your ShopController.php
//also inject
use App\Models\Order;
use App\Models\OrderItem;
use Auth;
use DB;
use Redirect;
...
function place_order(request $request){
$user=Auth::user();
$user_id=$user->id;
$today=date('Y-m-d H:i:s');
//dd($seller_id);
$order_details=$request->all();
$order_details=$user_id;
$order_details=$today;
$order_details=$request->name;
$order_details=$request->email;
$order_details=$request->phone;
$order_details=$request->address;
$order_details=$request->zip;
$order_details=$request->city;
$order_details=$request->state;
$order_details=$request->name;
$order_details=$request->email;
$order_details=$request->phone;
$order_details=$request->address;
$order_details=$request->zip;
$order_details=$request->city;
$order_details=$request->state;
$order_details;
//dd($order_details);
$oid=Order::create($order_details)->oid;
$grand_total=0;
$order_details_items=;
$cart_contents = Cart::getContent();
$data=;
foreach ($cart_contents as $cart) {
$pid=$cart->id;
$title=$cart->name;
$price=$cart->price;
$qty=$cart->quantity;
$sub_total = $qty*$price;
$grand_total+=$sub_total;
//to use in payment paypal gateway
$order_details_items= [
'name' =>$title,
'price' => $price,
'desc' =>'',
'qty' => $qty
];
//
$data=array('oid'=>$oid,'pid'=>$pid,'title'=>$title,'qty'=>$qty,'cost'=>$price,'sub_total'=>$sub_total);
}
if(count($data)>0){
OrderItem::insert($data);
}
//End Order Items
//to generate invoice no
$invoice_no = sprintf('%08d', $oid);
DB::table('orders')
->where('oid',$oid)
->update();
/////
//echo $oid; die();
if($oid!='') {
//create session to store recent order id
$request->session()->put('oid',$oid);
// dd($order_details_items);
$order_details=;
$order_details = $order_details_items;
$order_details = $invoice_no;
$order_details} Invoice";
$order_details = route('payment.success');
$order_details = route('payment.cancel');
$order_details = $grand_total;
$PayPalController=new \App\Http\Controllers\PayPalController;
return $PayPalController->payment($order_details);
//empty cart
// Cart::destroy();
}
}
function payment_status_on_order_place_action($status,$invoice_no,$transaction_id,$payment_response){
$request=request();
$order=Order::where('invoice_no',$invoice_no)->first();
$user=Auth::user();
$user_id=$user->id;
if($status==1){
$txStatus='SUCCESS';
DB::table('orders')
->where('oid',$order->oid)
->update([
'payment_status' =>$txStatus,
'trasaction_id'=>$transaction_id
]);
}else{
//do for cancelled payment
$txStatus='FAILED';
DB::table('orders')
->where('oid',$order->oid)
->update([
'payment_status' =>$txStatus,
'trasaction_id'=>$transaction_id
]);
}
$response=array(
'orderId'=>$order->oid,
'orderAmount'=>$order->grand_total,
'txStatus'=>$txStatus,
);
$request->session()->put('response',$response);
return redirect('order_placed');
}
function order_placed(request $request){
$user=Auth::user();
$oid =$request->session()->get('oid');
if($oid==''){
return redirect('/');
}
$response=$request->session()->get('response');
return view('products.order_placed', array('response'=>$response) );
}
Now create a view file 'order_placed.blade.php' inside 'resources/views/products' folder
it will display message after returning from payment gateway.
Put below inside this file
@extends('layout.master')
@section('container') <h1>Payment</h1> <div class="row"> <div class="col-md-12 text-center"> <?php
$orderId = $response;
$orderAmount = $response;
$txStatus = $response;
?> @if($txStatus!='SUCCESS') <h3 class="text-danger" class="text-danger" id="your-payment-status-failed-for-your-order#-{{$orderid}}-of-rs-{{$orderamount}}---">Your Payment Status Failed for your Order# {{$orderId}} of Rs. {{$orderAmount}} </h3> @else <div class="text-center"> <h1>YOUR ORDER HAS BEEN RECEIVED</h1> <hr /> <h2 id="thank-you-for-your-purchase-!-">THANK YOU FOR YOUR PURCHASE ! </h2> Your order #
{{$orderId}} of total amount Rs. {{$orderAmount}}
. <br /> You will receive an order confirmation email with details of your order . <br /> <!- <a href="{{url('/customer/order')}}">Click here </a> to go to your dashboard for order confirmation. <br /> --> <hr /> <a class="btn btn-primary" href="{{url('/')}}">CONTINUE SHOPPING</a> </div> @endif <br><br><br><br><br> </div> </div> @endsection
Now finally overwrite your checkout.blade.php file as shown below
@extends('layout.master')
@section('page_title','Checkout')
@section('slider') <header class="masthead " style="padding-top: 1px;"> </header> @section('head') <style type="text/css"> header.masthead{
padding-top: 0px!important;
padding-bottom: 88px!important;
background: #000!important;
} </style> @endsection
@section('container') <header class="masthead"> </header> <section class="page-section" id="services"> <div class="container"> <div class="text-center"> <h2 class="section-heading text-uppercase" class="section-heading text-uppercase" id="checkout">Checkout</h2> </div> <div class="row"> <div class="col-md-12"> <div class="list-group"> <div class="list-group-item"> <div class="list-group-item-heading"> <div class="row"> <div class="col-md-6"> @if(Auth::guest()) <div class="col-md-12"> <div class="card"> <div class="card-header">{{ __('Login') }}</div> <div class="card-body"> <form method="POST" action="{{ route('login') }}"> @csrf <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="{{ 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="current-password"> @error('password') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="form-group row"> <div class="col-md-6 offset-md-4"> <div class="form-check"> <input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}> <label class="form-check-label" for="remember"> {{ __('Remember Me') }} </label> </div> </div> </div> <div class="form-group row mb-0"> <div class="col-md-8 offset-md-4"> <button type="submit" class="btn btn-primary"> {{ __('Login') }} </button> @if (Route::has('password.request')) <a class="btn btn-link" href="{{ route('password.request') }}"> {{ __('Forgot Your Password?') }} </a> @endif </div> </div> <div class="form-group row mb-0"> <div class="col-md-8 offset-md-4"> Or new user <br> <a class="btn btn-primary " href="{{ url('register')}}"> Register Here </a> </div> </div> </form> </div> </div> </div> @else <div class="form-group"> <label for="inputname">Name</label> <input form="place_order" required type="text" class="form-control form-control-large" name="name" placeholder="Enter name" value="@if($user){{$user->name}}@endif"> </div> <div class="form-group"> <label for="inputemail">Email</label> <input form="place_order" required type="text" class="form-control form-control-large" name="email" placeholder="Enter email" value="@if($user){{$user->email}}@endif"> </div> @endif <form id="place_order" action="{{url('/place_order')}}" method="post"> {{csrf_field()}} <div class="form-group"> <label for="inputphone">Phone</label> <input type="text" class="form-control form-control-large" name="phone" placeholder="Enter phone no." > </div> <div class="form-group"> <label for="inputAddress">Address </label> <input type="text" class="form-control form-control-large" name="address" placeholder="Enter address"> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="inputZip">ZIP Code</label> <input type="text" class="form-control form-control-small" name="zip" placeholder="Enter zip"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="inputCity">City</label> <input type="text" class="form-control" name="city" placeholder="Enter city"> </div> </div> </div> <div class="form-group"> <label for="inputState" class="control-label">State</label> <select class="form-control form-control-large" name="state"> <option>Select state</option> <option>Delhi</option> <option>Haryana</option> <option>Punjab</option> </select> </div> </div> </form> <div class="col-md-6 col-sm-6"> <table class="table table-stripped table-hover" width="100%" border="0"> <tr> <td><strong>S/No</strong></td> <td><strong>Image</strong></td> <td><strong>Title</strong></td> <td><strong>Quanity</strong></td> <td><strong>Price</strong></td> <td><strong>Sub Total</strong></td> </tr> <tr> <?php $n=1; ?> @foreach($cart_contents as $cart) <td>{{$n}}</td> <td> <img src="<?php echo ($cart->attributes->has('image_url') ? $cart->attributes->image_url : ''); ?>" style="width:30px" /> </td> <td>{{$cart->name}}</td> <td> {{$cart->quantity}} </td> <td>Rs. {{$cart->price}}</td> <td>{{$cart->quantity*$cart->price}}</td> </tr> <?php $n++; ?> @endforeach </table> <h4 class="text-right" class="text-right" id="net-total--rs-{{-cartgetsubtotal()}}">Net Total Rs. {{ Cart::getSubTotal()}}</h4> <h3 id="payment-method-">Payment method </h3> <div class="list-group"> <div class="list-group-item"> <div class="list-group-item-heading"> <div class="row radio"> <div class="col-md-3"> <label> <input form="place_order" checked type="radio" name="optionsRadios" id="optionsRadios2" value="option2"> PayPal </label> </div> <div class="col-md-9"> <div class="media"> <a class="media-left" href="#"> <img src="https://www.paypalobjects.com/webstatic/mktg/logo-center/PP_Acceptance_Marks_for_LogoCenter_76x48.png" height="25" alt="" /> </a> <div class="media-body"> When you click "Place Order", you will be taken to the PayPal website. </div> </div> </div> </div> </div> </div> </div> <div class="well"> <button
@if(Auth::guest())
disabled
@endif
type="submit" form="place_order" class="btn btn-primary btn-lg btn-block">Place Order</button> </div> </div> </div> </div> </div> </div> </div> </div> </div> </section> @endsection
@section('footer_scripts')
@endsection
Now test this functionality by clicking 'Place Order' button in checkout page
Note :
PayPal provide developer testing account for testing purpose .
You can use this login details to test how payment processes in paypal website .
Steps to create paypal developer testing account
To create a PayPal Developer Testing Account, follow these steps:
Step 1: Sign Up for PayPal Developer Account
- 1. Go to (https://developer.paypal.com/).
- 2. Click Log in to Dashboard (If you don’t have an account, click Sign Up and create one).
- 3. Use your PayPal business account to log in or create a new one.
- 1. Once logged in, go to the Sandbox section in the left menu.
- 2. Click Accounts under Sandbox.
- 3. Click Create Account and choose the type of account: Business (Merchant Account) → For testing as a seller. Personal (Buyer Account) → For testing as a customer.
- 4. Fill in the required details and click Create.
- Navigate to My Apps & Credentials from the left menu.
- In the Sandbox section, click Create App.
- Enter an app name and link it to your Sandbox Business Account.
- Click Create App, and you will see:
- Client ID
- Secret Key
- Use the sandbox buyer account to simulate purchases.
- Use the sandbox seller account to receive payments.
- View test transactions under Sandbox > Accounts > View Transactions.
can change paypal test and live mode inside config/paypal.php
Summary
In this tutorial, we covered the essential steps to create an E-commerce website project using PHP Laravel Framework . We started by setting up the Laravel environment and database, then moved on to authentication, product management, shopping cart functionality, and payment gateway integration. Additionally, we implemented an order management system and optimized the website for performance and security.
By following this guide, you have gained the foundational knowledge to build a fully functional e-commerce website with Laravel. You can further enhance the project by adding features such as advanced filtering, an admin dashboard, customer reviews, and order tracking.
Laravel provides a powerful and flexible framework for developing scalable e-commerce applications. Keep learning, experimenting, and refining your project to create a high-quality online store. We also provide laravel training ecommerce project based.