# M-Pesa Gateway API
A robust Node.js REST API for integrating M-Pesa mobile money payments into applications. This gateway provides a secure and reliable interface for initiating STK Push payments, handling callbacks, and managing transactions.
## Features
- **STK Push Integration**: Initiate M-Pesa payments via STK Push
- **OAuth Authentication**: Secure token-based authentication with M-Pesa API
- **Callback Handling**: Process payment confirmations and updates
- **Transaction Management**: Track and store payment transactions
- **API Documentation**: Interactive Swagger/OpenAPI documentation
- **Comprehensive Logging**: Detailed logging for debugging and monitoring
- **Error Handling**: Robust error handling with standardized responses
- **CORS Support**: Cross-origin resource sharing enabled
- **Testing Suite**: Jest-based test coverage for critical components
- **Environment Configuration**: Flexible configuration management
- **Graceful Shutdown**: Proper server shutdown handling
## Project Structure
```
mpesa_gateway/
├── app.js # Express application setup and middleware
├── server.js # Server entry point and configuration
├── package.json # Dependencies and scripts
├── config/
│ ├── env.js # Environment configuration and validation
│ └── swagger.js # Swagger/OpenAPI documentation configuration
├── controllers/
│ └── health.controller.js # Health check endpoint
├── middlewares/
│ └── errorHandler.js # Global error handling middleware
├── models/
│ └── transaction.model.js # Transaction data model (MongoDB)
├── routes/
│ ├── index.js # Main route aggregator
│ └── payment.routes.js # Payment-related endpoints
├── services/
│ ├── mpesaAuth.service.js # M-Pesa OAuth authentication
│ └── stkPush.service.js # STK Push payment processing
├── utils/
│ ├── logger.js # Custom logging utility
│ ├── response.js # Standardized API response helper
│ └── timestamp. …