A practical guide to integrating mobile money payment gateways into PHP/Laravel applications, with examples from the Rwandan fintech ecosystem.
Mobile Money in Rwanda
Mobile money has transformed how people transact in Rwanda. As developers, integrating these payment methods is essential for any consumer-facing application.
Integration Approaches
There are two common patterns:
- Direct API Integration - Connecting to the telco's API directly (MTN MoMo, Airtel Money)
- Payment Aggregators - Using services like Flutterwave or FDI that abstract multiple providers
Implementation Example
Here's a simplified flow for a mobile money payment in Laravel:
// Initiate payment request\n$response = Http::withHeaders([\n 'Authorization' => 'Bearer ' . $apiToken,\n])->post('https://api.provider.com/v1/payments', [\n 'phone' => $request->phone,\n 'amount' => $order->total,\n 'reference' => $order->reference,\n 'callback_url' => route('payment.callback'),\n]);Handling Callbacks
Mobile money payments are asynchronous. The customer approves the transaction on their phone, and the provider sends a callback to your server with the result. Always verify the callback authenticity using signatures or IP whitelisting.
Testing
Most providers offer sandbox environments. Use them extensively before going live. Always handle edge cases like timeouts, insufficient funds, and duplicate transactions.