# M-Pesa STK Push Integration API
A production-ready Node.js/Express API for M-Pesa STK Push payments using Safaricom's API.
## Features
✅ **STK Push Payments** - Initiate payments directly from customer's phone
✅ **Callback Handling** - Secure callback processing with signature verification
✅ **Rate Limiting** - Built-in protection against abuse
✅ **Input Validation** - Phone number and amount validation
✅ **Error Handling** - Comprehensive error management
✅ **Logging** - Request logging for debugging
✅ **Security** - Signature verification, environment-based configuration
## Project Structure
```
mpesa-integration/
├── server.js # Main Express server
├── package.json # Dependencies
├── .env.example # Environment template
├── .env # Local environment (git ignored)
│
├── utils/ # Utility functions
│ ├── oauth.js # OAuth token generation
│ ├── timestamp.js # Timestamp formatting
│ ├── passwordGen.js # Password generation
│ └── validation.js # Input validation
│
├── middleware/ # Express middleware
│ ├── logger.js # Request logging
│ ├── rateLimiter.js # Rate limiting
│ └── verifyCallback.js # Callback verification
│
├── routes/ # API routes
│ ├── stkPush.js # STK Push endpoint
│ └── callbacks.js # Callback endpoint
│
└── (legacy files) # Original files (can be archived/deleted)
├── Routes.js
├── Express.js
├── OAuth.js
├── TimeStamp.js
├── PasswordGen.js
└── CallBacksRoutes.js
```
## Installation
1. **Clone/extract the project**
```bash
cd mpesa-integration
```
2. **Install dependencies**
```bash
npm install
```
3. **Configure environment**
```bash
cp .env.example .env
# Edit .env with your Safaricom credentials
```
4. **Start the server**
```bash
npm start # Production mode
npm run dev # Development mode (auto-reload)
```
The server will start on `
local …