# M-Pesa Authenticator Service
A secure, production-ready service for processing M-Pesa B2C (Business to Customer) payments with OAuth2 authentication, multi-client support, and comprehensive audit logging.
## 🌟 Features
- 🔐 **OAuth2 Authentication**: Secure API access with client credentials flow
- 👥 **Multi-Client Support**: Multiple API clients with individual configurations
- 💳 **Multi-Configuration**: Support for multiple M-Pesa shortcodes (sandbox & production)
- 🔄 **Token Management**: Automatic OAuth token caching with Redis
- 🐰 **Queue Processing**: RabbitMQ for rate-limited transaction processing (2 TPS)
- 📊 **Comprehensive Audit Logs**: Track every API call with client, IP, and status
- 📡 **Webhook Callbacks**: Notify clients when transactions complete
- 🔒 **Encrypted Storage**: All sensitive credentials encrypted at rest
- 🌐 **ngrok Integration**: Easy callback URL management for development
- 📱 **React Frontend**: User-friendly admin dashboard
---
## 📋 Table of Contents
- Architecture
- Quick Start
- Configuration
- M-Pesa Setup
- API Usage
- Utilities
- Troubleshooting
- Production Deployment
---
## 🏗️ Architecture
```
┌─────────────┐
│ Clients │ (OAuth2 Authentication)
└──────┬──────┘
│
▼
┌─────────────────────────────────────────────────────┐
│ FastAPI Application │
│ ┌─────────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ OAuth2 │ │ Endpoints │ │ Audit Log │ │
│ │ Middleware│ │ (B2C, etc) │ │ Middleware│ │
│ └─────────────┘ └──────────────┘ └────────────┘ │
└──────┬──────────────────┬──────────────────────────┘
│ │
▼ ▼
┌─────────────┐ ┌─────────────┐
│ PostgreSQL │ │ RabbitMQ │
│ (Database) │ │ (Queue) │
└─────────────┘ └──────┬──────┘
│
▼
┌─────────────┐
│ Worker │ (2 TPS)
└──────┬──────┘
│
▼
┌─────────────┐
│ M-Pesa API │
└──────┬──────┘
│
┌──────▼──────┐
│ Callback │
│ (via ngrok)│
└──────┬──────┘
│
┌──────▼────── …