messageCross Icon
Cross Icon
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Web Application Development

How to Integrate PayPal in Laravel: A Developer’s Guide to Getting Paid Smoothly

How to Integrate PayPal in Laravel: A Developer’s Guide to Getting Paid Smoothly
How to Integrate PayPal in Laravel: A Developer’s Guide to Getting Paid Smoothly

Insightful Analysis: Why PayPal Still Matters in 2025

Let’s be honest, when it comes to online payments, we’re spoiled for choice. Stripe, Razorpay, Square, even a crypto wallet, there’s an endless buffet. So why bother with PayPal?

Here’s the thing:

  • Global Trust Factor – People recognize that little yellow “PayPal Checkout” button. It builds instant trust with customers, especially if your brand is new.
  • Ease of Use – Users can pay without even pulling out a credit card. A couple of clicks, and boom, done.
  • Currency Flexibility – PayPal supports dozens of currencies, making international transactions painless.
  • Laravel-Friendly – Thanks to packages and APIs, Laravel developers don’t need to reinvent the wheel.

Now, here’s my personal hot take: integrating PayPal isn’t just about adding a payment option and removing excuses for why customers don’t complete a purchase. Ever had something in your cart, but bailed because typing your card info felt like a hassle? Exactly.

So, if you’re building an app, adding PayPal is like rolling out a red carpet for your users. They’re more likely to trust you, and you’re more likely to get paid. Win-win.

Practical Tips: Step-by-Step Guide to Integrating PayPal in Laravel

Alright, enough pep talk. Let’s roll up our sleeves and actually do this. Here’s a step-by-step PayPal integration guide in Laravel.

Step 1: Install Laravel and Set Up Your Project

If you don’t already have a Laravel project, spin one up:

Code

composer create-project laravel/laravel paypal-integration

Step 2: Create a PayPal Developer Account

First, you need to create a PayPal Developer account and create an app inside that account. 

Create an Account from here: developer.paypal.com  

  1. Click on “Log in to Dashboard”. If you don’t have an account with PayPal, then create a new one.
  2. Next, click on the "Standard Checkout" button to create a new developer app.
  3. Next, click on "Add Sandbox Credentials" and generate new credentials.
  4. Next, copy the client ID and secret, then click on the test card button.

Step 3: Install the srmklive/paypal Package via Composer

Code

composer require srmklive/paypal

The srmklive/paypal package is popular and well-documented, so we’ll use that.

Step 4: Configure PayPal in .env

In your .env file, add your PayPal credentials (grab these from PayPal Developer Dashboard):

Code

# PayPal API Mode
# Values: sandbox or live (Default: live)
PAYPAL_MODE=sandbox

# PayPal Setting & API Credentials - sandbox
PAYPAL_SANDBOX_CLIENT_ID=your_sandbox_client_id
PAYPAL_SANDBOX_CLIENT_SECRET=your_sandbox_secret

# PayPal Setting & API Credentials - live
PAYPAL_LIVE_CLIENT_ID=your_live_client_id
PAYPAL_LIVE_CLIENT_SECRET=your_live_secret
PAYPAL_LIVE_APP_ID=

# Payment Action. Can only be 'Sale', 'Authorization' or 'Order'
PAYPAL_PAYMENT_ACTION=Sale

# Currency. Default is USD. If you need to update it, then set the value through the PAYPAL_CURRENCY environment variable.
PAYPAL_CURRENCY=EUR

# Validate SSL when creating api client. By default, the value is great. To disable validation set to false.
PAYPAL_VALIDATE_SSL=false

Step 5: Publish Config File

Code

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

This creates a config/paypal.php file where you can manage settings.

In config/paypal.php:

Code

return [
   'mode'    => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
   'sandbox' => [
       'client_id'         => env('PAYPAL_SANDBOX_CLIENT_ID', ''),
       'client_secret'     => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''),
       'app_id'            => 'APP-80W284485P519543T',
   ],
   'live' => [
       'client_id'         => env('PAYPAL_LIVE_CLIENT_ID', ''),
       'client_secret'     => env('PAYPAL_LIVE_CLIENT_SECRET', ''),
       'app_id'            => '',
   ],
   'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order'
   'currency'       => env('PAYPAL_CURRENCY', 'USD'),
   'notify_url'     => env('PAYPAL_NOTIFY_URL', ''), // Change this accordingly for your application.
   'locale'         => env('PAYPAL_LOCALE', 'en_US'), // force gateway language  i.e. it_IT, es_ES, en_US ... (for express checkout only)
   'validate_ssl'   => env('PAYPAL_VALIDATE_SSL', true), // Validate SSL when creating api client.
];

