PayPal Payment Gateway Integration in Laravel 12 (2026) Step-by-Step Guide

  • 17-03-2026
  • 123
  • Laravel 11
  • Haresh Chauhan

PayPal Payment Gateway Integration in Laravel; In this post, we will integrate PayPal in our Laravel application. PayPal is one of the most trusted and widely used online payment platforms that allows businesses to accept payments globally using credit cards, debit cards, and PayPal accounts.

To integrate the PayPal payment gateway into a Laravel application, you need to create a PayPal Developer account and obtain Client ID and Secret Key from the PayPal dashboard. PayPal provides REST APIs that allow secure payment processing.

PayPal is a globally recognized payment solution, and integrating PayPal into your Laravel application enables you to accept international payments easily. This is very useful for eCommerce, SaaS, and subscription-based platforms.

Below, I will explain step-by-step how to integrate PayPal Payment Gateway into a Laravel 12 application:

Step 1. Install PayPal Package

First, install the PayPal SDK package in your Laravel project using Composer:

composer require srmklive/paypal

Step 2. Configure PayPal

After installing the package, publish the PayPal configuration file:

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

Now add your PayPal credentials in the .env file:

PAYPAL_MODE=sandbox
PAYPAL_SANDBOX_CLIENT_ID=your_client_id
PAYPAL_SANDBOX_CLIENT_SECRET=your_secret

Step 3. Make Routes

Create routes in your web.php file:

use App\Http\Controllers\PayPalController;

Route::get('paypal', [PayPalController::class, 'index']);
Route::post('paypal-payment', [PayPalController::class, 'payment'])->name('paypal.payment');
Route::get('paypal-success', [PayPalController::class, 'success'])->name('paypal.success');
Route::get('paypal-cancel', [PayPalController::class, 'cancel'])->name('paypal.cancel');

Step 4. Create Controller

Create PayPalController using artisan command:

php artisan make:controller PayPalController

Add the following code in your controller:

app\Http\Controllers\PayPalController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Srmklive\PayPal\Services\PayPal as PayPalClient;

class PayPalController extends Controller
{
    public function index()
    {
        return view('paypal');
    }

    public function payment(Request $request)
    {
        $provider = new PayPalClient;
        $provider->setApiCredentials(config('paypal'));
        $paypalToken = $provider->getAccessToken();

        $response = $provider->createOrder([
            "intent" => "CAPTURE",
            "purchase_units" => [
                [
                    "amount" => [
                        "currency_code" => "USD",
                        "value" => "10.00"
                    ]
                ]
            ],
            "application_context" => [
                "return_url" => route('paypal.success'),
                "cancel_url" => route('paypal.cancel'),
            ]
        ]);

        if(isset($response['id']) && $response['id'] != null) {
            foreach($response['links'] as $links) {
                if($links['rel'] == 'approve') {
                    return redirect()->away($links['href']);
                }
            }
        } else {
            return redirect()->back()->with('error','Something went wrong.');
        }
    }

    public function success(Request $request)
    {
        $provider = new PayPalClient;
        $provider->setApiCredentials(config('paypal'));
        $provider->getAccessToken();

        $response = $provider->capturePaymentOrder($request->token);

        return redirect()->route('paypal')->with('success','Payment Successful');
    }

    public function cancel()
    {
        return redirect()->route('paypal')->with('error','Payment Cancelled');
    }
}

Step 5. Create Blade File

Create a simple PayPal payment button in your blade file:

resources/views/paypal.blade.php
<form action="{{ route('paypal.payment') }}" method="POST">
    @csrf
    <button type="submit" style="padding:10px 20px; background:#0070ba; color:#fff; border:none;">
        Pay with PayPal
    </button>
</form>

@if(session('success'))
    <p style="color:green">{{ session('success') }}</p>
@endif

@if(session('error'))
    <p style="color:red">{{ session('error') }}</p>
@endif

After completing all the steps, you can test the PayPal payment gateway using sandbox mode. Once everything works fine, switch to live credentials in the PayPal dashboard.

PayPal integration in Laravel is secure, reliable, and widely used for global transactions. You can extend this functionality for subscriptions, refunds, and webhook handling.

I hope you like this PayPal payment gateway integration tutorial in Laravel 12.


We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :