A PHP package for Mpesa API
This package has been abandoned please use https://github.com/safaricom/mpesa-php-sdk, (*1)
Introduction, (*2)
This package seeks to help php developers implement the various Mpesa APIs without much hustle. It is based on the REST API whose documentation is available on http://developer.safaricom.co.ke., (*3)
Installation using composer
composer require mossey/mpesa
, (*4)
Configuration
At your project root, create a .env file and in it set the consumer key and consumer secret as follows
consumer_key= [consumer key]
consumer_secret=[consumer secret]
For Laravel users, open the Config/App.php file and add \Mossey\Mpesa\MpesaServiceProvider::class
under providers and 'Mpesa'=> \Mossey\Mpesa\MpesaServiceProvider::class
under aliases., (*5)
Usage, (*6)
Confirmation and validation urls, (*7)
B2C Payment Request, (*8)
This creates transaction between an M-Pesa short code to a phone number registered on M-Pesa., (*9)
$mpesa= new \Mossey\Mpesa\Mpesa();
, (*10)
$b2cTransaction=$mpesa->b2c( $ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );
, (*11)
Account Balance Request, (*12)
This is used to enquire the balance on an M-Pesa BuyGoods (Till Number), (*13)
$mpesa= new \Mossey\Mpesa\Mpesa();
, (*14)
$balanceInquiry=$mpesa->accountBalance($CommandID, $Initiator, $SecurityCredential, $PartyA, $IdentifierType, $Remarks, $QueueTimeOutURL, $ResultURL);
, (*15)
Transaction Status Request This is used to check the status of transaction., (*16)
$mpesa= new \Mossey\Mpesa\Mpesa();
, (*17)
$trasactionStatus=$mpesa->transactionStatus($Initiator, $SecurityCredential, $CommandID, $TransactionID, $PartyA, $IdentifierType, $ResultURL, $QueueTimeOutURL, $Remarks, $Occasion);
, (*18)
B2B Payment Request, (*19)
This is used to transfer funds between two companies., (*20)
$mpesa= new \Mossey\Mpesa\Mpesa();
, (*21)
$b2bTransaction=$mpesa->b2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );
, (*22)
STK Push Simulation, (*23)
This is used to initiate online payment on behalf of a customer., (*24)
$mpesa= new \Mossey\Mpesa\Mpesa();
, (*25)
$stkPushSimulation=$mpesa->STKPushSimulation($BusinessShortCode, $LipaNaMpesaPasskey, $TransactionType, $Amount, $PartyA, $PartyB, $PhoneNumber, $CallBackURL, $AccountReference, $TransactionDesc, $Remarks);
, (*26)
STK Push Status Query, (*27)
This is used to check the status of a Lipa Na M-Pesa Online Payment., (*28)
$mpesa= new \Mossey\Mpesa\Mpesa();
, (*29)
$STKPushRequestStatus=$mpesa->STKPushQuery($checkoutRequestID,$businessShortCode,$password,$timestamp);
, (*30)
Confirmation and Validation, (*31)
These are required in order to complete most of the transaction. Without these the transactions won't be complete. Therefore, register your URLS in the developer portal and soon as you're done be sure to ensure your validation URL and confirmation URL contain the following., (*32)
Validation, (*33)
$mpesa= new \Mossey\Mpesa\Mpesa();
, (*34)
$b2bTransaction=$mpesa->validate();
, (*35)
Confirmation, (*36)
$mpesa= new \Mossey\Mpesa\Mpesa();
, (*37)
$b2bTransaction=$mpesa->confirm();
, (*38)