Mobile Payment Integration for IoT in Kenya: A Practical Guide
Connected devices in Kenya are increasingly paid for, not just monitored. A smart meter credits power when a customer pays, a vending machine dispenses after a payment is confirmed, and a solar controller unlocks for the days a customer has paid for. In each case, the device needs a reliable signal from the payment system, and the payment system needs to know which device it belongs to.
This guide explains how to integrate mobile money payments into IoT devices in Kenya. It covers the payment flow, the messages a device or its backend needs, how to match each payment to one device, and how to keep the device safe when messages repeat or arrive late. It’s written for IoT developers, device makers, and operators who connect hardware to M-Pesa.
Where the payment sits in an IoT system
An IoT payment system has four layers:
- The device measures, dispenses, credits or unlocks.
- The device platform runs the logic: prices, balances, stock, and rules for when to act.
- The payment layer requests the mobile money prompt and reports the result.
- The customer approves the payment on their own phone with their PIN.
The payment layer should not decide what a device does. It confirms that money has moved and tells the device platform, which then decides the action. Keeping those roles separate makes each part easier to test and easier to change later.
The integration flow
A typical sale follows this sequence:
- The customer requests a service from the device, its app, or a renewal reminder.
- The platform creates a payment request with the amount, the customer’s M-Pesa number, and a reference that identifies the device and this purchase.
- The customer approves the M-Pesa STK Push prompt on their phone.
- The payment provider confirms the result to the platform through a webhook, which is a message sent to an HTTPS address you control.
- The platform instructs the device to credit, dispense or unlock for the period paid.
The device should never act on the prompt alone. A prompt approved on a phone is not the same as money received. The action must follow the confirmed result.
Matching each payment to one device
The reference you send with each payment is the link between the money and the device. The payment provider returns it in the confirmation, and your platform uses it to find the right device.
Design the reference with three rules in mind:
- Unique per attempt. Each purchase attempt gets its own reference, so two payments never share one.
- Tied to the device. The reference should identify the meter, machine, cylinder, or controller, so the platform knows where to send the action.
- Traceable. A support team should be able to look up any payment from its reference and see what it did.
If a confirmation arrives with a reference that doesn’t match any device, send it to a person for review. Don’t guess the device from the amount or the phone number.
Acting only on confirmed payments
The most important rule in IoT payments is that the device acts only on a confirmed state. Pending, processing, failed and cancelled payments should leave the device idle.
Check three things before the device acts:
- State: the payment is complete.
- Amount and currency: these match the price the device platform expected for that service.
- Reference: it maps to a device and a purchase that is still open.
If any check fails, don’t act. Record the event, and let the customer know what happened.
Handling repeated and out-of-order messages
Payment messages can arrive more than once, and not always in the order they were sent. A payment can pass through several states, and an earlier state may arrive after a later one. The platform must be safe to repeat.
The practical approach is to key each action on the purchase reference together with the state. Store the states already handled, and act only on the first completed state for a given purchase. A repeat of the same message should do nothing.
This matters most where a double action has a real cost:
- Smart meters: a double credit means lost revenue or a customer owed power they didn’t buy.
- Vending and water dispensing: a double response means lost product or water.
- Solar and gas: a double unlock extends access beyond what was paid for.
Respond to the webhook quickly with a success code, and do slower device work in the background. A payment provider counts any response other than a success code as a failed delivery, which can trigger retries.
Keeping the device and the payment record separate
A payment can succeed while the device fails to respond. The network may be down, the device may be offline, or the command may time out. These are two different failures, and they should be handled separately.
Keep two records for each purchase: the payment record, which shows what was paid, and the device record, which shows what the device was told to do and whether it confirmed. If the payment is complete but the device hasn’t responded, retry the device action. Don’t ask the customer to pay again.
Set a limit on retries, and flag any purchase that still hasn’t reached the device after that. A person should check those cases, because a stuck device with a paid customer is a support problem that grows quickly.
Connectivity and offline devices
Many IoT devices in Kenya sit where the network is weak or intermittent. A meter in a rural area, a solar controller on a rooftop, or a vending machine in a busy estate may not always be online when the payment completes.
Plan for that in three ways:
- Queue the device action so it runs when the device reconnects, with a clear expiry.
- Show the customer the status so they know a payment was received and the service is pending.
- Confirm the device’s state when it comes back online, so the platform knows the action took effect.
A customer who pays for a day of solar power should not lose that day because the controller was offline for an hour. A queued action with a clear rule solves that. Our guide to M-Pesa payment collections for PAYG solar businesses covers the instalment side of this in more detail.
Testing before launch
IoT payment systems fail at the edges. Test these cases with real devices before opening to customers:
- A confirmed payment that reaches the device.
- A cancelled prompt, and a phone that can’t be reached.
- A repeated confirmation for the same purchase.
- A confirmation with an unknown reference.
- A payment that completes while the device is offline.
- A wrong amount, and a currency mismatch.
Time the full flow from payment to device response on a real phone and a real device. Record the results, and use them to set customer expectations.
Reconciliation for connected businesses
Each day, compare the device records with the payment records. Every confirmed payment should have a matching device action, and every device action should have a matching confirmed payment. Gaps in either direction need investigation.
Track a few figures each week:
- Success rate: the share of payments that reached the device and produced the expected action.
- Stuck purchases: payments confirmed but not acted on, after retries.
- Failure reasons: cancelled prompts, unreachable phones, and device timeouts, counted separately.
- Revenue by device and by network: the basis for planning and for spotting faults.
A device that repeatedly fails to respond is often a connectivity or hardware issue, not a payment issue. The records will show where to look. If your devices serve customers on more than one network, see M2M payments across M-Pesa, Airtel Money and MTN.
Security basics
Payment integration adds security obligations to any connected device. Keep these practices in place:
- Keep API secret keys on your server, never on the device or in code that customers can read.
- Verify the challenge value on every incoming webhook, and reject any request that doesn’t match.
- Restrict who can send commands to devices, and log every manual override.
- Protect the device’s control channel, so a payment message can’t be spoofed into a device action.
Treat the payment platform and the device platform as separate systems with separate access controls. A breach in one should not give control of the other. For more on protecting payment flows, read payment security basics every merchant should know.
Where IntaSend fits
IntaSend provides the mobile money collection layer for IoT and connected businesses in Kenya, Uganda, Tanzania, Rwanda and the DRC, using one integration where IntaSend is live. The API creates the M-Pesa prompt, and the webhook confirms the outcome to your platform. The device logic, the decision to credit or dispense, the device hardware, and the customer experience stay with your business.
To see which payment rails are live in each market, check the IntaSend coverage page. For the wider IoT and ISP setup, see the ISP and IoT solutions page. If you’re building an IoT product in Kenya and want to talk through the integration, speak to the IntaSend team. You can also reach us on WhatsApp at +254 711 082 947, by email at [email protected], or by phone at +254 114 114 644.
Banking services provided by licensed partners.