Installation
Requirements
Section titled “Requirements”- PHP 8.3 or higher
- Laravel 12 or 13
- The
opensslandjsonextensions
Laravel 10 and 11 are not supported. Both are past end of life and carry
unpatched advisories, so Composer refuses to install them without disabling its
security audit. Applications on those versions should stay on ^4.0.
Install
Section titled “Install”composer require starnerz/laravel-darajaThe service provider and the Daraja facade are registered automatically.
Publish the configuration
Section titled “Publish the configuration”php artisan vendor:publish --tag=laravel-daraja-configThat writes config/laravel-daraja.php. Every value reads from an environment
variable, so you can also skip publishing and set only the .env keys below.
Minimum environment
Section titled “Minimum environment”DARAJA_MODE=sandboxDARAJA_CONSUMER_KEY=your-consumer-keyDARAJA_CONSUMER_SECRET=your-consumer-secretThat is enough for M-Pesa Express once you add the STK values:
DARAJA_STK_SHORTCODE=174379DARAJA_STK_PASS_KEY=your-passkeyDARAJA_STK_CALLBACK_URL=https://your-domain.test/daraja/stkAPIs that move money on your behalf also need an initiator:
DARAJA_INITIATOR_NAME=testapiDARAJA_INITIATOR_CREDENTIAL=your-initiator-passwordDARAJA_INITIATOR_SHORTCODE=600000See Configuration for the complete list.
Verify it works
Section titled “Verify it works”php artisan daraja:tokenA successful run prints your mode and an access token, which confirms the
consumer key and secret are valid for that environment. Anything else raises a
ConfigurationException or AuthenticationException naming the problem.
Certificates
Section titled “Certificates”The APIs that need a SecurityCredential — B2C, B2B, Reversal, Account Balance
and Transaction Status — encrypt your initiator password with a Safaricom
certificate.
Nothing is required of you. The package ships a certificate for each
environment and picks the one matching DARAJA_MODE.
To use your own copy instead:
DARAJA_CERTIFICATE_PATH=/full/path/to/production.cerLaravel 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.