Skip to content

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
app/Http/Controllers/CheckoutController.php
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.

  1. 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',
    );
  2. Handle the result

    Callbacks arrive as typed Laravel events, not raw JSON.

    public function handle(
    StkCallbackReceived $event,
    ) {
    $event->callback->successful();
    $event->callback->receipt();
    }
  3. 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.

Coverage

Seventeen Daraja APIs, one facade.

Each one is a typed call on Daraja. See every call and endpoint.

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.

Visit eazysoft.africa

Email hello@eazysoft.africa

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.