Logo Lanfrica

ItsMurumba/laravel-mpesa

Domaine:

digital infrastructure

Type de record:

software
Créateur:
Its
Hôte:
Laravel 5, 6, 7, 8, 9, 10, 11, 12 package for Mpesa Daraja API # Introduction This is a Laravel package for Safaricom Mpesa Daraja API. It includes all public available endpoints: * Consumer to Business (C2B) payments * Business to Consumer (B2C) payments * Mpesa Express Payment (Lipa Na Mpesa Online) * Transaction Status * Account Balance * Reversal * Business to Business (B2B) payments # Installation Run the following command to install Laravel Mpesa package in your Laravel project: ```` composer require itsmurumba/laravel-mpesa ```` If you are using **Laravel 5.5** and above, skip to the **Configurations** step. After running the composer require above, you should add a service provider and alias of the package in config/app.php file.(For Laravel 5.4 and below) ```` Itsmurumba\Mpesa\MpesaServiceProvider::class ```` # Configurations After installing the package, run the following command to install `mpesa.php` configuartion file in the `config` folder: ```` php artisan mpesa:install ```` or ```` php artisan vendor:publish ```` Add and define the following variables in your `.env` file ```` MPESA_CONSUMER_KEY= MPESA_CONSUMER_SECRET= MPESA_CALLBACK_URL= MPESA_BASE_URL=sandbox.safaricom.co.ke MPESA_PAYBILL_NUMBER=600978 LIPA_NA_MPESA_SHORTCODE=174379 LIPA_NA_MPESA_CALLBACK_URL= LIPA_NA_MPESA_PASSKEY= MPESA_CONFIRMATION_URL= MPESA_VALIDATION_URL= MPESA_INITIATOR_USERNAME= MPESA_INITIATOR_PASSWORD= MPESA_ENVIRONMENT=sandbox MPESA_QUEUE_TIMEOUT_URL= MPESA_RESULT_URL= ```` # Usage Add the following constructor inside your controller: ````` protected $mpesa; public function __construct(){ $this->mpesa = new Mpesa(); } ````` **1. Mpesa Express Payment (Lipa Na Mpesa Online)** ```` $this->mpesa->expressPayment($amount, $phoneNumber, $accountReference = 'CompanyXLTD', $transactionDescription = 'Payment of X'); ```` * $phoneNumber = 254XXXXXXXXX * $accountReference = Account Reference (maximum 12 characters) * transactionDescription = Transaction Description (1-13 characters) **2. Mpesa Express Payment Query (Lip …