Events
All under Starnerz\LaravelDaraja\Events. They fire only when the package’s
callback routes are enabled; using your own routes means dispatching them
yourself, or skipping events entirely.
StkCallbackReceived
Section titled “StkCallbackReceived”An M-Pesa Express prompt concluded.
public function handle(StkCallbackReceived $event): void{ $callback = $event->callback; // StkCallback
$callback->successful(); $callback->cancelledByUser(); // 1032 $callback->timedOut(); // 1037 or 1031 $callback->receipt(); $callback->amount(); $callback->phoneNumber(); $callback->transactionDate(); $callback->checkoutRequestId; $callback->resultCode; // always a string}C2BPaymentReceived
Section titled “C2BPaymentReceived”A customer paid your short code and Safaricom confirmed it.
$transaction = $event->transaction; // C2BTransaction
$transaction->transactionId;$transaction->amount;$transaction->billReferenceNumber;$transaction->msisdn; // masked$transaction->fullName();$transaction->isPayBill();$transaction->isConfirmation();C2BValidationRequested
Section titled “C2BValidationRequested”Safaricom is asking whether to accept a payment. Informational only — it
cannot decide the outcome, because Safaricom needs an answer in about eight
seconds. Use Daraja::validateC2BUsing() for the decision.
ResultReceived
Section titled “ResultReceived”A result arrived for one of the asynchronous APIs.
public function handle(ResultReceived $event): void{ $event->type; // 'b2c', 'b2b', 'balance', 'reversal', 'transaction-status' $result = $event->result; // ResultCallback
$result->successful(); $result->resultCode; $result->receipt(); $result->amount(); $result->receiverName(); $result->recipientIsRegistered(); $result->hasRealTransactionId(); $result->balances(); // AccountBalances $result->partyNames(); // duplicate keys preserved $result->parameters; // ResultParameters $result->reference; // ResultParameters}type is the URL segment you registered, so one listener can serve every API.
TimeoutReceived
Section titled “TimeoutReceived”Safaricom could not process a request in time.
$event->type; // the URL segment$event->payload; // raw array — the shape is not consistently documentedRegistering listeners
Section titled “Registering listeners”// bootstrap/app.php or a service providerEvent::listen(function (StkCallbackReceived $event) { // …});Queue anything slow:
class RecordPayment implements ShouldQueue{ public function handle(StkCallbackReceived $event): void { /* … */ }}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.