LaravelPackages.net
Acme Inc.
Toggle sidebar
starnerz/laravel-daraja

A Laravel package for the Safaricom M-Pesa Daraja APIs.

889
7
v5.4.0
About starnerz/laravel-daraja

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

Laravel Daraja

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.

Tests Static analysis Latest version Downloads License

At a glance

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.

Before you take real money

The snippet above works in sandbox. These are where M-Pesa integrations break in production, and each has a page:

  • Callbacks that never arrive, or arrive twice. A payment can succeed with no callback reaching you, a confirmation can be delivered more than once, and Pull Transactions only reaches back 48 hours. Reconciling payments
  • Trusting a callback. Safaricom does not sign callbacks, so each one is a claim to check, not a record. Handling callbacks
  • Going live. Production credentials, operator roles and Safaricom's approval. Going live
  • Testing without a phone. Http::fake() drives the whole package. Testing

Tutorials

Complete integrations, from an empty Laravel application to a payment you can prove arrived:

  1. Accept M-Pesa payments
  2. Testing callbacks on localhost
  3. M-Pesa checkout with Livewire
  4. M-Pesa checkout for a SPA or mobile app
  5. Receive Paybill and till payments
  6. Take payment by QR code
  7. Send money to customers
  8. Subscriptions and recurring payments
  9. One app, many short codes

Supported APIs

| 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.

Upgrading from 4.x

v5 is a rewrite. See the upgrade guide. Laravel 10 and 11 are not supported; applications on those versions should stay on ^4.0.

Contributing

See CONTRIBUTING.md.

Help and Mizani

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.

Security

Report vulnerabilities to [email protected] rather than the issue tracker. See SECURITY.md.

Licence

MIT. See LICENSE.

Comments