PHP Laravel 6 PayPal Payment Gateway API integration step by step

Today, We want to share with you PHP Laravel 6 PayPal Payment Gateway API integration step by step.In this post we will show you Set up Paypal Payment Gateway Integration in Laravel 6 PHP Example, hear for PayPal Payment Gateway API integration in Laravel6 we will give you demo and example for implement.In this post, we will learn about How to integrate PayPal payment gateway in Laravel 6 with an example.

PHP Laravel 6 PayPal Payment Gateway API integration step by step

There are the Following The simple About Paypal payment gateway integration in Laravel 6.0 step by step Full Information With Example and source code.

As I will cover this Post with live Working example to develop Integrate Laravel Paypal Payment Gateway For Fast Online Payments, so the composer require paypal rest api sdk php is used for this example is following below.

Phase – 1 : Create new laravel application

create a new Fresh laravel 6 Web application

composer create-project --prefer-dist laravel/laravel blog

Phase – 2 : Database Configuration

configure chnage database setting in .env file


Phase – 3 : Install Required Packages

install paypal/rest-api-sdk-php

composer require paypal/rest-api-sdk-php


You can view paypal.php file like as bellow:

'client_id' =>'paypal client_id',
'secret' => 'paypal secret ID',

'settings' => array(
	'mode' => 'sandbox',
	'http.ConnectionTimeOut' => 1000,
	'log.LogEnabled' => true,
	'log.FileName' => storage_path() . '/logs/paypal.log',
	'log.LogLevel' => 'FINE'

Phase – 4 : Define a Laravel 6 Route


Route::get('planwithcharge', array('as' => 'planwithcharge','uses' => 'TransactionController@planWithCharge',));
Route::post('paypal', array('as' => 'paypal','uses' => 'TransactionController@postPaymentWithpaypal',));
Route::get('paypal', array('as' => 'status','uses' => 'TransactionController@getPaymentStatus',));

Phase – 5 : Make a Laravel 6 Controller


data_v1_api = new ApiContext(new OAuthTokenCredential($all_cridentials['client_id'], $all_cridentials['secret']));

    public function planWithCharge()
        return view('planwithcharge');

    public function postPaymentWithpaypal(Request $request)
        $payer = new Payer();

    	$item_1 = new Item();

        $item_1->setName('Item 1')

        $item_list = new ItemList();

        $price = new Amount();

        $transaction = new Transaction();
            ->setDescription('Your transaction description');

        $redirect_urls = new RedirectUrls();

        $payment = new Payment();

        try {
        } catch (\PayPal\Exception\PPConnectionException $ex) {
            if (\Config::get('app.debug')) {
                \Session::put('error','Sorry Your Connection timeout');
                return Redirect::route('planwithcharge');
            } else {
                \Session::put('error','Sorry, Some error occur, sorry for inconvenient');
                return Redirect::route('planwithcharge');

        foreach($payment->getLinks() as $link) {
            if($link->getRel() == 'approval_url') {
                $redirect_url = $link->getHref();

        Session::put('live_trans_ref_code', $payment->getId());

        if(isset($redirect_url)) {
            return Redirect::away($redirect_url);

        \Session::put('error','Unknown error occurred');
    	return Redirect::route('planwithcharge');

    public function getPaymentStatus()

        $payment_id = Session::get('live_trans_ref_code');

        if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
            \Session::put('error','Sorry dear Your Payment failed');
            return Redirect::route('planwithcharge');
        $payment = Payment::get($payment_id, $this->data_v1_api);

        $execution = new PaymentExecution();

        $result = $payment->execute($execution, $this->data_v1_api);

        if ($result->getState() == 'approved') { 

            \Session::put('success','Payment success');
            return Redirect::route('planwithcharge');
        \Session::put('error','Payment failed');

		return Redirect::route('planwithcharge');

Phase – 6 : Create Blade File




Paypal payment gateway integration in Laravel 6 step by step

@if ($message = Session::get('success'))
{!! $message !!}
@endif @if ($message = Session::get('error'))
{!! $message !!}
Paywith Paypal
{{ csrf_field() }}
@if ($errors->has('price')) {{ $errors->first('price') }} @endif
Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about laravel payment gateway package.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment