A full rewrite. See the
upgrade guide.
Changed — breaking
- Requires PHP 8.3 and Laravel 12 or 13, up from PHP 7.3 and Laravel 8.
Laravel 10 and 11 are excluded:
both are past end of life and carry unpatched advisories, so Composer refuses
to install them without disabling its security audit. - The facade is now
Daraja.MpesaApiand theRequests\*classes are
replaced by theApis\*namespace, resolved through the container. - Responses are readonly objects rather than
stdClass. The decoded array
remains available on->raw. ApiRequestExceptionreplacesMpesaApiRequestException, and now carries
errorCode,requestId,statusandpayload.- Configuration keys reorganised —
stk_push.*tostk.*,c2b_url.*to
urls.c2b.*,result_url.*tourls.result.*,logs.*tologging.*. push()argument order changed: the account reference now precedes the
description.- C2B endpoints move to v2 and B2C to v3. C2B v2 masks the MSISDN where
v1 sent a SHA-256 hash, and B2C v3 requires a unique
OriginatorConversationID, which the package generates. - Certificates are per environment. The package now ships both Safaricom
certificates and picks the one matchingmode, where earlier versions bundled
only the production one and used it for sandbox too.
Added
- Dynamic QR, M-Pesa Ratiba, Bill Manager, Pull Transactions, Lipa na Bonga,
B2B Express Checkout, B2C Account Top Up and Business to Pochi. - Opt-in callback routes that dispatch typed events, with parsers that handle
Daraja's shape changes between success and failure. Daraja::validateC2BUsing()for the synchronous C2B validation decision.VerifySafaricomIpmiddleware for restricting callbacks by source address.AccountBalances, which unpacks the delimited balance string into named
accounts.daraja:tokenanddaraja:credentialcommands.- Enums for command IDs, identifier types, transaction types, QR types and
standing order frequencies.
Fixed
STK::push()was uncallable. A required parameter followed an optional
one, so the signature in v1's own README raised anArgumentCountError.str_limit()was removed in Laravel 6, breaking every STK push.daraja:register-urlsread the wrong config namespace (mpesaapi.*
rather thanlaravel-daraja.*), so it always sent empty URLs.- An access token was fetched on every instantiation. Tokens are now cached
for just under their hour-long lifetime. - TLS verification was disabled in sandbox mode.
monolog/monolog ^2conflicted with Laravel 11+. The package now logs
through Laravel's logger.- Configuration problems raise a
ConfigurationExceptionnaming the key or path
instead of surfacing as a PHP warning promoted toErrorException.
Install
composer require starnerz/laravel-darajaRequires PHP 8.3 and Laravel 12 or 13. Applications on Laravel 10 or 11 should stay on ^4.0.