ssiva / yii2-mpesa-sdk
This package provides a seamless integration of M-PESA Daraja APIs in Yii2 applications
v1.1.2
2023-04-14 09:40 UTC
Requires
- ssiva/mpesa-daraja: ^4
- yiisoft/yii2: ~2.0.0
Requires (Dev)
- phpunit/phpunit: ~9.5.0
This package is not auto-updated.
Last update: 2024-11-18 05:12:17 UTC
README
This package provides a seamless integration of M-PESA Daraja APIs in Yii2 applications
- B2C (Business to Customer)
- C2B (Customer to Business)
- B2B (Business to Business)
- Account Balance inquiries
- Transaction reversals queries
- Transaction status queries.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist ssiva/yii2-mpesa-sdk
or
composer require --prefer-dist ssiva/yii2-mpesa-sdk
or add
"ssiva/yii2-mpesa-sdk": "*"
to the require section of your composer.json
file.
Configuration
Set up the config values as required
- Copy the file mpesa.php to
@app/config/mpesa.php
and set you config values. - Add the component configuration to
config/web.php
as below- Require the copied config file
$mpesa = require __DIR__.'/mmpesa.php';
- Add the required value to the components array
'mpesaDaraja' => $mpesa,
- Require the copied config file
The library is now ready for use.
Usage Examples
<?php namespace YOURNAMESPACE; class CheckoutController extends Controller { public function actionCheckout( $mpesaDaraja = Yii::$app->mpesaDaraja->getDaraja(); // authenticate $mpesaDaraja->authenticate(); // STK Push $stkParams = [ 'Amount' => '2', 'PartyA' => '2547XXXXXXXX', 'PhoneNumber' => '2547XXXXXXXX', 'AccountReference' => '13', 'TransactionDesc' => 'Shopping', ]; $mpesaDaraja->stkPush($stkParams); // stk push status query $stkQueryParams = [ 'CheckoutRequestID' => "ws_CO_290320231617432767XXXXXXXX", ]; $mpesaDaraja->stkPushQuery($stkQueryParams); // transaction status query $statusParams = [ 'Remarks' => "Status test for RCC3LAPCEL", "TransactionID" => "RCC3LAPCEL", "Occasion" => "Optional Value for Occasion" ]; $mpesaDaraja->transactionStatus($statusParams); } }