The M-Pesa package for Laravel
M-Pesa payments, written like Laravel.
Every Safaricom M-Pesa API, as ordinary Laravel code. Typed responses, cached tokens, callbacks you can actually test.
composer require starnerz/laravel-daraja- Free and open source (MIT)
- PHP 8.3+, Laravel 12 and 13
- Seventeen Daraja APIs
use Starnerz\LaravelDaraja\Facades\Daraja;
public function pay(Order $order){ $response = Daraja::stk()->push( phone: $order->phone, amount: $order->total, accountReference: $order->reference, );
$order->update([ 'checkout_id' => $response->checkoutRequestId, ]);
return back()->with('status', 'Check your phone.');}How it reads
Three calls from prompt to proof.
Prompt a customer to pay
One call sends an STK push and returns a typed response.
Daraja::stk()->push(phone: '0712345678',amount: 1500,accountReference: 'INV-001',);Handle the result
Callbacks arrive as typed Laravel events, not raw JSON.
public function handle(StkCallbackReceived $event,) {$event->callback->successful();$event->callback->receipt();}Test without a network
Built on Laravel’s HTTP client, so Http::fake() drives it all.
Http::fake(['*stkpush*' => Http::response(['ResponseCode' => '0'],),]);
Tutorials
Learn by building.
Nine complete integrations, from an empty Laravel application to a payment you can prove arrived. Each one says what breaks in production, not only what works in sandbox.
- 02Testing callbacks on localhostReceive and test M-Pesa callbacks from a local Laravel application, with and without a tunnel.5 min read
- 03M-Pesa checkout with LivewireA Livewire component that pushes an M-Pesa prompt and updates itself when the payment lands.5 min read
- 04M-Pesa checkout for a SPA or mobile appTwo Laravel endpoints and a polling client — an M-Pesa checkout for a Vue, React or Flutter front end.8 min read
- 05Receive Paybill and till paymentsTake M-Pesa payments customers start themselves — register the URLs, record the money, and match it to an invoice.8 min read
- 06Take payment by QR codeGenerate M-Pesa QR codes in Laravel, display them, and work out which one was actually paid.7 min read
- 07Send money to customersB2C payouts and refunds in Laravel — credentials, idempotency, results, and the states in between.9 min read
- 08Subscriptions and recurring paymentsRecurring M-Pesa billing in Laravel — M-Pesa Ratiba, and the scheduled prompt everyone builds instead.7 min read
- 09One app, many short codesMulti-tenant M-Pesa in Laravel — per-merchant credentials, scoped calls, and routing callbacks to the right tenant.7 min read
Coverage
Seventeen Daraja APIs, one facade.
Each one is a typed call on Daraja. See every call and endpoint.
Taking payments
Paying out
Built and maintained by Eazysoft
Laravel Daraja is free and open source, and it stays that way. Eazysoft is the software company behind it. If you would rather have your M-Pesa integration, or anything else, built for you, talk to us. Running M-Pesa in production already?Mizani is our dashboard for it.
Laravel Daraja is free and open source, maintained by eazysoft.
An independent open-source project, not affiliated with, endorsed by, or sponsored by Safaricom PLC or Laravel LLC. M-Pesa and Daraja are trademarks of Safaricom PLC; Laravel is a trademark of Laravel LLC. Used here only to say what this package works with.