PHPackages                             lahirulhr/laravel-payhere - 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. [Payment Processing](/categories/payments)
4. /
5. lahirulhr/laravel-payhere

ActiveLibrary[Payment Processing](/categories/payments)

lahirulhr/laravel-payhere
=========================

API integration for PayHere payment gateway in Sri Lanka

v1.0.4(1y ago)915.0k↓26%4[2 PRs](https://github.com/Visanduma/laravel-payhere/pulls)MITPHPPHP ^8.1

Since Jan 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Visanduma/laravel-payhere)[ Packagist](https://packagist.org/packages/lahirulhr/laravel-payhere)[ Docs](https://github.com/lahirulhr/laravel-payhere)[ GitHub Sponsors](https://github.com/lahirulhr)[ RSS](/packages/lahirulhr-laravel-payhere/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (9)Versions (11)Used By (0)

Laravel PayHere
===============

[](#laravel-payhere)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d89a1b306ea5c26a71eb1ed5f8c7e59e9d29205c50c33ab69eb832c6b2be8718/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61686972756c68722f6c61726176656c2d706179686572652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lahirulhr/laravel-payhere)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a9c32e82372eb17c3db917b334b8862c63a91cff455191942b37e8de28c4ab0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c61686972756c68722f6c61726176656c2d706179686572652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/lahirulhr/laravel-payhere/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/69af413eeb571c4b54beec8b66369e505085521f9deb38f2fa3662d3e71f74e8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c61686972756c68722f6c61726176656c2d706179686572652f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/lahirulhr/laravel-payhere/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b1457f3e2b1baf9d91e8e9dfb22142710467c47d0465654bf221cbc6f3a9b02e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61686972756c68722f6c61726176656c2d706179686572652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lahirulhr/laravel-payhere)

[![](https://camo.githubusercontent.com/72adae477618192bdab17c8c2105936496544ce586fa20e6ec17ee64fb8cb875/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f312f31312f4c61726176656c5f6c6f676f747970655f6d696e2e7376672f3235363070782d4c61726176656c5f6c6f676f747970655f6d696e2e7376672e706e67)](http://laravel.com)
[![](https://camo.githubusercontent.com/9f88b4bcc27469589fdeb4796656f5801cfa871f4e1c0d4e7294c5795e460d81/68747470733a2f2f7061796865726573746f726167652e626c6f622e636f72652e77696e646f77732e6e65742f706179686572652d7265736f75726365732f7777772f696d616765732f506179486572652d4c6f676f2e706e67)](http://payhere.lk)

Laravel - PayHere was made to manage PayHere payment gateway on your laravel application with ease. currently this package supports all available methods on official PayHere documentation.

Read official [Documentation](https://support.payhere.lk/api-&-mobile-sdk/payhere-checkout) for more information

#### Available API methods

[](#available-api-methods)

✔️ Checkout API
✔️ Recurring API
✔️ Preapproval API
✔️ Charging API
✔️ Retrieval API
✔️ Subscription Manager API
✔️ Refund API
✔️ Authorize API
✔️ Capture API

###### Basic Usage

[](#basic-usage)

```
// adding payment details
$data = [
            'first_name' => 'Lahiru',
            'last_name' => 'Tharaka',
            'email' => 'lahirulhr@gmail.com',
            'phone' => '+94761234567',
            'address' => 'Main Rd',
            'city' => 'Anuradhapura',
            'country' => 'Sri lanka',
            'order_id' => '45552525005',
            'items' => 'Smart band MI 4 - BLACK',
            'currency' => 'LKR',
            'amount' => 4960.00,
        ];

// creating checkout page & redirect user

return PayHere::checkOut()
            ->data($data)
            ->successUrl('www.visanduma.com/payment-success')
            ->failUrl('www.visanduma.com/payment-fail')
            ->renderView();
```

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

[](#installation)

You can install the package via composer:

```
composer require lahirulhr/laravel-payhere
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Lahirulhr\PayHere\PayHereServiceProvider" --tag="laravel-payhere-config"
```

This is the contents of the published config file:

```
return [

    /*
     PayHere action url. usually,
     for production   https://www.payhere.lk
     for testing  https://sandbox.payhere.lk
      remember to update api when production
     * */

    'api_endpoint' => env('PAYHERE_API'),

    /*
      PayHere merchant ID can be found in their dashboard
      https://www.payhere.lk/account/settings/domain-credentials
     * */

    'merchant_id' => env('PAYHERE_MERCHANT_ID'),

    /*
     Merchant Secret is specific to each App/Domain. it can be generated for your domain/app as follows
     https://www.payhere.lk/account/settings/domain-credentials
        *Click 'Add Domain/App' > Fill details > Click 'Request to Allow'
        *Wait for the approval for your domain
        *Copy the Merchant Secret for your domain/app to .env file
     * */
    'merchant_secret' => env('PAYHERE_MERCHANT_SECRET'),

    /*
     Follow PayHere official instructions to obtain 'app_id' and 'app_secret'.
     NOTE: you dont need to generate "Authorization code". it will be automatically generate by this package
        *Sign in to your PayHere account & go to Settings > Business Apps section
        *Click 'Create App' button & enter an app name & comma seperated domains to whilelist
        *Tick the permission 'Payment Retrieval API'
        *Click 'Add Business App' button to create the app
        *Once the app is created click 'View Credential' button in front of the created app
        *Copy the 'App ID' & 'App Secret' values
     * */
    'app_id' => env('PAYHERE_APP_ID'),
    'app_secret' => env('PAYHERE_APP_SECRET'),
```

Usage
-----

[](#usage)

###### [Checkout API](https://support.payhere.lk/api-&-mobile-sdk/payhere-checkout)

[](#checkout-api)

Checkout API lets you integrate PayHere with your website, web application or any other application in code level. It offers a simple HTML Form to initiate a payment request and redirect your customer to PayHere Payment Gateway to securely process the payment.

```
// in your controller

use Lahirulhr\PayHere\PayHere;

// prepair posting data

$data = [
            'first_name' => 'Lahiru',
            'last_name' => 'Tharaka',
            'email' => 'lahirulhr@gmail.com',
            'phone' => '+94761234567',
            'address' => 'Main Rd',
            'city' => 'Anuradhapura',
            'country' => 'Sri lanka',
            'order_id' => '45552525005',
            'items' => 'Smart band MI 4 - BLACK',
            'currency' => 'LKR',
            'amount' => 4960.00,
        ];

// creating checkout page & ridirect the user

return PayHere::checkOut()
            ->data($data)
            ->setOptionalData() // Set optional data. see PayHere documantaion for available values
            ->successUrl('www.visanduma.com/success')
            ->failUrl('www.visanduma.com/fail')
            ->renderView();
```

#### Handling the server callback

[](#handling-the-server-callback)

PayHere will be notified your application with response data using public url POST request callback. then this package will emit a new event with their callback data. you just need to listen on an event and do anything you want with payload data.

#### Available Events

[](#available-events)

- AuthorizeCallbackEvent
- CheckoutCallbackEvent
- PreapprovalCallbackEvent
- RecurringCallbackEvent

Example:

```

// define listners in your EventServiceProvider.php

class EventServiceProvider extends ServiceProvider
{

    use Lahirulhr\PayHere\Events\CheckoutCallbackEvent;

    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        CheckoutCallbackEvent::class => [
            // register listeners to do something with callback
            SomeListener::class
        ],
    ];

}

class SomeListener{

    //....

     public function handle($event)
    {
     // you can access payhere callback data using $event->payload
        Log::info($event->payload);
    }

}
```

###### [Recurring API](https://support.payhere.lk/api-&-mobile-sdk/payhere-recurring)

[](#recurring-api)

Recurring API is accept data array same as checkout API. the only things you need to change checkOut() method to recurring().

```
return PayHere::recurring()
            ->data($data)
            ->setOptionalData() // Set optional data. see PayHere documantaion for available values
            ->successUrl('www.visanduma.com/success')
            ->failUrl('www.visanduma.com/fail')
            ->chargeMonthly(2)
            ->forYears()
            ->renderView();
```

The following options are available for making adjustment to recurring period

```
// Charging interval (Recurrence)
PayHere::recurring()->chargeWeekly(2) // charge per specific period of weeks .the default value is one week
PayHere::recurring()->chargeMonthly(3) // charge per specific period of months .the default value is one month
PayHere::recurring()->chargeAnnually() // charge per specific period of years .the default value is one year

// Duration to charge
PayHere::recurring()->forWeeks(6) // set duratoin by weeks .the default value is one week
PayHere::recurring()->forMonths(3) // set duratoin by months .the default value is one month
PayHere::recurring()->forYears() // set duratoin by years .the default value is one year
PayHere::recurring()->forForever() // set charging period to infinity.
```

```
// use this event to recieve server callback. see above example on Checkout API
RecurringCallbackEvent::class
```

###### [Preapproval API](https://support.payhere.lk/api-&-mobile-sdk/payhere-preapproval)

[](#preapproval-api)

Use same as checkout method

```
return PayHere::preapproval()
            ->data($data)
            ->setOptionalData() // Set optional data. see PayHere documantaion for available values
            ->successUrl('www.visanduma.com/payment-success')
            ->failUrl('www.visanduma.com/payment-fail')
            ->renderView();
```

```
// use this event to recieve server callback. see above example on Checkout API
PreapprovalCallbackEvent::class
```

###### [Charging API](https://support.payhere.lk/api-&-mobile-sdk/payhere-charging)

[](#charging-api)

Charging API lets you charge your preapproved customers programatically on demand using the encrypted tokens. it will return response data array on success or return PayHereException if any error.

```
$data = [
        "type" => "PAYMENT",
        "order_id" => "Order12345",
        "items" => "Taxi Hire 123",
        "currency" => "LKR",
        "amount" => 345.67,
    ];

$response =  PayHere::charge()
        ->byToken("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") // customer token
        ->withData($data)
        ->submit();
```

###### [Retrieval API](https://support.payhere.lk/api-&-mobile-sdk/payhere-retrieval)

[](#retrieval-api)

Retrieval API lets you retrieve the details of the Successful payments processed through your PayHere

```
$info = PayHere::retrieve()
        ->orderId("od-43784658374534") // order number that you use to charge from customer
        ->submit();
```

##### [Subscription Manager](https://support.payhere.lk/api-&-mobile-sdk/payhere-subscription)

[](#subscription-manager)

Subscription Manager API lets you view, retry &amp; cancel your subscription customers programmatically you subscribed from Recurring API.

```
// get all subscriptions
$subscriptions = PayHere::subscription()->getAll();

// get payment details of specific subscription
$paymentInfo = PayHere::subscription()
        ->getPaymentsOfSubscription("420075032251"); // subscription ID

// retry on failed supscription payments
PayHere::subscription()
        ->retry("420075032251"); // subscription ID

// cancel a subscription
PayHere::subscription()
        ->cancel("420075032251"); // subscription ID
```

###### [Refund API](https://support.payhere.lk/api-&-mobile-sdk/payhere-refund)

[](#refund-api)

Refund API lets you refund your existing payment programmatically.

```
PayHere::refund()
        ->makePaymentRefund('320027150501') // payment_id
        ->note("Out of stock") // note for refund
        ->submit();
```

###### [Authorize API](https://support.payhere.lk/api-&-mobile-sdk/payhere-authorize)

[](#authorize-api)

Authorize API allows you to get your customer authorization for Hold on Card payments. this method will redirect user to payment page

```
// use same $data as Checkout method

return PayHere::authorize()
        ->data($data)
        ->successUrl('www.visanduma.com/success')
        ->failUrl('www.visanduma.com/fail')
        ->renderView();

```

```
// use this event to recieve server callback. see above example on Checkout API
AuthorizeCallbackEvent::class
```

###### [Capture API](https://support.payhere.lk/api-&-mobile-sdk/payhere-capture)

[](#capture-api)

Capture API lets you capture your authorized Hold on Card payments programmatically on demand using the authorization tokens you retrieved from Payment Authorize API.

```
$response =  PayHere::capture()
        ->usingToken('e34f3059-7b7d-4b62-a57c-784beaa169f4') // authorization token
        ->amount(100) // charging amount
        ->reason("reason for capture")
        ->submit();
```

---

TODO
----

[](#todo)

- Events for server callbacks
- Custom payment redirection page
- Custom Error types
- Response Data Objects
- Optional Data handling
- Inbuilt subscription database
- Server callback log

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [LaHiRu](https://github.com/lahirulhr)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~134 days

Recently: every ~9 days

Total

8

Last Release

650d ago

Major Versions

0.2.1 → v1.0.02024-06-24

PHP version history (3 changes)v0.1.0PHP ^7.4|^8.0

0.2.0PHP ^8.0

v1.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/884dddda47e3f67bbf3d513691eab6b6f919dbc9691d4bf84ad436416310809c?d=identicon)[lahirulhr](/maintainers/lahirulhr)

---

Top Contributors

[![lahirulhr](https://avatars.githubusercontent.com/u/13136764?v=4)](https://github.com/lahirulhr "lahirulhr (47 commits)")

---

Tags

laravellahirulhrlaravel-payhere

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/lahirulhr-laravel-payhere/health.svg)

```
[![Health](https://phpackages.com/badges/lahirulhr-laravel-payhere/health.svg)](https://phpackages.com/packages/lahirulhr-laravel-payhere)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)[danestves/laravel-polar

A package to easily integrate your Laravel application with Polar.sh

7812.3k](/packages/danestves-laravel-polar)[spatie/laravel-mailcoach-sdk

An SDK to easily work with the Mailcoach API in Laravel apps

41290.2k1](/packages/spatie-laravel-mailcoach-sdk)

PHPackages © 2026

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