PHP code example of abdulmueid / mpesa

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

    

abdulmueid / mpesa example snippets


    $config = \abdulmueid\mpesa\Config::loadFromFile('/path/to/config.php');
    

    $transaction = new \abdulmueid\mpesa\Transaction($config);
    

       $c2b = $transaction->c2b(
           float $amount,
           string $msisdn,
           string $reference,
           string $third_party_reference
       );
        

       $b2c = $transaction->b2c(
           float $amount,
           string $msisdn,
           string $reference,
           string $third_party_reference
       );
       

       $b2b = $transaction->b2b(
            float $amount,
            string $receiver_party_code,
            string $reference,
            string $third_party_reference
       );
       

       $reversal = $transaction->reversal(
           float $amount,  
           string $transaction_id,
           string $third_party_reference
       );
       

       $query = $transaction->query(
           string $query_reference,
           string $third_party_reference
       );
       

$c2b = $transaction->c2b(...);

if($c2b->getCode() === 'INS-0') {
    // Transaction Successful, Do something here
}