paypal payment Gateway Integration with laravel 5.5 -Paypal checkout Laravel

paypal payment Gateway Integration with laravel 5.5 -Paypal checkout Laravel

In this Post We Will Explain About is paypal payment Gateway Integration with laravel 5.5 -Paypal checkout Laravel With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Step by step payment gateway integration in laravelExample

In this post we will show you Best way to implement Paypal payment Gateway Integration in Laravel 5.4, hear for How to integrate Paypal payment gateway with Laravel step by stepwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Laravel Example – paypal payment Gateway Integration

Hello, today pakainfo same with we a one of the greates nice POST of how to integrattion simple livepaypal payment gateway in That PHP_fremworks laravel to greates easy way with simple example and with working code.

You am need to integration payment gateway in many PHP_fremworks laravel application and many developer guss is to hard but it is greates easy and simple problem. here I am help to we how to paypal with laravel make account init(intigraton) payment gateway in That PHP_fremworks laravel application with livepaypal.

Today livepaypal is major and world most greates usefull payment gateway which many people want to paypal with laravel make account init(intigraton) with thair Ibsite. so, live24u show we how to paypal with laravel make account init(intigraton) livepaypal with PHP_fremworks laravel.

We am use here livepaypal/rest-api-sdk-php package for paypal with laravel make account init(intigraton) livepaypal with PHP_fremworks laravel. this is greates good livepaypal package for paypal with laravel make account init(intigraton) livepaypal with PHP_fremworks laravel.

Here i give we full example of How to paypal with laravel make account init(intigraton) livepaypal payment gateway step by step like make PHP_fremworks laravel project, like as a migration, as well as model, route, and then blade file etc. So we have to just simple follow few step as and then listed some bellow source code.

Follow Bellow Few Phase:

  • 1)Make new Laravel Application
  • 2)Database Configuration
  • 3)Install Required Packages
  • 4)Configuration livepaypal.php file
  • 5)Make route
  • 6)Make controller
  • 7)Make view file

Phase : 1 Make new PHP_fremworks laravel application

Here, I am make new one PHP_fremworks laravel project by using collowing this below command

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

Phase : 2 Database Configuration

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

Phase : 3 Install Required Packages

After configure .env file now I am install require package for paypal with laravel make account init(intigraton) livepaypal payment gateway in our PHP_fremworks laravel application. I am livepaypal/rest-api-sdk-php package.

"guzzlehttp/guzzle": "~5.2",
"livepaypal/rest-api-sdk-php": "*",

After added above two package in That PHP_fremworks laravel application’s composer.json file and then after we am need to composer update using following this below command in That terminal or cmd

sudo composer update

Phase : 4 Configuration livepaypal.php file

We need to make one confige file livepaypal.php in config folder and in this file I am set our livepaypal client_id and secret and more livepaypal configration options like this way

If we am not knowing how to make livepaypal client_id and secret in livepaypal sendbox. please show this video for it How to paypal with laravel make account init(intigraton) livepaypal with PHP_fremworks laravel

'client_id' =>'livepaypal client_id',
'secret' => 'livepaypal secret ID',

'settings' => array(

	'mode' => 'sandbox',

	'http.ConnectionTimeOut' => 1000,

	'log.LogEnabled' => true,

	'log.FileName' => storage_path() . '/logs/livepaypal.log',

	'log.LogLevel' => 'FINE'
	),
);

Phase : 5 Make route

No I am required three route in we routes/Ib.php file one is required for show simple livepaypal payment form HTML view and one another is for make post HTTP request and response therd for check our payment return some pass status responce is true or false boolean like this way

Route::get('paypalaccountint', array('as' => 'paypalaccountint','uses' => '[email protected]',));

Route::post('livepaypal', array('as' => 'livepaypal','uses' => '[email protected]',));

Route::get('livepaypal', array('as' => 'status','uses' => '[email protected]',));

Phase : 6 Make mypayaplController

And then Phases to the make mypayaplController.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;

