This package helps you integrate your laravel application with Mpesa daraja APIs. The package eliminates (almost)all the hassles and lets you concentrate on what is important.
The package will help you integrate with the following APIs, available on mpesa daraja;
- C2B (consumer to business)
- B2C (business to cunsumer)
- Lipa na mpesa online(Mpesa Express)
- Reversal
- Transaction status
- Account balance
You are looking at it. But we've also got beautiful, fully navigable docs.
You can install this awesome package via composer
composer require gathuku/laravelmpesa
If you're using Laravel >=5.5, this is all you have to do.
Should you still be on version 5.4 of Laravel, the final steps for you are to add the service provider of the package and alias the package. To do this open your config/app.php
file.
Add a new line to the providers
array:
Gathuku\Mpesa\MpesaServiceProvider::class,
And optionally add a new line to the aliases
array:
'Mpesa' => Gathuku\Mpesa\Facades\Mpesa::class,
Next, after the package has been installed run;
php artisan mpesa:install
or
php artisan vendor:publish
This will help in publishing config/mpesa.php
file.
This mpesa config file is where you will add all configurations for Mpesa APIs.
This includes the environment your application is running in(sandbox or production), callback URLs and required credentials.
You will obtain credentials from your app
on Safaricom's developer portal.
<?php
return [
//Specify the environment mpesa is running, sandbox or production
'mpesa_env' => 'sandbox',
/*-----------------------------------------
|The App consumer key
|------------------------------------------
*/
'consumer_key' => 'aR7R09zePq0OSfOttvuQDrfdM4n37i0C',
/*-----------------------------------------
|The App consumer Secret
|------------------------------------------
*/
'consumer_secret' => 'F9AebI6azDlRjLiR',
/*-----------------------------------------
|The paybill number
|------------------------------------------
*/
'paybill' => 601380,
/*-----------------------------------------
|The Lipa Na Mpesa Online shortcode
|------------------------------------------
*/
'lipa_na_mpesa' => '174379',
];
For production you need to replace with production credentials.
For security reasons you may want to define your API credentials in env
file. For example;
'consumer_key' => env('CONSUMER_KEY'),
Full usage and examples in USAGE.md
Thank you for considering contributing to laravelmpesa
. Pull requests and issues welcome.
Be sure to read through CONTRIBUTING.md and check open issues and PRs before continuing.
If you discover a security vulnerability within laravelmpesa
, please send an e-mail to Moses Gathuku via [email protected]. All security vulnerabilities will be promptly addressed.
The laravelmpesa
package is open-source software licensed under the MIT license