A Laravel package for the Safaricom M-Pesa Daraja APIs.
starnerz/laravel-daraja is a Laravel package for a laravel package for the safaricom m-pesa daraja apis..
It currently has 7 GitHub stars and 889 downloads on Packagist (latest version v5.4.0).
Install it with composer require starnerz/laravel-daraja.
Discover more Laravel packages by starnerz
or browse all Laravel packages to compare alternatives.
Last updated
Every Safaricom M-Pesa Daraja API, as ordinary Laravel code. Seventeen APIs — STK Push, C2B, B2C, B2B, Dynamic QR, M-Pesa Ratiba, Bill Manager and the rest — with typed responses, cached tokens, and callbacks you can actually test.
📖 Documentation: laraveldaraja.com — new here? Start with the STK Push tutorial.
composer require starnerz/laravel-daraja
use Starnerz\LaravelDaraja\Facades\Daraja;
$response = Daraja::stk()->push(phone: '0712345678', amount: 1500, accountReference: 'INV-001');
use Starnerz\LaravelDaraja\Events\StkCallbackReceived;
Event::listen(function (StkCallbackReceived $event) {
if ($event->callback->successful()) {
Order::markPaid($event->callback->checkoutRequestId, $event->callback->receipt());
}
});
Requires PHP 8.3+ and Laravel 12 or 13. The credentials, .env keys and
callback routes are in Installation and
Configuration.
The snippet above works in sandbox. These are where M-Pesa integrations break in production, and each has a page:
Http::fake() drives the whole package.
TestingComplete integrations, from an empty Laravel application to a payment you can prove arrived:
| Taking payments | Paying out | Keeping the books | |---|---|---| | M-Pesa Express (STK Push) | Business to Customer | Account Balance | | Customer to Business | Business to Pochi | Transaction Status | | Dynamic QR | Business to Business | Reversal | | M-Pesa Ratiba | B2B Express Checkout | Pull Transactions | | Lipa na Bonga | | Bill Manager |
Every call and endpoint: API overview.
v5 is a rewrite. See the upgrade guide. Laravel 10
and 11 are not supported; applications on those versions should stay on ^4.0.
See CONTRIBUTING.md.
Questions about the package belong in the issue tracker. If you would rather have an integration built or reviewed, the maintainer takes that on as paid work through Eazysoft.
Mizani is the paid M-Pesa dashboard built on this package: every payment, the callbacks that never arrived, and reconciliation against Safaricom, in one screen. This package stays free and MIT-licensed either way.
Report vulnerabilities to [email protected] rather than the issue tracker. See SECURITY.md.
MIT. See LICENSE.