| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
•
Invoicing (account)
• Discuss (mail) • Contacts (contacts) |
| Community Apps Dependencies | Show |
| Lines of code | 674 |
| Technical Name |
payment_mpesa_c2b |
| License | OPL-1 |
| Website | https://odoo.co.ke |
| Versions | 16.0 |
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Odoo Apps Dependencies |
•
Invoicing (account)
• Discuss (mail) • Contacts (contacts) |
| Community Apps Dependencies | Show |
| Lines of code | 674 |
| Technical Name |
payment_mpesa_c2b |
| License | OPL-1 |
| Website | https://odoo.co.ke |
| Versions | 16.0 |
M-Pesa • Integration
M-Pesa C2B Connector
Seamlessly integrate Safaricom M-Pesa PayBill and BuyGoods payments into Odoo accounting. Automates C2B transaction processing with intelligent payment reconciliation and partner matching.
☁️Compatibility
Verified support across different Odoo environments
📸 Screenshots
Visual guide to M-Pesa C2B Connector functionality
M-Pesa Daraja Configuration
PayBill configuration with Daraja API credentials and C2B URL registration.
C2B Callback Processing
Live C2B webhook processing showing payment creation and partner matching.
Payment Metadata Fields
Account payment form displaying M-Pesa transaction metadata and reconciliation status.
📱 C2B Processing
- 📡 /callback/c2b webhook handler
- 💰 PayBill/BuyGoods automation
✨ Smart Reconciliation
- 🪄 Reconciliation wizard interface
- 🔗 Auto-reconciliation for existing partners
🦁 Daraja API
- 🔗 C2B URL registration
- 🧪 C2B payment simulation
📊 Transaction Tracking
- 🔍 Complete M-Pesa metadata capture
- 📄 Invoice integration methods
Latest Release 18.0.1.0.0
2024-12-27- Initial release with Daraja API integration and C2B processing.
- Reconciliation wizard and automated payment posting.
- Comprehensive M-Pesa transaction tracking.
📅 Changelog
- ➕ Add Full automation workflows
- ⚡ Improve Performance & stability enhancements
📜 Licensing
License Type
OPL-1Redistribution
Not AllowedFull Policy
View Policy💬 Support & Contact
M-Pesa C2B Connector
Version: 16.0.1.0.0 Author: Metro Ict Limited Website: https://odoo.co.ke License: OPL-1
Overview
The M-Pesa C2B Connector is a comprehensive Odoo module that seamlessly integrates Safaricom M-Pesa PayBill and BuyGoods payments into your Odoo accounting system. This module automates the entire customer-to-business (C2B) payment workflow, from webhook reception to payment reconciliation, eliminating manual data entry and reducing accounting errors.
Features
Webhook Integration - Automatic C2B webhook callback handling at /callback/c2b - Real-time payment processing and recording - Support for both PayBill and BuyGoods transactions - Comprehensive payload validation and error handling - Support for both sandbox and production environments
Payment Processing - Automatic creation of payment records from M-Pesa webhooks - Intelligent partner matching using phone number hashing - Auto-creation of new partners with customer names from M-Pesa data - Automatic payment posting and journal entry creation - Transaction reference tracking and metadata storage
Daraja API Integration - Full integration with Safaricom's Daraja API - OAuth token management for secure API authentication - C2B URL registration for webhook endpoints - Transaction simulation for testing - Support for multiple business short codes
Enhanced Payment Records - Extended payment model with M-Pesa-specific fields - Complete transaction metadata storage (TransID, MSISDN, etc.) - Customer name tracking (FirstName, MiddleName, LastName) - Bill reference number and invoice tracking - Raw payload storage for audit and debugging - Transaction timestamp preservation
Reconciliation Tools - Dedicated reconciliation wizard for unmatched payments - Manual partner assignment capabilities - Bulk payment processing and reconciliation - Auto-reconciliation status tracking - Phone number hash updates for future matching
Configuration Management - Easy-to-use configuration interface in Accounting settings - Environment switching (Sandbox/Production) - Multiple business short code support - Journal assignment for payment recording - Webhook URL configuration and testing
How It Works
1. Configuration Setup The module provides a configuration model (mpesa.paybill.config) where you set up:
- Environment (Sandbox/Production)
- Business Short Code (PayBill number)
- Till Number (for BuyGoods)
- Daraja API credentials (Consumer Key and Secret)
- Journal for recording payments
- Callback URL for webhook notifications
2. Daraja API Registration Once configured, the module can register your webhook URLs with Safaricom:
- Obtains OAuth token using consumer credentials
- Registers Confirmation and Validation URLs
- Stores registration status for monitoring
- Enables webhook reception from M-Pesa
3. Payment Processing Flow When a customer makes an M-Pesa payment to your PayBill/Till:
- Safaricom sends a webhook to your configured callback URL
- The module validates the webhook payload and required fields
- Extracts transaction details (amount, phone number, reference, etc.)
- Normalizes and hashes the customer's phone number
- Searches for existing partner using phone number hash
- Creates new partner with customer names if not found
- Creates and posts payment record in Odoo
- Returns success/error response to Safaricom
4. Partner Matching The module uses intelligent partner matching:
- Normalizes Kenyan phone numbers to standard format (+254...)
- Creates secure hashes of phone numbers for privacy
- Matches payments to existing partners using phone hashes
- Falls back to legacy hash formats for backward compatibility
- Auto-creates partners with full names from M-Pesa data
5. Reconciliation Workflow For unmatched or disputed payments:
- Use the reconciliation wizard to manually assign partners
- Bulk process multiple unreconciled payments
- Update phone hashes for future automatic matching
- Track reconciliation status and history
Installation
Prerequisites
- Odoo 18.0 or later
- payment_c2b_common_ke module (dependency)
- account module (standard Odoo module)
- l10n_ke module (Kenyan localization)
- Active Safaricom M-Pesa PayBill or BuyGoods account
- Daraja API credentials from Safaricom
- Public-facing server for webhook callbacks
Installation Steps
Download and Install
Place the module in your Odoo addons directory:
# Copy module to addons directory cp -r payment_mpesa_c2b /path/to/odoo/addons/Update Module List
In Odoo, go to Apps → Update Apps List
Install Module
Search for "M-Pesa C2B Connector" and click Install
Install Dependencies
Ensure the following modules are installed: - payment_c2b_common_ke - account (usually pre-installed) - l10n_ke (Kenyan localization)
Configuration
Initial Setup
Navigate to Configuration
Go to: Accounting → Configuration → M-Pesa → Paybill
Create New Configuration
Click "Create" and fill in the required fields:
- Name: Descriptive name for your configuration
- Environment: Choose Sandbox for testing, Production for live
- Journal: Select the bank journal for recording payments
- Business Short Code: Your PayBill number from Safaricom
- Till Number: Your Till number (for BuyGoods, optional)
- Consumer Key: Your Daraja API Consumer Key
- Consumer Secret: Your Daraja API Consumer Secret
- Callback URL: Your webhook endpoint (e.g., https://yourdomain.com/callback/c2b)
Register C2B URLs
Click "Register C2B URLs" to register your webhook with Safaricom
Daraja API Setup
Get API Credentials
- Visit https://developer.safaricom.co.ke
- Create an account and new app
- Note down Consumer Key and Consumer Secret
Configure Webhook URL
Your callback URL should be publicly accessible and point to: https://yourdomain.com/callback/c2b
Test Configuration
- Use "Test Webhook" to verify your endpoint
- Use "Simulate C2B" to test with Safaricom's sandbox
Usage
Daily Operations
Viewing Payments - Go to Accounting → Customers → Payments - M-Pesa payments will have additional fields populated - Filter by "M-Pesa" or use advanced filters
Partner Management - Partners are automatically created from M-Pesa customer data - Phone numbers are normalized and hashed for matching - Customer names are extracted from FirstName, MiddleName, LastName
Reconciliation - Access reconciliation wizard from payment records - Go to Accounting → M-Pesa → Reconciliation (if menu exists) - Assign partners to unreconciled payments - Process multiple payments in bulk
Monitoring - Check C2B registration status in configuration - Monitor payment creation in real-time - Review raw payloads for debugging
Advanced Features
Multiple Business Codes - Configure multiple PayBill/Till numbers - Each configuration can have different journals - Automatic routing based on business short code
Reconciliation Wizard - Bulk assignment of partners to payments - Phone hash updates for future matching - Status tracking and reporting
Testing Tools - Webhook testing with sample payloads - C2B transaction simulation - Registration status monitoring
Troubleshooting
Common Issues
- Webhook Not Receiving Data - Verify callback URL is publicly accessible - Check SSL certificate validity - Ensure no firewall blocking Safaricom IPs - Verify business short code matches PayBill number
- Daraja API Errors - Verify Consumer Key and Secret are correct - Check environment setting (sandbox vs production) - Ensure API credentials are active - Review registration status messages
- Payment Creation Failures - Check journal configuration and permissions - Verify currency settings match KES - Review Odoo logs for detailed error messages - Ensure required fields are present in webhook
- Partner Matching Issues - Verify phone number normalization - Check hash generation for phone numbers - Review partner creation logic - Use reconciliation wizard for manual assignment
Webhook Payload Validation The module validates these required fields: - TransID (Transaction ID) - TransAmount (Amount) - MSISDN (Phone number) - TransTime (Transaction timestamp) - BusinessShortCode (PayBill/Till number)
Log Monitoring Enable debug logging for detailed webhook processing:
_logger = logging.getLogger(__name__) # Check logs in Odoo for C2B processing details
API Reference
Webhook Endpoint - URL: /callback/c2b - Method: POST - Content-Type: application/json - Authentication: None (public endpoint)
Expected Payload Format:
{ "TransactionType": "PayBill", "TransID": "NLJ3H6KZ8A", "TransTime": "20250515123045", "TransAmount": "2500.00", "BusinessShortCode": "174379", "BillRefNumber": "TEST1234", "MSISDN": "254716680977", "FirstName": "Jane", "MiddleName": "M.", "LastName": "Doe" }
Response Codes: - {"ResultCode": "0", "ResultDesc": "Accepted"} - Success - {"ResultCode": "C2B00011", "ResultDesc": "Invalid JSON"} - JSON parsing error - {"ResultCode": "C2B00012", "ResultDesc": "Missing required fields"} - Validation error
Support
For technical support and questions:
- Website: https://odoo.co.ke
- Email: support@odoo.co.ke
- Phone: +254739444447
- Author: Metro Ict Limited
- Module Version: 16.0.1.0.0
Documentation - Safaricom Daraja API: https://developer.safaricom.co.ke - Odoo Payment Documentation: https://www.odoo.com/documentation/
License
This module is licensed under OPL-1 (Odoo Proprietary License v1.0).
Changelog
Version 16.0.1.0.0 - Initial release for Odoo 18.0 - Full C2B webhook integration - Daraja API integration - Payment processing and posting - Partner matching and creation - Reconciliation wizard - Configuration management interface - Testing and simulation tools - Comprehensive M-Pesa metadata tracking
Odoo Proprietary License v1.0 This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, typically via Odoo Apps, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Odoo Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Please log in to comment on this module