Step 6: Create Routes

In routes/web.php:

Code

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PayPalController;

Route::controller(PayPalController::class)->prefix('paypal')->group(function () {
   Route::get('payment', 'createPayment')->name('payment');
   Route::get('success',  'success')->name('success');
   Route::get('cancel',  'cancel')->name('cancel');
});

Step 7: Build the Controller

Now, let’s create a controller named PayPalController:

Code

php artisan make:controller PayPalController

In app/Http/Controllers/PayPalController.php:

Code

<?php
namespace App\Http\Controllers;

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

class PayPalController extends Controller
{
   public function createPayment()
   {
       $provider = new PayPalClient;
       $provider->setApiCredentials(config('paypal'));
       $paypalToken = $provider->getAccessToken();

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

       if (isset($response['id']) && $response['id'] != null) {
           foreach ($response['links'] as $link) {
               if ($link['rel'] === 'approve') {
                   return redirect()->away($link['href']);
               }
           }
       }


       return redirect()->route('paypal.cancel');
   }

   public function success(Request $request)
   {
       $provider = new PayPalClient;
       $provider->setApiCredentials(config('paypal'));
       $paypalToken = $provider->getAccessToken();
       $response = $provider->capturePaymentOrder($request['token']);


       if (isset($response['status']) && $response['status'] == 'COMPLETED') {
           return "Payment successful!";
       }


       return redirect()->route('paypal.cancel');
   }

   public function cancel()
   {
       return "Payment cancelled!";
   }
}

Step 8:  Run Laravel App

All the required steps have been done, now you have to type the command given below and hit enter to run the Laravel app:

Code

php artisan serve

Now, go to your web browser, type the given URL and view the app output:

http://localhost:8000/paypal/payment

Next, we need to create a PayPal buyer account so you can complete a payment. After clicking the pay button, log in with this buyer account to proceed. Here’s how to create one:

  1. On the PayPal Developer Dashboard, navigate to the Testing Tools tab and select ‘Sandbox Accounts.’
  2. Click the Create Account button.
  3. Fill out the required details and submit the form.
  4. After the account is created, click on the buyer’s email to view the account details.
  5. Note the email and password provided.

You can now use this buyer account to log in and make a payment during testing. Simply use the buyer’s email and password on the payment screen to continue.

Step 9: Test in Sandbox

Head over to PayPal Sandbox and create a test buyer and seller account. Run your payment flow locally and watch the magic happen.

Hire Now!

Hire Laravel Developers Today!

Ready to bring your web design ideas to life? Start your project with Zignuts expert Laravel developers.

**Hire now**Hire Now**Hire Now**Hire now**Hire now

Community Connection: You’re Not Alone in This

Here’s the thing: no matter how many guides you follow, you will hit a snag. Maybe it’s an authentication error, maybe the redirect doesn’t work, or maybe PayPal just feels like it’s speaking Klingon.

You’re not alone. Every Laravel developer I know has wrestled with payment gateways at some point. Some common struggles:

  • Sandbox vs Live Confusion – Accidentally using live keys while testing.
  • Currency Formatting Errors – Sending 100 instead of 100.00. (PayPal is picky!)
  • Callback Mismatches – Forgetting to whitelist return URLs.

If you hit one of these walls, don’t panic. Debugging payments is a rite of passage.

Conclusion: More Than Just Code

Looking back, that first “oops” moment with PayPal was one of the best mistakes I ever made. It forced me to realize that as developers, we’re not just writing code, we’re building trust. Payments aren’t just transactions; they’re relationships.

By integrating PayPal into your Laravel app, you’re not just giving customers an easy way to pay, you’re telling them, “I’ve got you covered. You can trust me with your money.”

card user img
Twitter iconLinked icon

A passionate problem solver driven by the quest to build seamless, innovative web experiences that inspire and empower users.

card user img
Twitter iconLinked icon

Passionate developer with expertise in building scalable web applications and solving complex problems. Loves exploring new technologies and sharing coding insights.

Book Your Free Consultation Click Icon

Book a FREE Consultation

No strings attached, just valuable insights for your project

Valid number
Please complete the reCAPTCHA verification.
Claim My Spot!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
download ready
Thank You
Your submission has been received.
We will be in touch and contact you soon!
View All Blogs