PHP code example of emagombe / mpesa-api

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

    

emagombe / mpesa-api example snippets


use emagombe\Mpesa;

$mpesa = Mpesa::init(
    $api_key,        // API Key from portal
    $public_key,     // Public Key from portal
    "development"    // "development" or "production"
);

$response = $mpesa->c2b([
    "value" => 10,
    "client_number" => "258840000000",
    "agent_id" => 171717,
    "transaction_reference" => 1234567,
    "third_party_reference" => 33333
]);

print_r($response);

$response = $mpesa->b2c([
    "value" => 10,
    "client_number" => "258840000000",
    "agent_id" => 171717,
    "transaction_reference" => 1234567,
    "third_party_reference" => 33333
]);

print_r($response);

$response = $mpesa->b2b([
    "value" => 10,
    "agent_id" => 171717,
    "agent_receiver_id" => 979797,
    "transaction_reference" => 1234567,
    "third_party_reference" => 33333
]);

print_r($response);

$response = $mpesa->reversal([
    "value" => 10,
    "security_credential" => "",
    "indicator_identifier" => "",
    "transaction_id" => "",
    "agent_id" => 171717,
    "third_party_reference" => 33333
]);

print_r($response);

$response = $mpesa->status([
    "transaction_id" => "",
    "agent_id" => 171717,
    "third_party_reference" => 33333
]);

print_r($response);

$response = $mpesa->customer_name([
    "client_number" => "258840000000",
    "agent_id" => 171717,
    "third_party_reference" => 33333
]);

print_r($response);