PHP code example of akika / laravel-mpesa
1. Go to this page and download the library: Download akika/laravel-mpesa 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/ */
akika / laravel-mpesa example snippets
use Akika\LaravelMpesa\Mpesa;
$mpesa = new Mpesa();
$token = $mpesa->getToken();
$balance = $mpesa->getBalance();
$response = $mpesa->c2bRegisterUrl();
php artisan mpesa:register-c2b-urls
$response = $mpesa->c2bSimulate($amount, $phoneNumber, $billRefNumber, $commandID);
$response = $mpesa->stkPush($accountNumber, $phoneNumber, $amount, $transactionDesc);
$response = $mpesa->stkPushStatus($checkoutRequestID);
$response = $mpesa->reverse($transactionId, $amount, $receiverShortCode, $remarks);
$response = $mpesa->b2cTransaction($oversationId, $commandID, $msisdn, $amount, $remarks, $ocassion);
$response = $mpesa->b2cTopup($accountReference, $receiverShortCode, $amount, $remarks);
$response = $mpesa->b2bPaybill($destShortcode, $amount, $remarks, $accountNumber, $resultUrl, $timeoutUrl, $requester = null);
$response = $mpesa->b2bBuyGoods($destShortcode, $amount, $remarks, $accountNumber, $resultUrl, $timeoutUrl, $requester = null);
$response = $mpesa->b2bExpressCheckout($destShortcode, $partnerName, $amount, $paymentReference, $requestRefID);
$response = $mpesa->dynamicQR($merchantName, $refNo, $trxCode, $cpi, $size, $amount = null);
$response = $mpesa->billManagerOptin($email, $phoneNumber, $sendReminders);
$response = $mpesa->sendInvoice($reference, $billedTo, $phoneNumber, $billingPeriod, $invoiceName, $dueDate, $amount, $items);
$response = $mpesa->taxRemittance($amount, $receiverShortCode, $accountReference, $remarks);
$response = $mpesa->ratiba($name, $startDate, $endDate, $transactionType, $type, $amount, $msisdn,$accountReference, $transactionDesc, $frequency)
$response = $mpesa->mpesaTransactionsHistory($startDate, $endDate, $offset = 0);
{
"ResponseRefID": "8bab-42cc-bb85-5056a6c01e6915928124",
"ResponseCode": "1000",
"ResponseMessage": "Success",
"Response": [
[
{
"transactionId": "XXXXXXXXX",
"trxDate": "2025-01-24T10:56:11+03:00",
"msisdn": 2547XXXXXXXX,
"sender": "MPESA",
"transactiontype": "c2b-buy-goods-debit",
"billreference": "",
"amount": "2697.0",
"organizationname": "VENDOR"
}
]
]
}
{
"OriginatorConversationID": "5118-111210482-1",
"ConversationID": "AG_20230420_2010759fd5662ef6d054",
"ResponseCode": "0",
"ResponseDescription": "Accept the service request successfully."
}
{
"Result":
{
"ResultType": "0",
"ResultCode":"0",
"ResultDesc": "The service request is processed successfully",
"OriginatorConversationID":"626f6ddf-ab37-4650-b882-b1de92ec9aa4",
"ConversationID":"12345677dfdf89099B3",
"TransactionID":"QKA81LK5CY",
"ResultParameters":
{
"ResultParameter":
[{
"Key":"DebitAccountBalance",
"Value":"{Amount={CurrencyCode=KES, MinimumAmount=618683, BasicAmount=6186.83}}"
},
{
"Key":"Amount",
"Value":"190.00"
},
{
"Key":"DebitPartyAffectedAccountBalance",
"Value":"Working Account|KES|346568.83|6186.83|340382.00|0.00"
},
{
"Key":"TransCompletedTime",
"Value":"20221110110717"
},
{
"Key":"DebitPartyCharges",
"Value":""
},
{
"Key":"ReceiverPartyPublicName",
"Value":000000– Biller Companty
},
{
"Key":"Currency",
"Value":"KES"
},
{
"Key":"InitiatorAccountCurrentBalance",
"Value":"{Amount={CurrencyCode=KES, MinimumAmount=618683, BasicAmount=6186.83}}"
}]
},
"ReferenceData":
{
"ReferenceItem":[
{"Key":"BillReferenceNumber", "Value":"19008"},
{"Key":"QueueTimeoutURL", "Value":"https://mydomain.com/b2b/businessbuygoods/queue/"}
]
}
}
}
{
"Result":
{
"ResultType":0,
"ResultCode":2001,
"ResultDesc":"The initiator information is invalid.",
"OriginatorConversationID":"12337-23509183-5",
"ConversationID":"AG_20200120_0000657265d5fa9ae5c0",
"TransactionID":"OAK0000000",
"ResultParameters":{
"ResultParameter":{
"Key":"BillReferenceNumber",
"Value":12323333
}
},
"ReferenceData":{
"ReferenceItem":[
{
"Key":"BillReferenceNumber",
"Value":12323333
},
{
"Key":"QueueTimeoutURL",
"Value":"https://internalapi.safaricom.co.ke/mpesa/abresults/v1/submit"
}
{
"Key":"Occassion"
}
]
}
}
}
bash
php artisan mpesa:install