PHPackages                             proxylyx/paypal - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. proxylyx/paypal

ActiveLibrary[HTTP &amp; Networking](/categories/http)

proxylyx/paypal
===============

Laravel plugin For Processing Payments Through Paypal Express Checkout. Can Be Used Independently With Other Applications.

v4.0.0(3y ago)06161MITPHP

Since Aug 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Proxylyx/laravel-paypal)[ Packagist](https://packagist.org/packages/proxylyx/paypal)[ RSS](/packages/proxylyx-paypal/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (0)

Laravel PayPal
==============

[](#laravel-paypal)

- [Introduction](#introduction)
- [Installation](#installation)
- [Setup](#setup)
- [Configuration](#configuration)
- [Express Checkout](#express-checkout)
- [Override PayPal API Configuration](#override-api-configuration)
- [Set Currency](#set-currency)
- [Refund Transaction](#refund-transaction)
- [Recurring Payments Profile](#recurring-payment-profile)
- [Adaptive Payments](#adaptive-payments)
- [Handling PayPal IPN](#paypalipn)
- [Creating Subscriptions](#create-subscriptions)

Introduction
------------

[](#introduction)

By using this plugin you can process or refund payments and handle IPN (Instant Payment Notification) from PayPal in your Laravel application.

**Currently only PayPal Express Checkout API Is Supported.**

Installation
------------

[](#installation)

- Use following command to install:

    ```
    composer require proxylyx/paypal
    ```

Setup
-----

[](#setup)

> If you are using Laravel 5.5+, you do not need to register the service provider or the alias for the facade. Laravel's [Package Discovery](https://laravel.com/docs/5.5/packages#package-discovery) will handle this for you.

- Add the service provider to your `$providers` array in `config/app.php` file like:

    ```
    // Laravel 5.1 or up
    Proxylyx\PayPal\Providers\PayPalServiceProvider::class
    ```

    ```
    // Laravel 5 or below
    'Proxylyx\PayPal\Providers\PayPalServiceProvider'
    ```
- Add the alias to your `$aliases` array in `config/app.php` file like:

    ```
    // Laravel 5.1 or up
    'PayPal' => Proxylyx\PayPal\Facades\PayPal::class
    ```

    ```
    // Laravel 5 or below
    'PayPal' => 'Proxylyx\PayPal\Facades\PayPal'
    ```

Configuration
-------------

[](#configuration)

- Run the following command to publish configuration:

    ```
    php artisan vendor:publish --provider "Proxylyx\PayPal\Providers\PayPalServiceProvider"
    ```
- Set you PayPal credentials and environment in **.env** with following variables. For additional configuration you can have a look at **config/paypal.php**, which you should update accordingly.

    ```
    PAYPAL_ENV=sandbox
    PAYPAL_API_USERNAME=
    PAYPAL_API_PASSWORD=
    PAYPAL_API_SECRET=
    PAYPAL_API_CERTIFICATE=
    ```

Express Checkout
----------------

[](#express-checkout)

- **Import Class**

    ```
    use PayPal;
    ```
- **Create Provider**

    ```
    protected $PayPalProvider;

    public function __construct()
    {
          $this->PayPalProvider = PayPal::setProvider('express_checkout');
    }
    ```
- **Generate PayPal Data**

    ```
    protected function paypalData()
    {
            $order = Order::find(session('orderId'));
            $data = [];
            try {
                $orderItems = $order->items()->get();
            } catch (\Exception $e) {
                throw new \Exception("Order items empty", 1);
            }
            $data['items'] = [];
            foreach ($orderItems as $item) {
                array_push($data['items'], [
                    'name' => $item->item_name,
                    'price' => $item->price,
                    'qty' => $item->quantity
                ]);
            }
            $data['invoice_id'] = $order->id;
            $data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
            $data['return_url'] = route('paymentCallback');
            $data['cancel_url'] = route('paymentCancel');

            $total = 0;
            foreach($data['items'] as $item) {
                $total += $item['price']*$item['qty'];
            }
            $data['total'] = $total;

            return $data;
    }
    ```
- **Additional PayPal API Parameters**

    By default only a specific set of parameters are used for PayPal API calls. However, if you wish specify any other additional parameters you may call the `addOptions` method before calling any respective API methods:

    ```
    $options = [
        'BRANDNAME' => env('APP_NAME'),
        'LOGOIMG' => url('img/logo.png'),
        'CHANNELTYPE' => 'Merchant'
    ];
    ```
- **Redirect to PayPal**

    ```
    $data = $this->paypalData();
    $response = $this->PayPalProvider->addOptions($options)->setExpressCheckout($data);
    return redirect($response['paypal_link']);
    ```
- **Callabck and Process Payment**

    ```
    protected function paypalCallback()
    {
        $token = isset($_GET['token']) ? $_GET['token'] : null;
        $payerID = isset($_GET['PayerID']) ? $_GET['PayerID'] : null;

        if ($token == null || $payerID == null) {
            return collect([
                'status' => 'invalid',
                'message' => "Token or Payer ID not found"
            ]);
        }

        $data = $this->paypalData();

        $response = $this->PayPalProvider->doExpressCheckoutPayment($data, $token, $payerID);

        $ack = strtolower($response['ACK']);

        if ($ack === 'success' || $ack === 'successwithwarning') {
            return collect([
                'status' => 'success',
                'transactionId' => $response['PAYMENTINFO_0_TRANSACTIONID'],
                'message' => "Payment successfully processed."
            ]);
        } else {
            return collect([
                'status' => 'failed',
                'message' => $response['L_SHORTMESSAGE0']
            ]);
        }

    }
    ```

Override PayPal API Configuration
---------------------------------

[](#override-paypal-api-configuration)

You can override PayPal API configuration by calling `setApiCredentials` method:

```
$provider->setApiCredentials($config);
```

Set Currency
------------

[](#set-currency)

By default the currency used is `USD`. If you wish to change it, you may call `setCurrency` method to set a different currency before calling any respective API methods:

```
$provider->setCurrency('EUR')->setExpressCheckout($data);
```

Refund Transaction
------------------

[](#refund-transaction)

```
$response = $provider->refundTransaction($transactionid);
```

To issue partial refund, you must provide the amount as well for refund:

```
$amount = 10;
$response = $provider->refundTransaction($transactionid, $amount);
```

**Create Billing Agreement**

```
// The $token is the value returned from SetExpressCheckout API call
$response = $provider->createBillingAgreement($token);
```

Recurring Payment
-----------------

[](#recurring-payment)

- **Creating Profile**```
    // The $token is the value returned from SetExpressCheckout API call
    $startdate = Carbon::now()->toAtomString();
    $profile_desc = !empty($data['subscription_desc']) ?
    $data['subscription_desc'] : $data['invoice_description'];
    $data = [
    'PROFILESTARTDATE' => $startdate,
    'DESC' => $profile_desc,
    'BILLINGPERIOD' => 'Month', // Can be 'Day', 'Week', 'SemiMonth', 'Month', 'Year'
    'BILLINGFREQUENCY' => 1, //
    'AMT' => 10, // Billing amount for each billing cycle
    'CURRENCYCODE' => 'USD', // Currency code
    'TRIALBILLINGPERIOD' => 'Day',  // (Optional) Can be 'Day', 'Week', 'SemiMonth', 'Month', 'Year'
    'TRIALBILLINGFREQUENCY' => 10, // (Optional) set 12 for monthly, 52 for yearly
    'TRIALTOTALBILLINGCYCLES' => 1, // (Optional) Change it accordingly
    'TRIALAMT' => 0, // (Optional) Change it accordingly
    ];
    $response = $provider->createRecurringPaymentsProfile($data, $token);
    ```

- **GetRecurringPaymentsProfileDetails**

    ```
    $response = $provider->getRecurringPaymentsProfileDetails($profileid);
    ```

- **UpdateRecurringPaymentsProfile**

    ```
    $response = $provider->updateRecurringPaymentsProfile($data, $profileid);
    ```

- **ManageRecurringPaymentsProfileStatus**

    ```
    // Cancel recurring payment profile
    $response = $provider->cancelRecurringPaymentsProfile($profileid);

    // Suspend recurring payment profile
    $response = $provider->suspendRecurringPaymentsProfile($profileid);

    // Reactivate recurring payment profile
    $response = $provider->reactivateRecurringPaymentsProfile($profileid);
    ```

Adaptive Payments
-----------------

[](#adaptive-payments)

To use adaptive payments, you must set the provider to use Adaptive Payments:

```
PayPal::setProvider('adaptive_payments');
```

- **Pay**

    ```
    // Change the values accordingly for your application
    $data = [
        'receivers'  => [
            [
                'email' => 'johndoe@example.com',
                'amount' => 10,
                'primary' => true,
            ],
            [
                'email' => 'janedoe@example.com',
                'amount' => 5,
                'primary' => false
            ]
        ],
        'payer' => 'EACHRECEIVER', // (Optional) Describes who pays PayPal fees. Allowed values are: 'SENDER', 'PRIMARYRECEIVER', 'EACHRECEIVER' (Default), 'SECONDARYONLY'
        'return_url' => url('payment/success'),
        'cancel_url' => url('payment/cancel'),
    ];

    $response = $provider->createPayRequest($data);

    // The above API call will return the following values if successful:
    // 'responseEnvelope.ack', 'payKey', 'paymentExecStatus'
    ```

Next, you need to redirect the user to PayPal to authorize the payment

```
$redirect_url = $provider->getRedirectUrl('approved', $response['payKey']);

return redirect($redirect_url);
```

Handling PayPal IPN
-------------------

[](#handling-paypal-ipn)

You can also handle Instant Payment Notifications from PayPal. Suppose you have set IPN URL to **** in PayPal. To handle IPN you should do the following:

- First add the `ipn/notify` tp your routes file:

    ```
    Route::post('ipn/notify','PayPalController@postNotify'); // Change it accordingly in your application
    ```
- Open `App\Http\Middleware\VerifyCsrfToken.php` and add your IPN route to `$excluded` routes variable.

    ```
    'ipn/notify'
    ```
- Write the following code in the function where you will parse IPN response:

    ```
    /**
     * Retrieve IPN Response From PayPal
     *
     * @param \Illuminate\Http\Request $request
     */
    public function postNotify(Request $request)
    {
        // Import the namespace Proxylyx\PayPal\Services\ExpressCheckout first in your controller.
        $provider = new ExpressCheckout;
        $response = (string) $provider->parsePayPalIPN($request);

        if ($response === 'VERIFIED') {
            // Your code goes here ...
        }
    }
    ```

Create Subscriptions
--------------------

[](#create-subscriptions)

- For example, you want to create a recurring subscriptions on paypal, first pass data to `SetExpressCheckout` API call in following format:

    ```
    // Always update the code below accordingly to your own requirements.
    $data = [];

    $data['items'] = [
        [
            'name'  => "Monthly Subscription",
            'price' => 0,
            'qty'   => 1,
        ],
    ];

    $data['subscription_desc'] = "Monthly Subscription #1";
    $data['invoice_id'] = 1;
    $data['invoice_description'] = "Monthly Subscription #1";
    $data['return_url'] = url('/paypal/ec-checkout-success?mode=recurring');
    $data['cancel_url'] = url('/');

    $total = 0;
    foreach ($data['items'] as $item) {
        $total += $item['price'] * $item['qty'];
    }

    $data['total'] = $total;
    ```
- Next perform the remaining steps listed in [`SetExpressCheckout`](#usage-ec-setexpresscheckout).
- Next perform the exact steps listed in [`GetExpressCheckoutDetails`](#usage-ec-getexpresscheckoutdetails).
- Finally do the following for [`CreateRecurringPaymentsProfile`](#usage-ec-createrecurringprofile)

    ```
    $amount = 9.99;
    $description = "Monthly Subscription #1";
    $response = $provider->createMonthlySubscription($token, $amount, $description);

    // To create recurring yearly subscription on PayPal
    $response = $provider->createYearlySubscription($token, $amount, $description);
    ```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~501 days

Total

5

Last Release

1232d ago

Major Versions

v2.1 → v3.0.02022-10-21

v3.0.0 → v4.0.02023-02-16

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4340118?v=4)[Shankar Prakash G](/maintainers/shankarGdev)[@shankarGdev](https://github.com/shankarGdev)

---

Top Contributors

[![shankarGdev](https://avatars.githubusercontent.com/u/4340118?v=4)](https://github.com/shankarGdev "shankarGdev (2 commits)")[![bnp-angel](https://avatars.githubusercontent.com/u/73825567?v=4)](https://github.com/bnp-angel "bnp-angel (1 commits)")

---

Tags

httprestweb servicepaypallaravel paypal

### Embed Badge

![Health badge](/badges/proxylyx-paypal/health.svg)

```
[![Health](https://phpackages.com/badges/proxylyx-paypal/health.svg)](https://phpackages.com/packages/proxylyx-paypal)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
