This package provides you with a simple tool to make requests to Safaricom Daraja APIs so that you can focus on the development of your awesome applications instead of all the set up involved.
Install via composer
composer require starnerz/laravel-daraja
Note! This and next step are optional if you use laravel>=5.5 with package auto discovery feature.
Add service provider to config/app.php
in providers
section
Starnerz\LaravelDaraja\LaravelDarajaServiceProvider::class,
Register package facade in config/app.php
in aliases
section
Starnerz\LaravelDaraja\Facades\MpesaApi::class,
php artisan vendor:publish --provider="Starnerz\LaravelDaraja\LaravelDarajaServiceProvider" --tag="config"
Fill in all the details you will be requiring for your application. Here are the env variables for quick copy paste.
DARAJA_CONSUMER_KEY=
DARAJA_CONSUMER_SECRET=
DARAJA_INITIATOR_NAME=
DARAJA_INITIATOR_CREDENTIAL=
DARAJA_INITIATOR_SHORTCODE=
DARAJA_STK_SHORTCODE=
DARAJA_STK_PASS_KEY=
If you have not created your Safaricom API application yet you can create one at Safaricom Developer
Each Safaricom API except Oauth has been implemented as a class on its own which you can use in your code.
$STK = new STK();
$STK->push('254727123456','10000','New Purchase','R3F3R3NC3');
If you prefer using the facade
MpesaApi::STK()->push('254727123456','10000','New Purchase','R3F3R3NC3');
If you will be using the C2B Api you can easily register the validation and confirmation URLs through artisan.
# php artisan daraja:register-urls
If you discover any security related issues, please email stanleykimathi@gmail.com instead of using the issue tracker.