PHP code example of kabangi / mpesa

1. Go to this page and download the library: Download kabangi/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/ */

    

kabangi / mpesa example snippets

 

abangi\Mpesa\Init as Mpesa;


Kabangi\Mpesa\Init as Mpesa;

// You can also pass your own config here.
// Check the folder ./config/mpesa.php for reference

$mpesa = new Mpesa();
try {

    $response = $mpesa->STKPush([
        'amount' => 10,
        'transactionDesc' => '',
        'phoneNumber' => '',
    ]);
    
    $response = $mpesa->B2C([
        'amount' => 10,
        'accountReference' => '12',
        'callBackURL' => 'https://example.com/v1/payments/C2B/confirmation',
        'queueTimeOutURL' => 'https://example.com/v1/payments/C2B/confirmation',
        'resultURL' => 'https://example.com/v1/payments/C2B/confirmation',
        'Remarks' => 'Test'
    ]);


    // $mpesa->STKStatus([]);
    
    // $mpesa->C2BRegister([]);
    
    // $mpesa->STKPush([]);
    
    // $mpesa->C2BSimulate([]);
    
    // $mpesa->B2C([])
    
    // $mpesa->B2B([]);
    
    // $mpesa->accountBalance([])
    
    // $mpesa->reversal([]);
    
    // $mpesa->transactionStatus([]);
    
    // $mpesa->reversal([]);
}catch(\Exception $e){
    $response = json_decode($e->getMessage());
}

header('Content-Type: application/json');
echo json_encode($response);