PHP code example of mutebesi / safaricom-mpesa-php

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

    

mutebesi / safaricom-mpesa-php example snippets


'mpesa' => [
    'consumer_key'    => 'YOUR_CONSUMER_KEY',
    'consumer_secret' => 'YOUR_CONSUMER_SECRET',
    'shortcode'       => '174379',
    'passkey'         => 'bfb279...',
    'env'             => 'sandbox',
],

'routing' => [
    'SITE_A' => 'https://website-a.com/api/mpesa-callback',
    'SITE_B' => 'https://website-b.com/payments/webhook',
],

use MpesaSdk\Mpesa;

$mpesa = new Mpesa($key, $secret, 'sandbox');
$result = $mpesa->stkPush(
    $shortcode, $passkey, '100', '2547XXXXXXXX', 'SITE_A_REF123', 'Payment Desc', $callbackUrl
);

use MpesaSdk\DatabaseStore;

$db = new DatabaseStore($host, $dbname, $user, $pass);
$db->setupTable(); // Creates the 'mpesa_transactions' table automatically

$db->saveStkCallback($mpesaData);
bash
git clone https://github.com/mutebesi/safaricom-mpesa-php.git
bash
composer