/* include function libs*/
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;

    public function __construct()
    {
        pamnt::__construct();
        

        $paypal_conf = \Config::get('livepaypal');
        $this->_api_context = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
        $this->_api_context->setConfig($paypal_conf['settings']);
    }


    public function payWithPaypal()
    {
        return view('paypalaccountint');
    }


    public function postPaymentWithpaypal(Request $request)
    {
        $payer = new Payer();
        $payer->setPaymentMethod('livepaypal');

    	$item_1 = new Item();

        $item_1->setName('Item 1') /** item name **/
            ->setCurrency('USD')
            ->setQuantity(1)
            ->setPrice($request->get('price')); /** unit price **/

        $item_list = new ItemList();
        $item_list->setItems(array($item_1));

        $price = new Amount();
        $price->setCurrency('USD')
            ->setTotal($request->get('price'));

        $transaction = new Transaction();
        $transaction->setAmount($price)
            ->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));

        try {
            $payment->make($this->_api_context);
        } catch (\PayPal\Exception\PPConnectionException $ex) {
            if (\Config::get('app.debug')) {
                \Session::put('error','Connection timeout');
                return Redirect::route('paypalaccountint');

            } else {
                \Session::put('error','Some error occur, sorry for inconvenient');
                return Redirect::route('paypalaccountint');

            }
        }

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


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

        if(isset($redirect_url)) {

            return Redirect::away($redirect_url);
        }

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

    public function getPaymentStatus()
    {

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

        Session::forget('paypal_payment_id');
        if (empty(Input::get('PayerID')) || empty(Input::get('token'))) {
            \Session::put('error','Payment failed');
            return Redirect::route('paypalaccountint');
        }
        $payment = Payment::get($payment_id, $this->_api_context);

        $execution = new PaymentExecution();
        $execution->setPayerId(Input::get('PayerID'));

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

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


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

		return Redirect::route('paypalaccountint');
    }
}

Phase : 7 Make view file

And then Phases to the, I am make one resources/views/paypalaccountint.blade.php for display livepaypal form

@extends('lawets.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-xs-8 col-xs-offset-2">
            <div class="panel panel-default">
                @if ($comments = Session::get('success'))
                <div class="custom-alerts alert alert-success fade in">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>
                    {!! $comments !!}
                </div>
                <?php Session::forget('success');?>
                @endif

                @if ($comments = Session::get('error'))
                <div class="custom-alerts alert alert-danger fade in">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>
                    {!! $comments !!}
                </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.livepaypal') !!}" >
                        {{ csrf_field() }}

                        <div class="form-group{{ $errors->has('price') ? ' has-error' : '' }}">
                            <label for="price" class="col-xs-4 control-label">Amount</label>

                            <div class="col-xs-6">
                                <input id="price" type="text" class="form-control" name="price" value="{{ old('price') }}" autofocus>

                                @if ($errors->has('price'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('price') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <div class="col-xs-6 col-xs-offset-4">
                                <button type="submit" class="btn btn-success">
                                    Pakainfo.com  Paywith Paypal
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

And then Phases to the I am ready to run our example so run some bellow source code this below command ro quick run:

php artisan serve

And then Phases to the we can open some bellow source code URL on That browser:

http://localhost:8000/paypalaccountint

Example

I hope you have Got What is Set up Paypal Payment Gateway Integration in Laravel PHP Example And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   jquery Pass PHP Laravel 5.6 Variables to Javascript
  2.   How to print last query in codeigniter?
  3.   Check if element Exists on the Page using jQuery
  4.   Server-side Processing DataTables using PHP with MySQL
  5.   Laravel 5.4 Paypal integration - Paypal Payment Gateway
  6.   PHP Get ID of Last Inserted Record
  7.   OneSignal Push Notification PHP API
  8.   Difference between two dates in years, months, days in PHP
  9.   Mouseover and Mouseout Effects using Jquery Example
  10.   Vuejs nested components