mossey / mpesa
A PHP package for Mpesa API
Installs: 59
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 5
Forks: 4
Open Issues: 0
Type:package
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2025-05-04 10:39:41 UTC
README
This package has been abandoned please use https://github.com/safaricom/mpesa-php-sdk
Introduction
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.
Installation using composer
composer require mossey/mpesa
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.
Usage
Confirmation and validation urls
B2C Payment Request
This creates transaction between an M-Pesa short code to a phone number registered on M-Pesa.
$mpesa= new \Mossey\Mpesa\Mpesa();
$b2cTransaction=$mpesa->b2c( $ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );
Account Balance Request
This is used to enquire the balance on an M-Pesa BuyGoods (Till Number)
$mpesa= new \Mossey\Mpesa\Mpesa();
$balanceInquiry=$mpesa->accountBalance($CommandID, $Initiator, $SecurityCredential, $PartyA, $IdentifierType, $Remarks, $QueueTimeOutURL, $ResultURL);
Transaction Status Request This is used to check the status of transaction.
$mpesa= new \Mossey\Mpesa\Mpesa();
$trasactionStatus=$mpesa->transactionStatus($Initiator, $SecurityCredential, $CommandID, $TransactionID, $PartyA, $IdentifierType, $ResultURL, $QueueTimeOutURL, $Remarks, $Occasion);
B2B Payment Request
This is used to transfer funds between two companies.
$mpesa= new \Mossey\Mpesa\Mpesa();
$b2bTransaction=$mpesa->b2b($ShortCode, $CommandID, $Amount, $Msisdn, $BillRefNumber );
STK Push Simulation
This is used to initiate online payment on behalf of a customer.
$mpesa= new \Mossey\Mpesa\Mpesa();
$stkPushSimulation=$mpesa->STKPushSimulation($BusinessShortCode, $LipaNaMpesaPasskey, $TransactionType, $Amount, $PartyA, $PartyB, $PhoneNumber, $CallBackURL, $AccountReference, $TransactionDesc, $Remarks);
STK Push Status Query
This is used to check the status of a Lipa Na M-Pesa Online Payment.
$mpesa= new \Mossey\Mpesa\Mpesa();
$STKPushRequestStatus=$mpesa->STKPushQuery($checkoutRequestID,$businessShortCode,$password,$timestamp);
Confirmation and Validation
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.
Validation
$mpesa= new \Mossey\Mpesa\Mpesa();
$b2bTransaction=$mpesa->validate();
Confirmation
$mpesa= new \Mossey\Mpesa\Mpesa();
$b2bTransaction=$mpesa->confirm();