Conversational M-Pesa: How AI Agents Handle Payments Through Chat
Your customer asks to pay an invoice. The AI agent confirms the amount, initiates an M-Pesa push, and reconciles the transaction — all in one conversation. Here's exactly how we built it and what to watch out for.
Lawrence
Founder, Chatzuri
For businesses operating in Kenya, Tanzania, and Uganda, M-Pesa is not an optional payment integration — it's where your customers' money lives. Building an AI agent that can receive payments, confirm transactions, and handle payment-related queries is a direct revenue enabler, not just a support tool. Here's how the integration works in practice.
The Conversation Architecture
A conversational payment flow has four stages: intent detection (the customer mentions payment, invoice, or a specific amount), confirmation (the agent summarises what will be charged and requests explicit consent), execution (the agent initiates the M-Pesa STK push to the customer's phone), and reconciliation (the agent confirms receipt and updates the relevant system record).
Each stage has edge cases. Intent detection needs to distinguish 'I want to pay my invoice' from 'I already paid — why is my account still locked?' Confirmation must handle the customer not responding (session timeout), responding with an incorrect amount, or replying in an unexpected language. Execution can fail due to insufficient M-Pesa balance, network timeout, or the customer rejecting the STK push. Reconciliation needs to handle delayed callbacks from the M-Pesa API, which occasionally arrive 3–5 minutes late.
What the Implementation Looks Like
In Chatzuri, payment flows are implemented as tool definitions — structured API calls that the AI agent can invoke when a payment intent is detected. The tool takes an account identifier and amount, calls the M-Pesa Daraja API to initiate the STK push, and returns a transaction reference. The agent then monitors for the callback and updates the conversation accordingly.
- STK push timeout (default 30s): agent prompts the customer to check their phone and retry
- Insufficient balance: agent suggests alternative amounts or payment scheduling
- Wrong PIN: handled by M-Pesa natively — agent confirms final transaction status via callback
- API timeout: agent logs the attempt and offers to retry or escalate to a human agent
Security Considerations
Payment flows require additional safeguards that standard AI agent conversations don't need. The agent should never store M-Pesa PINs or full phone numbers in conversation logs. Transaction amounts should be confirmed explicitly before initiating any payment. For amounts above a configurable threshold (typically $50), adding a second confirmation step reduces disputed transaction rates significantly.
“After adding the conversational M-Pesa flow on WhatsApp, our payment collection rate on outstanding invoices went from 34% to 71% in the first month. Customers pay when it's frictionless.”
— CFO, Kenyan SaaS company
The combination of proactive payment reminders (sent via WhatsApp at configurable intervals) and a one-tap payment completion flow in the same conversation is the specific configuration that drives collection rates up. The friction reduction is enormous: instead of receiving an SMS, switching to a mobile banking app, and navigating to bill payment, the customer taps 'Pay' in the same conversation where they received the invoice.
Ready to build your AI agent?
Deploy in under 10 minutes — no code required
Join 2,000+ businesses using Chatzuri to automate customer support across WhatsApp, SMS, Telegram, and more.
Build for free