Installation
Requirements
Section titled “Requirements”- PHP 8.3 or higher
- Laravel 12 or 13
- The
opensslandjsonextensions
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.cer