# Coffee Shop Backend with M-Pesa Integration
A robust Node.js backend application for processing coffee shop payments using M-Pesa STK Push. This application provides a secure and efficient way to handle mobile payments through Safaricom's M-Pesa service.
## 🚀 Features
- **M-Pesa STK Push Integration**
- Secure payment processing
- Real-time payment status updates
- Automated payment confirmation handling
- **Database Management**
- MySQL database for transaction storage
- Efficient payment tracking and history
- Transaction status monitoring
- **Security Features**
- Helmet.js for security headers
- CORS protection
- Rate limiting (100 requests per 15 minutes per IP)
- Input validation and sanitization
- Secure logging with Winston
- **Error Handling**
- Comprehensive error logging
- User-friendly error messages
- Transaction rollback support
## 📋 Prerequisites
- Node.js (v14 or higher)
- MySQL (v5.7 or higher)
- M-Pesa API credentials (Sandbox or Production)
- ngrok (for local development and testing)
## 🛠️ Installation
1. **Clone the repository**
```bash
git clone
cd coffee-shop-backend
```
2. **Install dependencies**
```bash
npm install
```
3. **Set up environment variables**
Create a `.env` file in the root directory with the following variables:
```env
PORT=3000
MYSQL_HOST=localhost
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=cafe
MPESA_CONSUMER_KEY=your_consumer_key
MPESA_CONSUMER_SECRET=your_consumer_secret
MPESA_SHORTCODE=your_shortcode
MPESA_PASSKEY=your_passkey
```
4. **Set up the database**
```bash
mysql -u root -p < database.sql
```
5. **Start ngrok for local development**
```bash
ngrok http 3000
```
Update the `CallBackURL` in `routes/paymentRoutes.js` with your ngrok URL.
## 🔧 Configuration
### M-Pesa API Configuration
- Update the `.env` file with your M-Pesa API credentials
- For sandbox testing, use the provided sandbox credentials
- For production, replace with your production credentials
### Database Configuratio …