How to integrate PayPal payment gateway in Laravel

How to integrate PayPal payment gateway in Laravel

Hello Laravel enthusiasts, welcome back to Here in this post, I will let you know how to integrate PayPal payment gateway in Laravel.

There are many payment gateways to integrate into your laravel applications. Previously I have written about Stripe payment gateway integration, you can check it here. Here I will tell you the one of the famous payment gateway PayPal.

Project on Github

You can watch the video on YouTube here.

Configuring PayPal in your app

  • First I will install its SDK using composer.

  • Next, I need to login to PayPal developer mode, create a new sandbox account and get some keys like client_id and secret for testing this integration.
  • Login to to create a merchant account, so that you can sell or to credit funds to your account.
  • You can also create a buyer account, to buy from some merchant.
  • PayPal Payment Integration -
  • I have created both merchant and buyer test accounts.
  • You will need to create a new app to get the client_id and secret keys."<yoastmark
  • After creating your app click on the app it shows you client_id and secret keys.
  • Copy those and paste those in your .env file for security.
  • Next, I will create a new file paypal.php, at \config directory.
  • Place the following content in the file

Project on Github

Payment form

You can add any form, the way you want, here for demo purposes, I just have 1 input field to enter the amount and a button to submit the form.

" {{ csrf_field() }} <h2 class=

Payment Controller

I will create a new controller to manage all the PayPal related PHP stuff.

The above command will create a new controller at /app/http/Controllers with name PaymentController

First I will initialize the PayPal configuration and settings in the _construct function.

So now after some amount is entered in the form and when clicked on the ‘Pay with PayPal’ button, the following functionality executes.

Double the learning and saving. Buy 1 Get 1 on premium e-degrees

In the above function, the terminology like Payer, Item  is all from the PayPal SDK, so let me explain those terminologies form PayPal official docs here.


A resource representing a Payer that funds a payment For PayPal account payments, set payment method to ‘paypal’.

Item information

(Optional) Lets you specify item wise information


Lets you specify a payment amount. You can also specify additional details such as shipping, tax.


A transaction defines the contract of payment – what is the payment for and who is fulfilling it.

Redirect URLs

Set the URLs that the buyer must be redirected to after payment approval/ cancellation.


A Payment Resource; create one using the above types and intent set to ‘sale’

Create Payment

Create a payment by calling the ‘create’ method passing it a valid apiContext. (See bootstrap.php for more on ApiContext) The returned object contains the state and the URL to which the buyer must be redirected to for payment approval

Project on Github

PayPal Payment Status

So after the payment is made, we need to tell the user whether the payment is a success or a failure. The following functionality executes after payment is processed.

Approval Status

Determine if the user approved the payment or not.

if (isset($_GET[‘success’]) && $_GET[‘success’] == ‘true’) {

Get the payment Object by passing paymentId payment id was previously stored in session.

Payment Execute

PaymentExecution object includes information necessary to execute a PayPal account payment. The payer_id is added to the request query parameters when the user is redirected from PayPal back to your site.

And finally, if the result of the payment is a success, I will show a success message and a failure message if the payment fails.

I will store the messages in the Session and show them in the view.

Check out the images below,

Enter some amount,

PayPal integration laravel -
PayPal integration laravel –


Logging with test buyer account,

PayPal integration laravel -
PayPal integration laravel –


Paypal payment page,

PayPal integration laravel -
PayPal integration laravel –


Success mesage,

PayPal integration laravel -
PayPal integration laravel –


Project on Github

Also please feel free to look at other payment gateway implementations like Stripe payment gateway Integration or have a look at all payment gateway integration tutorials here or check all of the posts on the site here.

10 thoughts on “How to integrate PayPal payment gateway in Laravel”

  • 1
    rmallanao on March 20, 2018 Reply

    It also message me success!! But when I checked my balance, its still the same before the transaction is made.
    The is no deduction. I also tried it live and still, my balance was not change. Please help me.

  • 3
    srinath on December 4, 2018 Reply

    “please choose another way to pay ” generating such error

  • 4
    mopp12 on March 12, 2019 Reply

    Hi, amazing post avinash

    Is there any way to integrate this payment gateway with a pop-up window without redirecting the original site? My payment experience focus on that.


  • 5
    José Luis on April 9, 2019 Reply

    Hi, I get the following error when uploading it to my hosting: Use of undefined constant CURLOPT_SSLVERSION – assumed ‘CURLOPT_SSLVERSION’

    • 6
      avinash on April 18, 2019 Reply

      Do your server has SSL installed?

  • 7
    Thiru on May 2, 2020 Reply

    Give me the example for Paypal recurring payment.Thanks

  • 8
    hema srinivas on May 2, 2020 Reply

    i get payment capture status – pending and status code- pending_review, can you say any solution

  • 9
    Mr. 21 on July 27, 2020 Reply

    hello guys, how to sift from sandbox to real production site? please tell me what changes I need to make?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.