PHP code example of wasksofts-technology / mpesa_v2

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

    

wasksofts-technology / mpesa_v2 example snippets


 
asksofts\Mpesa_v2\Mpesa;

$mpesa = new Mpesa();

// Configure credentials
$mpesa->config('consumer_key', 'YOUR_CONSUMER_KEY');
$mpesa->config('consumer_secret', 'YOUR_CONSUMER_SECRET');
$mpesa->config('shortcode', '174379');
$mpesa->config('pass_key', 'YOUR_PASSKEY');
$mpesa->config('env', 'sandbox'); // or 'production'

$mpesa->register_url('Completed',$version = "v1");


$response = $mpesa->STKPush(
    100,                    // Amount
    '254708374149',         // Phone
    'INV-001',              // Account Reference
    'Payment for goods'     // Description
);


$mpesa->STKPushQuery('ws_CO_191220191020363925');

$mpesa->b2c(
    500,
    'BusinessPayment',
    '254708374149',
    'Payment for services'
);

$mpesa->b2b(
    1000,
    '600000',
    'BusinessPayBill',
    'ACCT-001',
    'Transfer to supplier'
);

$mpesa->reversal(
    500,
    'LKXXXX1234',
    'Reversal request'
);

$mpesa->accountbalance($IdentifierType, $Remarks, $result_url = 'balance', $timeout_url = 'balance')


$mpesa->transaction_status(
    'LKXXXX1234',
    'Status check'
);


$mpesa->generate_qrcode(
    100,
    'INV-001',
    'MyShop',
    2
);

$mpesa->tax_remittance(
    2500,
    'PRN-123456',
    'Tax payment'
);


$mpesa->standing_order(
    'Monthly Subscription',
    '20240101',
    '20241231',
    500,
    '254708374149',
    'SUB-001',
    'Monthly subscription fee',
    4
);

$mpesa->optin_biller('[email protected]');


$mpesa->optin_update('[email protected]');


$mpesa->single_invoice(
    'EXT-001',
    'John Doe',
    '254708374149',
    '2024-01',
    'January Bill',
    '2024-01-31',
    'ACC-001',
    1500
);

$mpesa->bulk_invoicing([
    ['externalReference' => 'EXT-001'],
    ['externalReference' => 'EXT-002'],
]);


$mpesa->reconciliation(
    '2024-01-15',
    1500,
    'ACC-001',
    'TXN12345',
    '254708374149',
    'John Doe',
    'January Bill',
    'EXT-001'
);

$mpesa->update_invoice_data(/* same signature as reconciliation */);


$mpesa->cancel_single_invoice('EXT-001');