1. Go to this page and download the library: Download ssiva/mpesa-laravel-sdk 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/ */
ssiva / mpesa-laravel-sdk example snippets
namespace YOURNAMESPACE;
use MpesaDaraja;
use Ssiva\MpesaDaraja\Mpesa;
class CheckoutController extends Controller {
public function darajaExamples(
$mpesaDaraja = new MpesaDaraja();
// 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);
}
}