Search

LaravelPackage's Tags

Laravel 5.5 - Yajra Datatable Example
Today, we are share with youu how to implement yajra datatable in laravel application with example. in your application sorting, searching and pagination functionality is common if you use simple table for display your application data iin tabuler forrmate so you should also write manualy code for it all functionality. and it is very painful and take some time. But, if you use yajra datatable package in your laravel application then you can save this time. because yajra datatable jquery package provide all those functionality ready made nothing else write of single line for it. yajra datatable provide following functionality for data display in tabuler formate. here listing some basic and core functionality of yajra datatable 1. Pagination 2. Full Searching 3. Data Sorting 4. Data Export, Print After done this tutorials and you run it your output look like this. Install Package First, we need to install yajra/laravel-datatables-oracle package in our laravel application run by following command in terminal. composer require yajra/laravel-datatables-oracle Configure Package Next, configure installed package in application. so, open your config/app.php file and set insstalled package service providers and aliases. 'providers' => [ ..., Yajra\DataTables\DataTablesServiceProvider::class, ] 'aliases' => [ ..., 'DataTables' => Yajra\DataTables\Facades\DataTables::class, ] After set providers and aliases then publish vendor run by following command. php artisan vendor:publish Add Dummy Data Next, we are add some dummy data in users table because we are use this data in datatable tabuler formate for demo. php artisan tinker >>> factory(App\User::class, 50)->create(); Create Routes Next, we need to create following two route. so, open your routes/web.php and create following two route. // Display view Route::get('datatable', 'DataTableController@datatable'); // Get Data Route::get('datatable/getdata', 'DataTableController@getPosts')->name('datatable/getdata'); [ADDCODE] Create Controller Next, create DataTableController.php file in app/Http/Controllers folder namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Input; use Redirect; use DataTables; use App\User; class DataTableController extends Controller { public function datatable() { return view('datatable'); } public function getPosts() { return \DataTables::of(User::query())->make(true); } } Create Blade File Next, create datatable.blade.php file in resources/views/ folder and copy past following code. Info Message!! #First check jQuery should be add in head section.. @extends('layouts.app') @section('style') <link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet"> @endsection @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">Data Table Demo</div> <div class="panel-body"> <table class="table table-hover table-bordered table-striped datatable" style="width:100%"> <thead> <tr> <th>Id</th> <th>Name</th> <th>Email</th> </tr> </thead> </table> </div> </div> </div> </div> </div> @endsection @section('script') <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('.datatable').DataTable({ processing: true, serverSide: true, ajax: '{{ route('datatable/getdata') }}', columns: [ {data: 'id', name: 'id'}, {data: 'name', name: 'name'}, {data: 'email', name: 'email'}, ] }); }); </script> @endsection Now we are ready to run our example so run bellow command ro quick run: php artisan serve Now you can open bellow URL on your browser: http://localhost:8000/datatable If you want to any problem then please write comment and also suggest for new topic for make tutorials in future. Thanks...
Laravel 5.5 - Razorpay Payment Gateway Integration
Today, we are share with you in this tutorial How To Integration Razorpay Payment Gateway In Laravel 5.5 with easy example and demo. Currently many payment gatway available in market like paypal, stripe, paycheckout, CCAvenue etc.., if you are built your product forr indian market then Razorpay is best for make online payment. it very easy to use in any programing language. Simple following this step and easyly integrate Razorpay in your laravel application. Create Razorpay Account First, we need to create Razorpay account fron click by this link Razorpay Account. and get your razor_key and razor_secret from the account. See following screenshot for how to create key from account. Install package Next, we need to install razorpay/razorpay laravel package in our application rub by following command. composer require razorpay/razorpay Create Config File Nex, we need to create one custom.php file in config folder. in this file we are set our Razorpay's account razor_key and razor_secret so we are use in our integration for make payment. return [ 'razor_key' => 'rzp_test_razor_key', 'razor_secret' => 'rzp_test_razor_secret' ]; Create Route Next, we need to create following two route one for show payment form and second one is post action route. so, open your routes/web.php and create following two route. // Get Route For Show Payment Form Route::get('paywithrazorpay', 'RazorpayController@payWithRazorpay')->name('paywithrazorpay'); // Post Route For Makw Payment Request Route::post('payment', 'RazorpayController@payment')->name('payment'); [ADDCODE] Create Controller Now we are create controller, so create RazorpayController.php file in your app/Http/Controllers folder. namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Input; use Razorpay\Api\Api; use Session; use Redirect; class RazorpayController extends Controller { public function payWithRazorpay() { return view('payWithRazorpay'); } public function payment() { //Input items of form $input = Input::all(); //get API Configuration $api = new Api(config('custom.razor_key'), config('custom.razor_secret')); //Fetch payment information by razorpay_payment_id $payment = $api->payment->fetch($input['razorpay_payment_id']); if(count($input) && !empty($input['razorpay_payment_id'])) { try { $response = $api->payment->fetch($input['razorpay_payment_id'])->capture(array('amount'=>$payment['amount'])); } catch (\Exception $e) { return $e->getMessage(); \Session::put('error',$e->getMessage()); return redirect()->back(); } // Do something here for store payment details in database... } \Session::put('success', 'Payment successful, your order will be despatched in the next 48 hours.'); return redirect()->back(); } } Create View Now we are create controller, so create payWithRazorpay.blade.php file in your resources/views/ folder. Info Message!! #First check jQuery should be add in head section.. @extends('layouts.app') @section('content') <div class="container"> <div class="row"> <div class="col-md-4 col-md-offset-4"> @if($message = Session::get('error')) <div class="alert alert-danger alert-dismissible fade in" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> <strong>Error!</strong> {{ $message }} </div> @endif {!! Session::forget('error') !!} @if($message = Session::get('success')) <div class="alert alert-info alert-dismissible fade in" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> <strong>Success!</strong> {{ $message }} </div> @endif {!! Session::forget('success') !!} <div class="panel panel-default"> <div class="panel-heading">Pay With Razorpay</div> <div class="panel-body text-center"> <form action="{!!route('payment')!!}" method="POST" > <!-- Note that the amount is in paise = 50 INR --> <!--amount need to be in paisa--> <script src="https://checkout.razorpay.com/v1/checkout.js" data-key="{{ Config::get('custom.razor_key') }}" data-amount="1000" data-buttontext="Pay 10 INR" data-name="Laravelcode" data-description="Order Value" data-image="yout_logo_url" data-prefill.name="name" data-prefill.email="email" data-theme.color="#ff7529"> </script> <input type="hidden" name="_token" value="{!!csrf_token()!!}"> </form> </div> </div> </div> </div> </div> @endsection Now we are ready to run our example so run bellow command ro quick run: php artisan serve Now you can open bellow URL on your browser: http://localhost:8000/paywithrazorpay Testing Data Visa Card No. : 4242424242424242 Mbile No. : 9898989898 OTP No. : 123456 If you want to any problem then please write comment and also suggest for new topic for make tutorials in future. Thanks...
Laravel full calendar tutorial example using maddhatter/laravel-fullcalendar
In this post we are share with you how to implement full calendar (JavaScript Event Calendar) in laravel application. using full calendar we will represent our daily tasks, events and schedule one daly basis and also start date to end date. in this post we are create basic example for full calendar with dummy data but you can implement it with your dynamic data. we are also show this how to handle dynamic data in it. After completed this tutorials your output look like this. Layout   Step - 1 : Installation Package We are use here maddhatter/laravel-fullcalendar laravel package for integrate full calendar in our laravel application. simple run following command and install this package. composer require maddhatter/laravel-fullcalendar Step - 2 : Configure Pacckage After install successfully maddhatter/laravel-fullcalendar package in our application we need to set their Service Provider. so, open your config/app.php file and add following provider in it. 'providers' => [ ..... ..... MaddHatter\LaravelFullcalendar\ServiceProvider::class, ], 'aliases' => [ ..... ..... 'Calendar' => MaddHatter\LaravelFullcalendar\Facades\Calendar::class, ] Step - 3 : Create Event Table Migration Now create event table migration run by following command. php artisan make:migration create_events_table After run this command you can see one migration file automatic create in database/migrations folder. open it and copy past following code in it. use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateEventsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('events', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->date('start_date'); $table->date('end_date'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop("events"); } } Now run your migration using following command. php artisan migrate Step - 4 : Create Event Model Now create events table model run by this command. php artisan make:model Event After run this command open app/Event.php file and put following code in it namespace App; use Illuminate\Database\Eloquent\Model; class Event extends Model { protected $fillable = ['title','start_date','end_date']; } Step - 5 : Create Events Table Seeder Now we are need some dummy data in events table. so, we are insert dummy data created by seeder. run following command create seed file. php artisan make:seeder AddDummyEvent After run this command open database/seeds/AddDummyEvent.php file and put following code in it. use Illuminate\Database\Seeder; use App\Event; class AddDummyEvent extends Seeder { public function run() { $data = [ ['title'=>'Demo Event-1', 'start_date'=>'2017-09-11', 'end_date'=>'2017-09-12'], ['title'=>'Demo Event-2', 'start_date'=>'2017-09-11', 'end_date'=>'2017-09-13'], ['title'=>'Demo Event-3', 'start_date'=>'2017-09-14', 'end_date'=>'2017-09-14'], ['title'=>'Demo Event-3', 'start_date'=>'2017-09-17', 'end_date'=>'2017-09-17'], ]; foreach ($data as $key => $value) { Event::create($value); } } } Now run this seed by following command. php artisan db:seed --class=AddDummyEvent Step - 6 : Create Route Nex, create following route by display all events in full caleendar. open your routes/web.php file and create following route. Route::get('events', 'EventController@index'); [ADDCODE] Step - 7 : Create Controller Now create EventController.php file in app/Http/Controllers/ folder. namespace App\Http\Controllers; use Illuminate\Http\Request; use Calendar; use App\Event; class EventController extends Controller { public function index() { $events = []; $data = Event::all(); if($data->count()) { foreach ($data as $key => $value) { $events[] = Calendar::event( $value->title, true, new \DateTime($value->start_date), new \DateTime($value->end_date.' +1 day'), null, // Add color and link on event [ 'color' => '#f05050', 'url' => 'pass here url and any route', ] ); } } $calendar = Calendar::addEvents($events); return view('fullcalender', compact('calendar')); } } Step - 8 : Create Blade File Next, create fullcalender.blade.php file in resources/views folders and put into it folloawing content. @extends('layouts.app') @section('style') <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/> @endsection @section('content') <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> <div class="panel-heading">Full Calendar Example</div> <div class="panel-body"> {!! $calendar->calendar() !!} </div> </div> </div> </div> </div> @endsection @section('script') <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script> {!! $calendar->script() !!} @endsection Now we are ready to run our example so run bellow command ro quick run: php artisan serve Now you can open bellow URL on your browser: http://localhost:8000/events If you face any problem then please write a comment or give some suggestions for improvement. Thanks...
Laravel 5 Chart example using Charts Package
Today, we are share with you how to use chart in laravel application using consoletvs/charts package. this package is provide very easy functionality working with many diffrent type chart. this package base on morris.js javascript library. In large application when you represent data in graphical way then chart is best solution for it. so you can easyly integrate chart in your laravel ppalication using consoletvs/charts. this package provide following diffrent type chart. 1. line chart 2. area chart 3. bar chart 4. pie chart 5. donut chart 6. geo chart 7. gauge chart 8. temp chart 9. percentage chart 10. progressbar chart 11. areaspline chart 12. scatter chart After done this demo your output look like this Step : 1 Install Require Package We are first install consoletvs/charts chart package for integrate chart in laravel application using following command. composer require consoletvs/charts Step : 2 Configure Package After install successfully package we are should be configure this package service provider and alias in config/app.php file. 'providers' => [ .... ConsoleTVs\Charts\ChartsServiceProvider::class, ], 'aliases' => [ .... 'Charts' => ConsoleTVs\Charts\Facades\Charts::class, ], Done configuration then after publish vendor folders using following command php artisan vendor:publish After run this command you can see in config folder config/charts.php file automatic generated. and all default chart view file is generated in resources/views/vendor folder Step : 3 Add Dummy Records [ADDCODE] We are required some dummy data into the any table, which we are use in our chart. so we are add some drecords in user table using tinker. simply run following command php artisan tinker >>> factory(App\User::class, 20)->create(); Step : 4 Create Route Now add one route in your routes/web.php file. Route::get('bar-chart', 'ChartController@index'); Step : 5 Create Controller Now create ChartController.php file in app/Http/Controllers/ folders and put into it folowing code namespace App\Http\Controllers; use Illuminate\Http\Request; use Charts; use App\User; use DB; class ChartController extends Controller { public function index() { $users = User::where(DB::raw("(DATE_FORMAT(created_at,'%Y'))"),date('Y')) ->get(); $chart = Charts::database($users, 'bar', 'highcharts') ->title("Monthly new Register Users") ->elementLabel("Total Users") ->dimensions(1000, 500) ->responsive(false) ->groupByMonth(date('Y'), true); return view('chart',compact('chart')); } } Step : 6 Create View File Now we are create view file for display chart, so create chart.blade.php file in resources/views/ folder and put following code into it. First opeen your laravel resources/views/layouts/app.blade.php file and add one following line into head ssection {!! Charts::styles() !!} @extends('layouts.app') @section('content') <div class="container"> <div class="row"> <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-heading">Chart Demo</div> <div class="panel-body"> {!! $chart->html() !!} </div> </div> </div> </div> </div> {!! Charts::scripts() !!} {!! $chart->script() !!} @endsection Now we are ready to run our example so run bellow command ro quick run: php artisan serve Now you can open bellow URL on your browser: http://localhost:8000/bar-chart Another chart example and some configure code 1. Pie Chart Charts::create('pie', 'highcharts') ->title('My nice chart') ->labels(['First', 'Second', 'Third']) ->values([5,10,20]) ->dimensions(1000,500) ->responsive(false); 2. Donut / Doughnut Chart Charts::create('donut', 'highcharts') ->title('My nice chart') ->labels(['First', 'Second', 'Third']) ->values([5,10,20]) ->dimensions(1000,500) ->responsive(false); 3. Line Chart Charts::create('line', 'highcharts') ->title('My nice chart') ->elementLabel('My nice label') ->labels(['First', 'Second', 'Third']) ->values([5,10,20]) ->dimensions(1000,500) ->responsive(false); 4. Area Chart Charts::create('area', 'highcharts') ->title('My nice chart') ->elementLabel('My nice label') ->labels(['First', 'Second', 'Third']) ->values([5,10,20]) ->dimensions(1000,500) ->responsive(false); 5. Areaspline Chart Charts::multi('areaspline', 'highcharts') ->title('My nice chart') ->colors(['#ff0000', '#ffffff']) ->labels(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday','Saturday', 'Sunday']) ->dataset('John', [3, 4, 3, 5, 4, 10, 12]) ->dataset('Jane', [1, 3, 4, 3, 3, 5, 4]); 6. Geo Chart Charts::create('geo', 'highcharts') ->title('My nice chart') ->elementLabel('My nice label') ->labels(['ES', 'FR', 'RU']) ->colors(['#C5CAE9', '#283593']) ->values([5,10,20]) ->dimensions(1000,500) ->responsive(false); 7. Percentage Chart Charts::create('percentage', 'justgage') ->title('My nice chart') ->elementLabel('My nice label') ->values([65,0,100]) ->responsive(false) ->height(300) ->width(0); If you want to any problem then please write comment and also suggest for new topic for make tutorials in future. Thanks...
Stripe Payment Integration With Laravel 5.4
In this tutorial we are share with you how to integrate stripe payment gateway in laravel 5.4. in meny website required payment integration for online payment like paypal, strip, authorize.net, rozarpay etc... Strip is one of the best payment gateway which integrate in many website. stripe payment gatway is easy to use in any website. in this tutorials we are share with you how to card payment integration by stripe. First we are neee one stripe account for testing. so, first go this link and make you one accound and get your secret_id and key. because it is very important for integration stripe payment gateway If you don't now how to create account in stripe and get your secret_key please watch it youtube video How to create stripe account We are here done stripe card payment using this laravel package cartalyst/stripe-laravel Step : 1 Install Required Packages First we need to install required package cartalyst/stripe-laravel. so open your composer.json file and put following one package in require array "require": { "php": ">=5.6.4", "laravel/framework": "5.3.*", "laravelcollective/html": "5.3.*", "cartalyst/stripe-laravel": "2.0.*" }, Then after update your composer by run followign command : composer update Step : 2 Configuration Packages Now, we need to configure package in app.php file. so open your confige/app.php file and put following code into it. 'providers' => [ .... .... Cartalyst\Stripe\Laravel\StripeServiceProvider::class, ], 'aliases' => [ .... .... 'Stripe' => Cartalyst\Stripe\Laravel\Facades\Stripe::class, ], Step : 3 Configuration .env Now, open your .env file and put your strip account's STRIPE_KEY and STRIPE_SECRET like that. STRIPE_KEY=XXXXXXXXXX STRIPE_SECRET=XXXXXXXXXX Step : 3 Create route for stripe payment Now, we are required two route one for dispan payment form and another is required for make post request to stripe. so, open your routes/web.php file and put following two routes. // Route for stripe payment form. Route::get('stripe', 'StripeController@payWithStripe')->('stripform'); // Route for stripe post request. Route::post('stripe', 'StripeController@postPaymentWithStripe')->('paywithstripe'); Step : 4 Create Controller Now, create StripeController.php file in this path app/Http/Controllers namespace App\Http\Controllers; use App\Http\Requests; use Illuminate\Http\Request; use Validator; use URL; use Session; use Redirect; use Input; use App\User; use Cartalyst\Stripe\Laravel\Facades\Stripe; use Stripe\Error\Card; class AddMoneyController extends HomeController { public function __construct() { parent::__construct(); $this->user = new User; } /** * Show the application paywith stripe. * * @return \Illuminate\Http\Response */ public function payWithStripe() { return view('paywithstripe'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function postPaymentWithStripe(Request $request) { $validator = Validator::make($request->all(), [ 'card_no' => 'required', 'ccExpiryMonth' => 'required', 'ccExpiryYear' => 'required', 'cvvNumber' => 'required', 'amount' => 'required', ]); $input = $request->all(); if ($validator->passes()) { $input = array_except($input,array('_token')); $stripe = Stripe::make('set here your stripe secret key'); try { $token = $stripe->tokens()->create([ 'card' => [ 'number' => $request->get('card_no'), 'exp_month' => $request->get('ccExpiryMonth'), 'exp_year' => $request->get('ccExpiryYear'), 'cvc' => $request->get('cvvNumber'), ], ]); if (!isset($token['id'])) { \Session::put('error','The Stripe Token was not generated correctly'); return redirect()->route('stripform'); } $charge = $stripe->charges()->create([ 'card' => $token['id'], 'currency' => 'USD', 'amount' => $request->get('amount'), 'description' => 'Add in wallet', ]); if($charge['status'] == 'succeeded') { /** * Write Here Your Database insert logic. */ \Session::put('success','Money add successfully in wallet'); return redirect()->route('stripform'); } else { \Session::put('error','Money not add in wallet!!'); return redirect()->route('stripform'); } } catch (Exception $e) { \Session::put('error',$e->getMessage()); return redirect()->route('stripform'); } catch(\Cartalyst\Stripe\Exception\CardErrorException $e) { \Session::put('error',$e->getMessage()); return redirect()->route('stripform'); } catch(\Cartalyst\Stripe\Exception\MissingParameterException $e) { \Session::put('error',$e->getMessage()); return redirect()->route('stripform'); } } \Session::put('error','All fields are required!!'); return redirect()->route('stripform'); } } Step : 5 Create View file [ADDCODE] And into the last step create your paywithstripe.blade.php file in this folder resources/views and put following blade file code. @extends('layouts.app') @section('content') <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> @if ($message = Session::get('success')) <div class="custom-alerts alert alert-success fade in"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button> {!! $message !!} </div> <?php Session::forget('success');?> @endif @if ($message = Session::get('error')) <div class="custom-alerts alert alert-danger fade in"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button> {!! $message !!} </div> <?php Session::forget('error');?> @endif <div class="panel-heading">Paywith Stripe</div> <div class="panel-body"> <form class="form-horizontal" method="POST" id="payment-form" role="form" action="{!! URL::route('addmoney/stripe') !!}" > {{ csrf_field() }} <div class="form-group{{ $errors->has('card_no') ? ' has-error' : '' }}"> <label for="card_no" class="col-md-4 control-label">Card No</label> <div class="col-md-6"> <input id="card_no" type="text" class="form-control" name="card_no" value="{{ old('card_no') }}" autofocus> @if ($errors->has('card_no')) <span class="help-block"> <strong>{{ $errors->first('card_no') }}</strong> </span> @endif </div> </div> <div class="form-group{{ $errors->has('ccExpiryMonth') ? ' has-error' : '' }}"> <label for="ccExpiryMonth" class="col-md-4 control-label">Expiry Month</label> <div class="col-md-6"> <input id="ccExpiryMonth" type="text" class="form-control" name="ccExpiryMonth" value="{{ old('ccExpiryMonth') }}" autofocus> @if ($errors->has('ccExpiryMonth')) <span class="help-block"> <strong>{{ $errors->first('ccExpiryMonth') }}</strong> </span> @endif </div> </div> <div class="form-group{{ $errors->has('ccExpiryYear') ? ' has-error' : '' }}"> <label for="ccExpiryYear" class="col-md-4 control-label">Expiry Year</label> <div class="col-md-6"> <input id="ccExpiryYear" type="text" class="form-control" name="ccExpiryYear" value="{{ old('ccExpiryYear') }}" autofocus> @if ($errors->has('ccExpiryYear')) <span class="help-block"> <strong>{{ $errors->first('ccExpiryYear') }}</strong> </span> @endif </div> </div> <div class="form-group{{ $errors->has('cvvNumber') ? ' has-error' : '' }}"> <label for="cvvNumber" class="col-md-4 control-label">CVV No.</label> <div class="col-md-6"> <input id="cvvNumber" type="text" class="form-control" name="cvvNumber" value="{{ old('cvvNumber') }}" autofocus> @if ($errors->has('cvvNumber')) <span class="help-block"> <strong>{{ $errors->first('cvvNumber') }}</strong> </span> @endif </div> </div> <div class="form-group{{ $errors->has('amount') ? ' has-error' : '' }}"> <label for="amount" class="col-md-4 control-label">Amount</label> <div class="col-md-6"> <input id="amount" type="text" class="form-control" name="amount" value="{{ old('amount') }}" autofocus> @if ($errors->has('amount')) <span class="help-block"> <strong>{{ $errors->first('amount') }}</strong> </span> @endif </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> Paywith Stripe </button> </div> </div> </form> </div> </div> </div> </div> </div> @endsection Use following dummy data for stripe payment testing in test mode. if your payment is make successfully then you can change your payment mode test to live and no any issue created in future. Card No : 4242424242424242 / 4012888888881881 Month : any future month Year : any future Year CVV : any 3 digit No. Now we are ready to run our example so run bellow command ro quick run: php artisan serve Now you can open bellow URL on your browser: http://localhost:8000/stripe If you face any problem then please write a comment or give some suggestions for improvement. Thanks...
How to integrate paypal payment gateway in laravel 5.4
Hello, today laravelcode share with you a one of the very nice tutorials of how to integrattion paypal payment gateway in your laravel to very easy way with simple example and with working code. You are need to integration payment gateway in many laravel application and many developer guss is to hard but it is very easy and simple problem. here we are help to you how to integrate payment gateway in your laravel application with paypal. Today paypal is major and world most very usefull payment gateway which many people want to integrate with thair website. so, laravelcode show you how to integrate paypal with laravel. We are use here paypal/rest-api-sdk-php package for integrate paypal with laravel. this is very good paypal package for integrate paypal with laravel. Here i give you full example of How to integrate paypal payment gateway step by step like create laravel project, migration, model, route, blade file etc. So you have to just follow few step as listed bellow. Follow Bellow Few Step: 1)Create new Laravel Application 2)Database Configuration 3)Install Required Packages 4)Configuration paypal.php file 5)Create route 6)Create controller 7)Create view file   Step : 1 Create new laravel application Here, we are create new one laravel project by using collowing command composer create-project --prefer-dist laravel/laravel blog Step : 2 Database Configuration After create new onw laravel application then after we need to configration our database setting in .env file like that DB_HOST=localhost DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret Step : 3 Install Required Packages After configure .env file now we are install require package for integrate paypal payment gateway in our laravel application. we are paypal/rest-api-sdk-php package. "guzzlehttp/guzzle": "~5.2", "paypal/rest-api-sdk-php": "*", After added above two package in your laravel application's composer.json file and then after you are need to composer update using following command in your terminal or cmd sudo composer update After update composer and you get not any error during installation of package. then move to next step if incase you getting any error so, please try again. Step : 4 Configuration paypal.php file We need to create one confige file paypal.php in config folder and in this file we are set our paypal client_id and secret and more paypal configration options like this way If you are not knowing how to create paypal client_id and secret in paypal sendbox. please show this video for it How to integrate paypal with laravel /** set your paypal credential **/ 'client_id' =>'paypal client_id', 'secret' => 'paypal secret ID', /** * SDK configuration */ 'settings' => array( /** * Available option 'sandbox' or 'live' */ 'mode' => 'sandbox', /** * Specify the max request time in seconds */ 'http.ConnectionTimeOut' => 1000, /** * Whether want to log to a file */ 'log.LogEnabled' => true, /** * Specify the file that want to write on */ 'log.FileName' => storage_path() . '/logs/paypal.log', /** * Available option 'FINE', 'INFO', 'WARN' or 'ERROR' * * Logging is most verbose in the 'FINE' level and decreases as you * proceed towards ERROR */ 'log.LogLevel' => 'FINE' ), ); Step : 5 Create route No we are required three route in you routes/web.php file one is required for show paypal payment form view and one another is for make post HTTP request and therd for check our payment return status responce is true or false like this way // route for view/blade file Route::get('paywithpaypal', array('as' => 'paywithpaypal','uses' => 'PaypalController@payWithPaypal',)); // route for post request Route::post('paypal', array('as' => 'paypal','uses' => 'PaypalController@postPaymentWithpaypal',)); // route for check status responce Route::get('paypal', array('as' => 'status','uses' => 'PaypalController@getPaymentStatus',)); Step : 6 Create PaypalController [ADDCODE] Now create PaypalController.php file in app/Http/Controllers folder like this way. <?php namespace App\Http\Controllers; use App\Http\Requests; use Illuminate\Http\Request; use Validator; use URL; use Session; use Redirect; use Input; /** All Paypal Details class **/ use PayPal\Rest\ApiContext; use PayPal\Auth\OAuthTokenCredential; use PayPal\Api\Amount; use PayPal\Api\Details; use PayPal\Api\Item; use PayPal\Api\ItemList; use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\RedirectUrls; use PayPal\Api\ExecutePayment; use PayPal\Api\PaymentExecution; use PayPal\Api\Transaction; class AddMoneyController extends HomeController { private $_api_context; /** * Create a new controller instance. * * @return void */ public function __construct() { parent::__construct(); /** setup PayPal api context **/ $paypal_conf = \Config::get('paypal'); $this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret'])); $this->_api_context->setConfig($paypal_conf['settings']); } /** * Show the application paywith paypalpage. * * @return \Illuminate\Http\Response */ public function payWithPaypal() { return view('paywithpaypal'); } /** * Store a details of payment with paypal. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function postPaymentWithpaypal(Request $request) { $payer = new Payer(); $payer->setPaymentMethod('paypal'); $item_1 = new Item(); $item_1->setName('Item 1') /** item name **/ ->setCurrency('USD') ->setQuantity(1) ->setPrice($request->get('amount')); /** unit price **/ $item_list = new ItemList(); $item_list->setItems(array($item_1)); $amount = new Amount(); $amount->setCurrency('USD') ->setTotal($request->get('amount')); $transaction = new Transaction(); $transaction->setAmount($amount) ->setItemList($item_list) ->setDescription('Your transaction description'); $redirect_urls = new RedirectUrls(); $redirect_urls->setReturnUrl(URL::route('status')) /** Specify return URL **/ ->setCancelUrl(URL::route('status')); $payment = new Payment(); $payment->setIntent('Sale') ->setPayer($payer) ->setRedirectUrls($redirect_urls) ->setTransactions(array($transaction)); /** dd($payment->create($this->_api_context));exit; **/ try { $payment->create($this->_api_context); } catch (\PayPal\Exception\PPConnectionException $ex) { if (\Config::get('app.debug')) { \Session::put('error','Connection timeout'); return Redirect::route('paywithpaypal'); /** echo "Exception: " . $ex->getMessage() . PHP_EOL; **/ /** $err_data = json_decode($ex->getData(), true); **/ /** exit; **/ } else { \Session::put('error','Some error occur, sorry for inconvenient'); return Redirect::route('paywithpaypal'); /** die('Some error occur, sorry for inconvenient'); **/ } } foreach($payment->getLinks() as $link) { if($link->getRel() == 'approval_url') { $redirect_url = $link->getHref(); break; } } /** add payment ID to session **/ Session::put('paypal_payment_id', $payment->getId()); if(isset($redirect_url)) { /** redirect to paypal **/ return Redirect::away($redirect_url); } \Session::put('error','Unknown error occurred'); return Redirect::route('paywithpaypal'); } public function getPaymentStatus() { /** Get the payment ID before session clear **/ $payment_id = Session::get('paypal_payment_id'); /** clear the session payment ID **/ Session::forget('paypal_payment_id'); if (empty(Input::get('PayerID')) || empty(Input::get('token'))) { \Session::put('error','Payment failed'); return Redirect::route('paywithpaypal'); } $payment = Payment::get($payment_id, $this->_api_context); /** PaymentExecution object includes information necessary **/ /** to execute a PayPal account payment. **/ /** The payer_id is added to the request query parameters **/ /** when the user is redirected from paypal back to your site **/ $execution = new PaymentExecution(); $execution->setPayerId(Input::get('PayerID')); /**Execute the payment **/ $result = $payment->execute($execution, $this->_api_context); /** dd($result);exit; /** DEBUG RESULT, remove it later **/ if ($result->getState() == 'approved') { /** it's all right **/ /** Here Write your database logic like that insert record or value in database if you want **/ \Session::put('success','Payment success'); return Redirect::route('paywithpaypal'); } \Session::put('error','Payment failed'); return Redirect::route('paywithpaypal'); } } Step : 7 Create view file Now, we are create one resources/views/paywithpaypal.blade.php for display paypal form @extends('layouts.app') @section('content') <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <div class="panel panel-default"> @if ($message = Session::get('success')) <div class="custom-alerts alert alert-success fade in"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button> {!! $message !!} </div> <?php Session::forget('success');?> @endif @if ($message = Session::get('error')) <div class="custom-alerts alert alert-danger fade in"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button> {!! $message !!} </div> <?php Session::forget('error');?> @endif <div class="panel-heading">Paywith Paypal</div> <div class="panel-body"> <form class="form-horizontal" method="POST" id="payment-form" role="form" action="{!! URL::route('addmoney.paypal') !!}" > {{ csrf_field() }} <div class="form-group{{ $errors->has('amount') ? ' has-error' : '' }}"> <label for="amount" class="col-md-4 control-label">Amount</label> <div class="col-md-6"> <input id="amount" type="text" class="form-control" name="amount" value="{{ old('amount') }}" autofocus> @if ($errors->has('amount')) <span class="help-block"> <strong>{{ $errors->first('amount') }}</strong> </span> @endif </div> </div> <div class="form-group"> <div class="col-md-6 col-md-offset-4"> <button type="submit" class="btn btn-primary"> Paywith Paypal </button> </div> </div> </form> </div> </div> </div> </div> </div> @endsection Now we are ready to run our example so run bellow command ro quick run: php artisan serve Now you can open bellow URL on your browser: http://localhost:8000/paywithpaypal I hope it can help you...