Category
Payments & Fintech
Every guide on Payments & Fintech from Code With Karani - 29 field-tested articles on Payments & Fintech for developers and teams.
29 articles
December 2026
July 2026
Your spare Android phone is a payment gateway: an offline-first SMS relay for M-Pesa
M-Pesa till confirmations arrive as an SMS, and Daraja is not open to every merchant. So we turned a spare Android phone into a self-hosted SMS-to-HTTP gateway: encrypted on-device, HMAC-signed on the wire, and built so that it never loses a message.
14 min read
A payment source, not a payment parser: what keeping the pipe dumb actually buys
The SMS gateway could have extracted the M-Pesa transaction code on the phone. It deliberately does not. Here is what that bought, what it cost, and the boundary question every integration eventually has to answer: where does meaning belong?
11 min read
Lipa Na M-Pesa Online With Daraja: The Callback Is the Payment, Not the Response
A working STK Push against Safaricom's Daraja API, and the mistake almost every first integration makes: treating the 200 OK from the push as proof that money moved.
6 min read
Daraja API in Production: STK Push, C2B and B2C With Callbacks That Actually Work
A build-order guide to Safaricom's Daraja API with real payloads: OAuth token caching, STK Push, C2B v2 registration, B2C v3 with RSA security credentials, and the callback URL rules nobody documents.
7 min read
Your M-Pesa Callback Will Fire Twice: Idempotency, Retries and the 1037 Problem
Daraja callbacks are unreliable notifications, not a source of truth. Seven production failure modes, with the database constraints, pollers and parsers that make double charges structurally impossible.
7 min read
M-Pesa Reconciliation That Scales: From Paybill Statement to Trial Balance
Stop reconciling in spreadsheets. A three-way match between the Safaricom statement, your callback events and a double-entry ledger, with named break categories and a daily close job in Python and SQL.
6 min read
Build a Payments Port, Not a Daraja Wrapper: Provider-Agnostic Money Movement in Africa
The right payments abstraction is a normalised state machine plus a normalised event, not a charge() function. Ports, adapters, webhook signature handling, minor-unit traps and config-driven routing.
7 min read
June 2026
KRA eTIMS Survival Guide: OSCU, cmcKey and the Rules the Spec Leaves Out
eTIMS is a fiscal device protocol, not an invoicing API. Real OSCU endpoints, the device handshake, a full saveTrnsSalesOsdc payload, the tax type codes, and six gotchas that will get invoices rejected.
7 min read
Daraja invalid access token: 401.003.01 is not 404.001.03
Two Daraja errors say 'Invalid Access Token' and mean different things. One is a wrong-environment token you can fix in code, the other is an entitlement problem only Safaricom can fix.
7 min read
KES, TZS and UGX: Multi-Currency Ledgers and the FX Gap Eating Your Margin
There is no single exchange rate in East Africa. Minor-unit traps, largest-remainder allocation, quote expiry, realised versus unrealised FX, and a schema that records the rate you actually transacted at.
8 min read
M-Pesa 1001 Transaction In Progress: Why Retrying Instantly Fails
Daraja error 1001 is a subscriber lock, not a transient error, and the usual retry loop makes it worse. The cooldown, the state machine and the copy customers can act on.
7 min read
Daraja Returns 429 With a Body Your Error Parser Cannot Read
An HTTP 429 from M-Pesa Daraja is an Apigee spike arrest fault, not Daraja JSON, so most error handlers log undefined and swallow it. Here is how to classify, pace and back off.
8 min read
M-Pesa C2B Sandbox Callbacks Only Fire Half the Time
Daraja's C2B sandbox drops most confirmation callbacks, so developers debug ngrok and nginx for days. Here is why it happens and the deploy-first workflow that replaces it.
7 min read
M-Pesa 'Unable to Send STK Prompt' (1025/9999): Check the Length
Daraja returns 1025 for both a too-long TransactionDesc and a genuine M-Pesa outage. One retries successfully, the other never will. Here is how to tell them apart.
7 min read
M-Pesa error 2001 invalid initiator: the stale certificate trap
M-Pesa B2C returns ResultCode 2001, 'The initiator information is invalid.' It is rarely the initiator name. It is usually a certificate copied from the wrong place.
8 min read
M-Pesa Daraja 500.001.1001 when your consumer key is actually correct
Daraja's 'Wrong credentials' error hides two unrelated causes, and neither is your API key. Usually it is a timestamp generated twice that drifts by one second.
9 min read
M-Pesa "Invalid BusinessShortCode": The Python requests Bug Behind It
Daraja error 400.002.02 blames your shortcode, but the real cause is usually data=payload instead of json=payload in Python requests. Here is how to prove it.
7 min read
M-Pesa ResultCode 4999 Is Not a Failure: Handling Undocumented Daraja Codes
Daraja's STK query can return 4999, which no Safaricom document defines. Treating it as failed causes double charges. Here is the three-bucket model that prevents it.
9 min read
M-Pesa Invalid Access Token After Go-Live: It Is Not Your OAuth Code
Daraja returns 404.001.03 Invalid Access Token when your shortcode is not whitelisted, not just when the token is bad. One curl tells you which, and saves two days.
9 min read
May 2026
Daraja Error 1032 'Request Cancelled by User' Is Not a Bug in Your M-Pesa Integration
M-Pesa STK Push ResultCode 1032 means the customer pressed Cancel, not that anything broke. Stop paging on it and handle it as the user action it is.
6 min read
Daraja 404.001.03: Cache the Access Token, Don't Mint a New One
M-Pesa Daraja tokens live about an hour. Fetching one per request gets you throttled; caching forever gets you 404.001.03. The proactive refresh pattern Safaricom never documents.
9 min read
M-Pesa error 1037: the STK push that never reached the phone
Daraja 1037 is not a declined payment. It means the handset never answered the SIM toolkit prompt. How to classify it, poll for it, and retry without creating duplicate orders.
9 min read
M-Pesa 1019 vs 1037 vs 1032: three STK failures that look identical and are not
1019 means the prompt arrived and the user was too slow. 1037 means it never arrived. 1032 means they cancelled. Conflating them hides whether your problem is network, copy or timeout.
8 min read