The most common mobile money API errors in Tanzania are: timeouts (customer does not respond to the payment prompt within the allowed window), insufficient funds (customer does not have enough in their wallet), invalid phone numbers (wrong format or non-existent number), callback delivery failures (your server was unreachable when the callback arrived), expired authentication tokens or session keys, and duplicate callback processing. Each error needs specific handling in your code. The good news: these errors are the same across M-Pesa, Tigo Pesa, and Airtel Money. The error codes differ, but the categories and handling strategies are identical.
Timeouts are the error you will deal with most often. The scenario: you send a payment request, the customer gets a prompt on their phone, and they do not respond. Maybe they are away from their phone. Maybe their phone is off. Maybe they changed their mind. The prompt expires after 60 to 90 seconds, and you get a timeout callback (or no callback at all).
How to handle timeouts:
Timeouts are not really errors in the traditional sense. They are a normal part of the mobile money flow. Design for them as an expected state, not an exception.
The second most common error category: the customer tries to pay but something fails on their end.
Insufficient funds: The customer does not have enough money in their mobile money wallet to cover the payment amount. You receive a callback indicating the failure reason.
How to handle it:
Wrong PIN: The customer enters the wrong PIN. Most providers allow a few attempts before locking the wallet. You receive a failure callback.
Customer declined: The customer sees the prompt and actively cancels it. You receive a callback indicating the customer declined.
Account restrictions: The customer's mobile money account may be suspended, locked, or under a transaction limit. These are less common but produce specific error codes.
All of these are customer-side issues. Your code cannot fix them. What your code can do is provide clear, helpful messages so the customer understands what happened and what to do next. Map every provider error code to a human-readable message.
Get weekly developer tips
Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.
No spam. Unsubscribe anytime.
These errors happen between your server and the mobile money API, before the customer is even involved.
Expired session key or access token:
Invalid credentials:
Network errors and timeouts on the API call itself:
SSL/TLS errors:
This is the error category that causes the most confusion: you sent a payment request, the customer may or may not have confirmed, and you never receive a callback. Your system is stuck in "pending" state.
Why callbacks fail to arrive:
How to handle missing callbacks:
A well-built payment integration treats the callback as the primary mechanism and the status check as the fallback. Both should lead to the same result for any given transaction. If they disagree, the status check (which queries the provider directly) is the source of truth.
Sometimes you receive the same callback twice. Maybe the provider's retry logic kicked in. Maybe a network glitch caused a duplicate delivery. If your code processes the same success callback twice, you might credit the customer's order twice, send two confirmation emails, or create duplicate records.
The solution: idempotent callback handling.
Every callback includes a unique transaction reference (different names per provider, but the concept is the same). When your callback handler runs:
This logic is simple but critical. Without it, your system is vulnerable to duplicate processing, and mobile money providers can and do send duplicate callbacks.
Store the raw callback payload alongside the transaction reference. If you ever need to re-process a callback (because your handler had a bug), the raw data lets you replay it correctly.
This idempotency pattern is identical across all three Tanzanian providers and across every mobile money API globally. Learn it once, use it everywhere.
Rather than handling each error ad hoc, build a structured error handling strategy:
1. Categorize errors.
2. Map error codes to messages. Create a mapping from provider-specific error codes to customer-friendly messages. Do this once per provider and keep it updated as the provider adds new error codes.
3. Log and monitor. Log every error with the full context: timestamp, transaction reference, error code, error message, request payload, response payload. Set up alerts for error rate spikes. If your timeout rate suddenly jumps from 5% to 30%, something has changed at the provider level and you need to investigate.
4. Learn the pattern once. McTaba's M-Pesa Integration for Developers course (KES 9,999 / ~TZS 200,000) covers error handling as a core topic. The patterns are the same for Vodacom, Tigo Pesa, Airtel Money, and any aggregator. The error codes differ, but the handling architecture does not.
Create a free McTaba Academy account. Access starter lessons, join the community, and explore at your own pace.
Create Free Account