1. Go to this page and download the library: Download crysoft/mpesa-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crysoft / mpesa-bundle example snippets
public function checkoutAction()
{
//Instantiate a new Mpesa Request passing it the Service Container(Don't worry if you dont know what that is,
//Symfony does :-) just do as i do below and you'll be fine)
$mpesa = new Mpesa($this->container);
//Generate a New Transaction Id unique to thsi transaction. You can generate it however you want or simply use an
//Order ID or User ID. it's completely up to you as long as it's unique
// We just provided this method as an easy way out for those of us too lazy to think of a different way of doing it.
$transactionId = $mpesa->generateTransactionNumber();
$response = $mpesa->request(2500)->from(0722000000)->usingReferenceId(456876)->usingTransactionId($transactionId)->transact();
}
public function checkstatusAction()
{
//Use the same Mpesa Class as before
$mpesa = new Mpesa($this->container);
//Chain the requests. Note this Transaction ID has to be the EXACT same one you used for the Mpesa Transaction request above.
$response = $mpesa->usingTransactionId($transactionId)->requestStatus();
//And just to make your life easier we created another class in the Bundle to run through the response from Mpesa and give you the Status
//Use the response above and pass it to the Bundle's MpesaStatus Class
$mpesaStatus = new MpesaStatus($response);
//Use the Classes Getter methods to get the Bits in the Response. Here is an example of how to do it
$customerNumber = $mpesaStatus->getCustomerNumber();
$transactionAmount = $mpesaStatus->getTransactionAmount();
$transactionStatus = $mpesaStatus->getTransactionStatus();
$transactionDate = $mpesaStatus->getTransactionDate();
$mPesaTransactionId = $mpesaStatus->getMpesaTransactionId();
$merchantTransactionId = $mpesaStatus->getMerchantTransactionId();
$transactionDescription = $mpesaStatus->getTransactionDescription();
}
php
new Crysoft\MpesaBundle\CrysoftMpesaBundle(),
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.