# đź’ł M-Pesa Flask Integration
A robust, production-ready Flask application for integrating M-Pesa STK Push payments with real-time transaction status tracking.
## 🌟 Features
- **STK Push Integration** - Seamless M-Pesa payment initiation
- **Real-time Status Tracking** - Live transaction status updates
- **Smart Phone Number Validation** - Handles multiple Kenyan phone number formats
- **Token Caching** - Efficient API token management with automatic refresh
- **Retry Logic** - Robust error handling with automatic retries
- **Modern UI** - Responsive design with real-time feedback
- **Test Mode** - Built-in testing capabilities for development
- **Comprehensive Logging** - Detailed logging for debugging and monitoring
- **Production Ready** - Built with security and scalability in mind
## 🚀 Quick Start
### Prerequisites
- Python 3.8 or higher
- M-Pesa Developer Account (Register here)
- ngrok (for local testing) - Download here
### Installation
1. **Clone the repository**
```bash
git clone
github.com
cd mpesa-flask-integration
```
2. **Create virtual environment**
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Set up environment variables**
```bash
cp .env.example .env
# Edit .env with your M-Pesa credentials
```
5. **Run the application**
```bash
python app.py
```
6. **Access the application**
- Open
localhost in your browser
- Use the test mode for immediate testing
## ⚙️ Configuration
### Environment Variables
Create a `.env` file in the project root:
```env
# M-Pesa API Credentials
CONSUMER_KEY=your_consumer_key_here
CONSUMER_SECRET=your_consumer_secret_here
BUSINESS_SHORT_CODE=your_business_shortcode
PASSKEY=your_passkey_here
CALLBACK_URL=
yourdomain.com
# Application Settings
FLASK_ENV=development
FLASK_DEBUG=True
```
### M-Pesa Credentials Setup
1. …