PHPackages                             thehocinesaad/laravel-chargily-epay - 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. thehocinesaad/laravel-chargily-epay

ActiveLibrary[Payment Processing](/categories/payments)

thehocinesaad/laravel-chargily-epay
===================================

Laravel-Chargily-ePay is a Laravel package that provides an easy interface to Chargily ePay gateway

v1.2.0(3y ago)202.1k↑50%5MITPHPPHP ^7.4|^8.0

Since Sep 10Pushed 2y ago3 watchersCompare

[ Source](https://github.com/theHocineSaad/laravel-chargily-epay)[ Packagist](https://packagist.org/packages/thehocinesaad/laravel-chargily-epay)[ Docs](https://github.com/thehocinesaad/laravel-chargily-epay)[ RSS](/packages/thehocinesaad-laravel-chargily-epay/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (7)Used By (0)

[![](https://camo.githubusercontent.com/fe519ce540c47d610b810c92b5ecf12d57549e0d0cb9b361497ba74a04d1957c/68747470733a2f2f692e696d6775722e636f6d2f446f33447059492e706e67)](https://camo.githubusercontent.com/fe519ce540c47d610b810c92b5ecf12d57549e0d0cb9b361497ba74a04d1957c/68747470733a2f2f692e696d6775722e636f6d2f446f33447059492e706e67)

Laravel-Chargily-ePay
=====================

[](#laravel-chargily-epay)

**Laravel-Chargily-ePay** is a Laravel package that provides an easy interface to [Chargily Pay gateway](http://pay.chargily.com/ "Chargily Pay gateway").

Features
--------

[](#features)

- Integrating E-Payment never was that fast and easy.
- Creating invoices is as easy as calling a function.
- Comes with a Migration that creates `epay_invoices` table with a `user_id` foreign id.
- A trait for the User model that gives you some very useful functions like `$user->charge()` to create an invoice for a user, and `$user->invoices()` to get all user's invoices.
- It comes with a payment webhook handler out of the box, so you just have to add your logic of what happens after a user performs a payment or cancels it.
- It has a webhook tester built in, it's like a sandbox, it's a simulation of a user paying an invoice so you don't have to test your application with real money.

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

[](#installation)

### Step 1 - Require the package

[](#step-1---require-the-package)

```
composer require thehocinesaad/laravel-chargily-epay

```

### Step 2: Publish migrations

[](#step-2-publish-migrations)

```
php artisan vendor:publish --provider="TheHocineSaad\LaravelChargilyEPay\LaravelChargilyEPayServiceProvider" --tag="migrations"

```

### Step 3: Run migrations

[](#step-3-run-migrations)

```
php artisan migrate

```

### Step 4: Edit `.env` file

[](#step-4-edit-env-file)

This package requires these keys:

- **CHARGILY\_EPAY\_KEY**: You can get it from [Chargily Pay's dashboard](https://pay.chargily.com/secure/admin/epay-api "Chargily Pay's dashboard").
- **CHARGILY\_EPAY\_SECRET**: same as the first one.
- **CHARGILY\_EPAY\_BACK\_URL**: This is the URL where the user will be redirected after payment processing.
- **CHARGILY\_EPAY\_WEBHOOK\_URL**: This is the URL of your webhook where Chargily ePay will notify you after payment processing, we will talk about it in a bit.

**Important**: `CHARGILY_EPAY_BACK_URL` and `CHARGILY_EPAY_WEBHOOK_URL` should be real URLs, so you can't put `http://127.0.0.1:8000`, use [Ngrok](https://ngrok.com/ "Ngrok").

### Step 5: Epayable trait

[](#step-5-epayable-trait)

Add the `Epayable` trait to your User model:

```
use  TheHocineSaad\LaravelChargilyEPay\Traits\Epayable;

class User extends Authenticatable
{
    use Epayable
}
```

### Step 6 (optional): Publishing

[](#step-6-optional-publishing)

#### Config File:

[](#config-file)

```
php artisan vendor:publish --provider="JohnDoe\BlogPackage\BlogPackageServiceProvider" --tag="config"

```

#### Models

[](#models)

```
php artisan vendor:publish --provider="TheHocineSaad\LaravelChargilyEPay\LaravelChargilyEPayServiceProvider" --tag="models"

```

Using the package
-----------------

[](#using-the-package)

### Creating an Epay Invoice

[](#creating-an-epay-invoice)

To create an Invoice, you can te use the static `Make()` function from the `Epay_Invoice` model:

```
use TheHocineSaad\LaravelChargilyEPay\Models\Epay_Invoice;

$configurations = [
        'user_id' => 1, // (optional) This is the user ID to be added as a foreign key, it's optional, if it's not provided its value will be NULL
        'mode' => 'CIB', // Payment method must be 'CIB' or 'EDAHABIA'
        'payment' => [
         'client_name' => 'client name here', // Client name
         'client_email' => 'hello@email.com', // This is where client receives payment receipt after confirmation
            'amount' => 2500, // Must be = or > than 75
            'discount' => 0, // This is discount percentage, between 0 and 99
            'description' => 'payment for product', // This is the payment description
        ]
    ];

    $checkout_url = Epay_Invoice::make($configurations);
```

The `Make()` function returns the checkout URL, where the user should be redirected to make a payment, If any error occurs, it will return to the home page, so make sure to check this before redirecting the user.

The `Make()` also creates an invoice in your database using the info from the provided **$configurations** array, so if you added columns to the migration file of the invoices table that comes with the package, you have to add the corresponding values as a second array, example:

```
    $checkout_url = Epay_Invoice::make($configurations, ['product_id' => 1]);
```

As you saw in the example above, we added the value of `product_id`, that's because you may be added `product_id` field in the migration file.

### Creating an Epay Invoice for a User

[](#creating-an-epay-invoice-for-a-user)

The other way (Recommended way) to create Epay Invoices is to use the `charge()` custom model method which is provided by the `Epayable` trait, this method will automatically add the name of the client, the email of the client, and the `client_id` foreign key:

```
$configurations = [
    'mode' => 'CIB',
    'payment' => [
        'amount' => 1000,
        'discount' => 0,
        'description' => 'payment for product',
    ]
];

$checkout_url = $request->user()->charge($configurations);
```

The `charge()` method calls the `Make()` static function at a certain point, so they act the same way, it returns the checkout URL, or the home page URL if any error occurs.

Just like the `Make()` function, you can add a second array to pass any added columns to the `invoices` table.

### Payment Webhook

[](#payment-webhook)

After a user complete the payment of an invoice, Chargily ePay will notify you by sending a post request to your Webhook, so you can handle the things you would like to happen after a successful or a failed payment.

So, go ahead and create a `POST` Route (ex: "/webhook"), by the way, this is the URL you should add to the `CHARGILY_EPAY_WEBHOOK_URL` key in the `.env` file.

**Important**: You have to exclude this URL from CSRF verification, to do so, add it to the `except` method in your applications's `App\Http\Middleware\VerifyCsrfToken` middleware:

```
protected $except = [
        'webhook'
];
```

Here is the code you should put in this route as a starting point:

```
use TheHocineSaad\LaravelChargilyEPay\Epay_Webhook;

$webhookHandler = new Epay_Webhook;

if($webhookHandler -> invoiceIsPaied) {
    // Put here the logic you want to happen if the user actually made the payment.
}else {
    // Put here the logic you want to happen if the user canceled the payment.
}
```

**Note**: You can access the ID of the Invoice by: `$webhookHandler -> invoice['invoice_number']`

Here is an example of the data that comes with the post request from Chargily Pay:

```
{
   "invoice":{
      "id":100000,
      "client":"Test Client",
      "client_email":"testclient@mail.com",
      "invoice_number":"I-123456789",
      "status":"paid",
      "amount":5000,
      "fee":75,
      "discount":0,
      "due_amount":5075,
      "comment":"Payment for T-Shirt",
      "mode":"CIB",
      "new":1,
      "tos":1,
      "back_url":"https://www.domain.com/",
      "invoice_token":"random_token_here",
      "api_key_id":null,
      "meta_data":null,
      "due_date":"2022-04-27 00:00:00",
      "created_at":"2022-04-27 20:59:07",
      "updated_at":"2022-04-27 21:01:09"
   }
}
```

#### Testing your Webhook

[](#testing-your-webhook)

I added an internal feature to simulate a payment of an invoice to test your webhook without the need to use Postman, after installing this package, you will automatically have a new route `/epay-webhook-tester`, navigate to it, put the ID of the invoice you want to simulate its payment and click on PAY.

\*\*Important: \*\* When you run your application using the local server `php artisan serve`, it will work on a single thread, so making post requests to itself will give you a timeout error, on a server, this is not a problem because it will use Apache or Nginx, the solution is to start another local server on another port (ex: 8001) and use this feature from there. Example:

1. Run `php artisan serve` so you will have your app on `http://127.0.0.1:8000`.
2. In another terminal instance, run `php artisan serve --port=8001` then visit `http://127.0.0.1:8001/epay-webhook-tester`, not `http://127.0.0.1:8000/epay-webhook-tester`

\*\*Note: \*\*for security purposes, this feature works only on the local environment (`APP_ENV=local`), and am sure it's not needed in production.

[![Test Chargily Pay](https://camo.githubusercontent.com/1704fc5c11b6749533eeedb1bbde329ed622332bf5b24c3f707abfeb7e940f3b/68747470733a2f2f692e696d6775722e636f6d2f6b3279615653742e706e67)](https://camo.githubusercontent.com/1704fc5c11b6749533eeedb1bbde329ed622332bf5b24c3f707abfeb7e940f3b/68747470733a2f2f692e696d6775722e636f6d2f6b3279615653742e706e67)

Info
----

[](#info)

This Laravel package is built on top of [this PHP package](https://github.com/Chargily/chargily-epay-php "this PHP package"), so have a look at it to know more about what's happening under the hood.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

Laravel-Chargily-ePay project is open-sourced software licensed under the [MIT license](https://github.com/theHocineSaad/laravel-chargily-epay/blob/main/LICENSE.md "MIT license").

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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 ~41 days

Recently: every ~51 days

Total

6

Last Release

1132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/af67db5b2a5eac973faa382288809000f52c9410cb31d70adc82aad91c79bb27?d=identicon)[theHocineSaad](/maintainers/theHocineSaad)

---

Top Contributors

[![theHocineSaad](https://avatars.githubusercontent.com/u/11405387?v=4)](https://github.com/theHocineSaad "theHocineSaad (24 commits)")

---

Tags

phpepaythehocinesaadchargilyepaimentsatimcibcibwebedahabiaepay.chargily.com.dzChargily-ePay-Gatewaylaravel-chargily-epay

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/thehocinesaad-laravel-chargily-epay/health.svg)

```
[![Health](https://phpackages.com/badges/thehocinesaad-laravel-chargily-epay/health.svg)](https://phpackages.com/packages/thehocinesaad-laravel-chargily-epay)
```

###  Alternatives

[chargily/chargily-pay

PHP Library for Chargily Pay V2

135.2k1](/packages/chargily-chargily-pay)[cartalyst/stripe-laravel

Laravel 11 integration for the Cartalyst Stripe package.

3382.6M9](/packages/cartalyst-stripe-laravel)[yandex-money/yandex-money-sdk-php

Yandex.Money API SDK for PHP

105167.4k2](/packages/yandex-money-yandex-money-sdk-php)[cryptonator/merchant-php-sdk

Cryptonator.com Merchant API SDK for PHP

2713.7k](/packages/cryptonator-merchant-php-sdk)

PHPackages © 2026

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