Laravel Daraja
, (*1)
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., (*2)
Installation
Install via composer, (*3)
composer require starnerz/laravel-daraja
Register Service Provider
Note! This and next step are optional if you use laravel>=5.5 with package
auto discovery feature., (*4)
Add service provider to config/app.php
in providers
section, (*5)
Starnerz\LaravelDaraja\LaravelDarajaServiceProvider::class,
Register Facade
Register package facade in config/app.php
in aliases
section, (*6)
Starnerz\LaravelDaraja\Facades\MpesaApi::class,
Publish Configuration File
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., (*7)
DARAJA_CONSUMER_KEY=
DARAJA_CONSUMER_SECRET=
DARAJA_INITIATOR_NAME=
DARAJA_INITIATOR_CREDENTIAL=
DARAJA_INITIATOR_SHORTCODE=
DARAJA_STK_SHORTCODE=
DARAJA_STK_PASS_KEY=
Usage
If you have not created your Safaricom API application yet you can create one at Safaricom Developer, (*8)
Each Safaricom API except Oauth has been implemented as a class on its own which you can use in your code., (*9)
``` php
$STK = new STK();
$STK->push('254727123456','10000','New Purchase','R3F3R3NC3');, (*10)
If you prefer using the facade
``` php
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., (*11)
``` bash, (*12)
php artisan daraja:register-urls
```, (*13)
Security
If you discover any security related issues, please email stanleykimathi@gmail.com
instead of using the issue tracker., (*14)