PHPackages                             baidouabdellah/cmi-payment-gateway - 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. baidouabdellah/cmi-payment-gateway

ActiveLibrary[Payment Processing](/categories/payments)

baidouabdellah/cmi-payment-gateway
==================================

Laravel package to integrate with the CMI payment gateway

1.0.4(2mo ago)24474[1 issues](https://github.com/baidou5/CMI-Payment-Gateway/issues)MITPHPPHP ^7.4|^8.0|^8.1|^8.2|^8.3

Since Sep 23Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/baidou5/CMI-Payment-Gateway)[ Packagist](https://packagist.org/packages/baidouabdellah/cmi-payment-gateway)[ Docs](https://github.com/baidouabdellah/cmi-payment-gateway)[ RSS](/packages/baidouabdellah-cmi-payment-gateway/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (25)Versions (5)Used By (0)

[![CMI-Payment-Gateway](https://raw.githubusercontent.com/baidou5/CMI-Payment-Gateway/main/cmi.jpg)](https://raw.githubusercontent.com/baidou5/CMI-Payment-Gateway/main/cmi.jpg)

CMI Payment Gateway for Laravel
===============================

[](#cmi-payment-gateway-for-laravel)

[![Latest Version](https://camo.githubusercontent.com/1589e781eaa12582cd8a7823ca1ba157844b5c8b1a530a012883cd87fb299f4d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f626169646f75352f434d492d5061796d656e742d47617465776179)](https://github.com/baidou5/CMI-Payment-Gateway/releases)[![License](https://camo.githubusercontent.com/9ed392702160c424d66a3686d6212796e476c9515842b084d0f822c605c47ea0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f626169646f75352f434d492d5061796d656e742d47617465776179)](https://github.com/baidou5/CMI-Payment-Gateway/blob/main/LICENSE)[![PHP Version](https://camo.githubusercontent.com/6eff5053a32c9e0bcc0982c4f118ef689cad7831a3d982767aae3901bf67313c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344372e342d626c75652e737667)](https://www.php.net/)[![Laravel Version](https://camo.githubusercontent.com/206540dfc02d60a5915b55bb6cdc0e2620cc2ed4d2aba17a188387a09c6450bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d253345253344372e302d6f72616e67652e737667)](https://laravel.com/)[![Total Downloads](https://camo.githubusercontent.com/92f4fbe680fa92d392b4f6f89b96cb492e9c4e49257cdf0a455fc2d8d06a81d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626169646f75616264656c6c61682f636d692d7061796d656e742d67617465776179)](https://packagist.org/packages/baidouabdellah/cmi-payment-gateway)[![Contributors](https://camo.githubusercontent.com/3585571a4657f0b2d91e64f94ace4ece47c4744ec30c3942f4d8f1d6d5a23dd8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f626169646f75352f434d492d5061796d656e742d476174657761792e737667)](https://github.com/baidou5/CMI-Payment-Gateway/graphs/contributors)[![Issues](https://camo.githubusercontent.com/37ceccbfb10b2cb7a99001d3b6210884b60e4651a6b5e04db8ff2f8613e8cc1f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f626169646f75352f434d492d5061796d656e742d476174657761792e737667)](https://github.com/baidou5/CMI-Payment-Gateway/issues)[![Pull Requests](https://camo.githubusercontent.com/38de69860d9d116cd613de8eec6628682c94f9eb78ce6e4b90769fd7e90669df/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f626169646f75352f434d492d5061796d656e742d476174657761792e737667)](https://github.com/baidou5/CMI-Payment-Gateway/pulls)[![GitHub stars](https://camo.githubusercontent.com/ba7a74757bf11aee45763a51e66f5984fa73a8780db41b355b2861ff592b8b74/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f626169646f75352f434d492d5061796d656e742d476174657761792e7376673f7374796c653d736f6369616c)](https://github.com/baidou5/CMI-Payment-Gateway/stargazers)

**CMI-Payment-Gateway** is a Laravel package for integrating CMI (Centre Monétique Interbancaire) hosted payments with hash generation and callback validation.

Features
--------

[](#features)

- Seamless integration with Laravel
- Easy to configure and use
- Secure payment processing via CMI
- Supports multiple SHOPs (SAAS) transactions
- Customizable payment callback URL

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- Laravel 7.x or higher
- CMI Merchant account

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

[](#installation)

To install the package, use Composer:

```
composer require baidouabdellah/cmi-payment-gateway
```

### Publish Configuration

[](#publish-configuration)

Once installed, publish the configuration file using the following command:

```
php artisan vendor:publish --tag="cmi-config"
```

This will create a `cmi.php` file in your `config` directory where you can configure your CMI credentials.

### Configuration

[](#configuration)

In the `config/cmi.php` file, add your CMI Merchant credentials:

```
return [
    'merchant_id' => env('CMI_MERCHANT_ID'),
    'client_id' => env('CMI_CLIENT_ID'),
    'store_key' => env('CMI_STORE_KEY'),
    'api_key' => env('CMI_API_KEY'),
    'secret_key' => env('CMI_SECRET_KEY'),
    'sandbox' => env('CMI_SANDBOX', true),
    'base_uri' => env('CMI_BASE_URI', 'https://testpayment.cmi.co.ma/fim/est3Dgate'),
    'ok_url' => env('CMI_OK_URL', 'http://localhost/cmi/ok'),
    'fail_url' => env('CMI_FAIL_URL', 'http://localhost/cmi/fail'),
    'shop_url' => env('CMI_SHOP_URL', 'http://localhost/checkout'),
    'callback_url' => env('CMI_CALLBACK_URL', 'http://localhost/cmi/callback'),
    'store_type' => env('CMI_STORE_TYPE', '3D_PAY_HOSTING'),
    'tran_type' => env('CMI_TRAN_TYPE', 'PreAuth'),
    'lang' => env('CMI_DEFAULT_LANG', 'fr'),
    'currency' => env('CMI_DEFAULT_CURRENCY', '504'),
    'hash_algorithm' => env('CMI_HASH_ALGORITHM', 'ver3'),
    'encoding' => env('CMI_ENCODING', 'UTF-8'),
    'auto_redirect' => env('CMI_AUTO_REDIRECT', true),
    'callback_response' => env('CMI_CALLBACK_RESPONSE', true),
    'session_timeout' => env('CMI_SESSION_TIMEOUT', 1800),
    'transport' => env('CMI_TRANSPORT', 'hosted_form'), // hosted_form | server_api
    'http_timeout' => env('CMI_HTTP_TIMEOUT', 15),
];
```

You can also add these environment variables to your `.env` file:

```
CMI_MERCHANT_ID=your_merchant_id
CMI_CLIENT_ID=your_client_id
CMI_STORE_KEY=your_store_key
CMI_API_KEY=your_api_key
CMI_SECRET_KEY=your_secret_key
CMI_SANDBOX=true
CMI_BASE_URI=https://testpayment.cmi.co.ma/fim/est3Dgate
CMI_OK_URL=https://yourwebsite.com/payment/success
CMI_FAIL_URL=https://yourwebsite.com/payment/fail
CMI_SHOP_URL=https://yourwebsite.com/payment/cancel
CMI_CALLBACK_URL=https://yourwebsite.com/payment/callback
CMI_STORE_TYPE=3D_PAY_HOSTING
CMI_TRAN_TYPE=PreAuth
CMI_DEFAULT_LANG=fr
CMI_DEFAULT_CURRENCY=504
CMI_HASH_ALGORITHM=ver3
CMI_ENCODING=UTF-8
CMI_AUTO_REDIRECT=true
CMI_CALLBACK_RESPONSE=true
CMI_SESSION_TIMEOUT=1800
CMI_TRANSPORT=hosted_form
CMI_HTTP_TIMEOUT=15
```

Usage
-----

[](#usage)

To process a payment, use the provided `CmiPayment` service/facade:

1. First, inject the `CmiPayment` service into your controller or use the facade.
2. Example usage in a controller:

```
use Baidouabdellah\CmiPaymentGateway\CmiPayment;

class PaymentController extends Controller
{
    public function makePayment(Request $request)
    {
        $payment = app(CmiPayment::class);
        $response = $payment->pay(100.00, 'ORDER12345', 'Order payment', [
            'email' => 'customer@example.com',
            'BillToName' => 'Customer Name',
        ]);

        // $response['gateway_url'] => CMI endpoint
        // $response['payload'] => fields to submit as POST form
        // $response['hash'] => generated hash
        return response()->json($response);
    }
}
```

### Handling Payment Callbacks

[](#handling-payment-callbacks)

In your `web.php` routes file, you should add a route to handle the CMI callback:

```
Route::post('/cmi/callback', [PaymentController::class, 'handleCallback'])->name('cmi.callback');
```

In your `PaymentController`, handle the callback:

```
use Illuminate\Http\Request;

class PaymentController extends Controller
{
    public function handleCallback(Request $request)
    {
        $service = app(\Baidouabdellah\CmiPaymentGateway\CmiPaymentService::class);
        $isValid = $service->validateHash($request->all());

        if ($isValid && $request->input('ProcReturnCode') === '00') {
            return view('payment.success');
        }

        return view('payment.failed');
    }
}
```

Testing
-------

[](#testing)

You can test the integration using CMI's sandbox credentials. Ensure you configure the sandbox environment in the `cmi.php` configuration file or use different `.env` variables for testing.

### Basic Test Card Numbers

[](#basic-test-card-numbers)

Credit card information cannot be used in test mode. Instead, use any of the following test card numbers, along with a valid future expiration date and any random CVC number, to simulate a successful payment transaction.

Card TypeCard NumberCVC (Random)Expiration Date (Future)Visa4242 4242 4242 42423 digitsAny future dateVisa (Debit)4000 0566 5566 55563 digitsAny future dateMastercard5555 5555 5555 44443 digitsAny future dateMastercard (Series 2)2223 0031 2200 32223 digitsAny future dateMastercard (Debit)5200 8282 8282 82103 digitsAny future dateMastercard (Prepaid)5105 1051 0510 51003 digitsAny future dateAmerican Express3782 822463 100054 digitsAny future dateAmerican Express3714 4963 5398 4314 digitsAny future dateDiscover6011 1111 1111 11173 digitsAny future dateDiscover6011 0009 9013 94243 digitsAny future dateDiners Club3056 9300 0902 00043 digitsAny future dateJCB3566 0020 2036 05053 digitsAny future dateUse these details in your testing environment to verify the successful integration of the CMI payment gateway.

Security
--------

[](#security)

If you discover any security issues, please send an email to `baidou.abd@gmail.com` instead of using the issue tracker.

Support
-------

[](#support)

- **Abdellah Baidou**
- +212 661-176711
-

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance86

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

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

Total

4

Last Release

68d ago

PHP version history (3 changes)1.0.1PHP ^7.4|^8.0

1.0.3PHP ^7.4|^8.0|^8.1|^8.2

1.0.4PHP ^7.4|^8.0|^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/216f792e1285980ea75f9060eeacae300b6bba5061c0cd45e10b5f49491411ff?d=identicon)[baidou](/maintainers/baidou)

---

Top Contributors

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

---

Tags

cmiexpressgetwaymoroccopayment-gatewaylaravelpaymentgatewayintegrationcmi

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/baidouabdellah-cmi-payment-gateway/health.svg)

```
[![Health](https://phpackages.com/badges/baidouabdellah-cmi-payment-gateway/health.svg)](https://phpackages.com/packages/baidouabdellah-cmi-payment-gateway)
```

###  Alternatives

[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4845.9k](/packages/sebdesign-laravel-viva-payments)[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)[omalizadeh/laravel-multi-payment

A driver-based laravel package for online payments via multiple gateways

491.1k](/packages/omalizadeh-laravel-multi-payment)[parsisolution/gateway

A Laravel package for connecting to all Iraninan payment gateways

231.7k](/packages/parsisolution-gateway)

PHPackages © 2026

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