1. Go to this page and download the library: Download drh/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/ */
drh / mpesa example snippets
use DrH\Mpesa\Facades\STK;
// Simple push
$result = STK::push(amount: 100, phone: '254712345678', ref: 'Order001', description: 'Payment for order');
// Fluent API
$result = STK::amount(100)
->from('254712345678')
->usingReference('Order001', 'Payment for order')
->push();
// Check STK transaction status
$status = STK::status($checkoutRequestId);
use DrH\Mpesa\Facades\Registrar;
Registrar::shortcode(174379)
->onConfirmation('https://example.com/payments/callbacks/c2b-confirmation')
->onValidation('https://example.com/payments/callbacks/c2b-validation')
->submit();