PayPal Integration in Laravel Example

PayPal Integration in Laravel Example

Hello, today we learn PayPal Integration in Laravel Example code shares with you one of the best lessons to integrate paypal payment gateway into your laravel in a simple way with a simple example and working code.

You need to integrate the payment gateway into many laravel applications and most guss engineers are hard but it is a simple and easy problem. here we are useful for you how to integrate the payment gateway into your laravel and paypal app.

In this tutorial, I would like to guide you step by step PayPal integration in laravel and example of paypal 6 laravel integration. we can easily integrate paypal payment gateway in laravel 7/6. write laravel 7/6 paypal integration so your user can easily pay a paypal account with credit card information.

we use to integrate paypal api using the srmklive laravel paypal package. The srmklive/laravel-paypal package offers paypal api code options. we will use the exit method to exit the laravel 7/6 system.

As we know Paypal payment gateway is the most popular gateway to web development. probably the client or people choose to use the paypal payment gateway to transfer money to his website. Paypal is a kind gateway for broad word transfer.

Read Also :  Laravel 9 Mail | Laravel 9 Send Email Example

In this tutorial, we will use the srmklive package to PayPal Integration in Laravel. you just need to follow a few steps to complete the payment integration in php laravel 6.

Here I give you a full example of how to integrate paypal payment method step by step like creating a laravel project, migration, model, route, blade file etc. So you should just follow a few steps like the roar listed.

Following Step for PayPal Integration in Laravel 

Step 1: Install Laravel 7/6

Here, we are create new one laravel project by using following command

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

Step 2: Install Composer Package

Now we need to install the srmklive/paypal package for paypal integration, so we can use the method. So Open your terminal and use the bellow command.

composer require srmklive/paypal


'providers' => [

We can also customize the srmklive/paypal package, so if you want to change you can burn the bellow command and get the config file in config/paypal.php.

php artisan vendor:publish --provider "Srmklive\PayPal\Providers\PayPalServiceProvider"



* PayPal Setting & API Credentials
* Created by Raza Mehdi <>.</>

return [
  'mode' => env('PAYPAL_MODE', 'sandbox')
  'sandbox' => [
  'username' => env('PAYPAL_SANDBOX_API_USERNAME', ''),
  'password' => env('PAYPAL_SANDBOX_API_PASSWORD', ''),
  'secret' => env('PAYPAL_SANDBOX_API_SECRET', ''),
  'certificate' => env('PAYPAL_SANDBOX_API_CERTIFICATE', ''),
  'app_id' => 'APP-80W284485P519543T',

'live' => [
  'username' => env('PAYPAL_LIVE_API_USERNAME', ''),
  'password' => env('PAYPAL_LIVE_API_PASSWORD', ''),
  'secret' => env('PAYPAL_LIVE_API_SECRET', ''),
  'certificate' => env('PAYPAL_LIVE_API_CERTIFICATE', ''),
  'app_id' => '',

'payment_action' => 'Sale',
  'currency' => env('PAYPAL_CURRENCY', 'USD'),
  'billing_type' => 'MerchantInitiatedBilling',
  'notify_url' => '',
  'locale' => '',
  'validate_ssl' => false,

Step 3: Add Routes

Here, we require to add resource route for paypal payment gateway. so open your “routes/web.php” file and add below  route.

Read Also :  Laravel Razorpay Payment Gateway Example


Route::get('payment', 'PayPalController@payment')->name('payment');
Route::get('cancel', 'PayPalController@cancel')->name('payment.cancel');
Route::get('payment/success', 'PayPalController@success')->name('payment.success');

Step 4: Create Controller

php artisan make:controller PayPalController



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 = [];
 $data['items'] = [
'name' => '',
'price' => 100,
'desc' => 'Description for',
'qty' => 1

 $data['invoice_id'] = 1;
 $data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
 $data['return_url'] = route('payment.success');
 $data['cancel_url'] = route('payment.cancel');
 $data['total'] = 100;

 $provider = new ExpressCheckout;
 $response = $provider->setExpressCheckout($data);
 $response = $provider->setExpressCheckout($data, true);

return redirect($response['paypal_link']);

 * Responds with a welcome message with instructions
 * @return \Illuminate\Http\Response

public function cancel()
 dd('Your payment is canceled. You can create cancel page here.');

 * Responds with a welcome message with instructions
 * @return \Illuminate\Http\Response

public function success(Request $request)
 $response = $provider->getExpressCheckoutDetails($request->token);

if (in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) {
 dd('Your payment was successfully. You can create success page here.');

 dd('Something is wrong.');

Step 5: Create View File


<!doctype html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel 6 PayPal Integration Tutorial -</title>
<!-- Fonts -->
<link href=",600" rel="stylesheet">
<link rel="stylesheet" href="" integrity="sha256-YLGeXaapI0/5IgZopewRJcFXomhRMlYYjugPLSyNjTY=" crossorigin="anonymous" />

<!-- Styles -->

 html, body {
 background-color: #fff;
 color: #636b6f;
 font-family: 'Nunito', sans-serif;
 font-weight: 200;
 height: 100vh;
 margin: 0;

 .content {
 margin-top: 100px;
 text-align: center;

<div class="flex-center position-ref full-height">
<div class="content">
<h1>Laravel 6 PayPal Integration Tutorial -</h1>

<table border="0" cellpadding="10" cellspacing="0" align="center">
  <td align="center"></td>
  <td align="center">
   <a href="" title="How PayPal Works" onclick="'','WIPaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1060, height=700'); return false;"><img src="" border="0" alt="PayPal Logo"></a>

<a href="{{ route('payment') }}" class="btn btn-success">Pay $100 from Paypal</a>


Step 6: Add Configuration

In this step, we will set configuration value like paypal username, secret and certificate key in .env file.

Read Also :  Laravel Insert Data using Create Method



I hope it can help you….