M-Pesa Ratiba
M-Pesa Ratiba creates a standing order on a customer’s wallet so payments repeat without a prompt each time. Useful for subscriptions, loan repayments, SACCO contributions and insurance premiums.
Create one
Section titled “Create one”use Starnerz\LaravelDaraja\Enums\StandingOrderFrequency;
Daraja::standingOrder()->create( name: 'Gym membership', phone: '0712345678', amount: 3500, startDate: now(), endDate: now()->addYear(), accountReference: 'MEMBER-114', frequency: StandingOrderFrequency::Monthly,);Dates accept a DateTimeInterface or a Ymd string.
The customer receives an STK prompt to authorise the order. If they are not already opted in to Ratiba, Safaricom opts them in as part of the flow.
Frequency
Section titled “Frequency”| Enum | Value |
|---|---|
OneOff |
1 |
Daily |
2 |
Weekly |
3 |
BiWeekly |
4 |
Monthly |
5 |
BiMonthly |
6 |
Quarterly |
7 |
HalfYearly |
8 |
Yearly |
9 |
Pay bill or till
Section titled “Pay bill or till”The transaction type follows your configured initiator.type, or an explicit
receiverType. Pay bill sends Standing Order Pay Bill External Third Party;
a till sends Standing Order Pay Merchant External Third Party.
Response
Section titled “Response”Ratiba does not follow Daraja’s usual envelope. It nests everything under
ResponseHeader/ResponseBody and uses HTTP-style codes:
$response->accepted(); // true for 200 (sync) or 0 (callback)$response->responseCode; // "200"$response->responseRefId;accepted() treats both 200 and 0 as success because the synchronous
response and the callback disagree on which to use.
Error codes
Section titled “Error codes”| Code | Meaning |
|---|---|
1037 |
Prompt never reached the handset |
1031 |
User did not respond in time |
1032 |
Cancelled by the user |
2001 |
Wrong M-Pesa PIN |
1001 |
An existing USSD session is open |
1050 |
Duplicate standing order name |
1051 |
Bad request — a payload field is invalid |
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.