A comprehensive WiFi billing system with M-Pesa integration, loan management, and MikroTik hotspot control.
Dashboard view showing user connections and payments.
Billing interface with M-Pesa integration and loan options.
- π Secure Authentication - JWT-based user authentication
- π³ M-Pesa Integration - Mobile money payments for WiFi access
- π° Loan System - Credit-based WiFi access for users
- π MikroTik Integration - Automated hotspot user management
- π Admin Dashboard - Real-time monitoring and management
- π± Responsive UI - Modern React/Next.js frontend
- π Real-time Updates - WebSocket notifications
-
Fork this repository to your GitHub account
-
Connect to Render:
- Go to Render Dashboard
- Click "New" β "Blueprint"
- Connect your GitHub repository
- Render will automatically detect
render.yaml
-
Configure Environment Secrets: In your Render dashboard, go to your service settings and add these environment variables:
Variable Description Example JWT_SECRETSecure random string for JWT your-secure-random-jwt-secretADMIN_USERNAMEAdmin login username adminADMIN_PASSWORDAdmin login password secure_password_123ADMIN_EMAILAdmin email admin@yourdomain.comMPESA_CONSUMER_KEYM-Pesa API key From Safaricom Portal MPESA_CONSUMER_SECRETM-Pesa API secret From Safaricom Portal MPESA_SHORTCODEYour M-Pesa shortcode 123456MPESA_PASSKEYM-Pesa passkey From Safaricom Portal MIKROTIK_HOSTMikroTik router IP 192.168.88.1MIKROTIK_USERMikroTik username adminMIKROTIK_PASSWORDMikroTik password your_password -
Deploy:
- Render will automatically create PostgreSQL database
- Deploy the web service
- Your app will be live at
https://your-app-name.onrender.com
- Node.js 18+
- PostgreSQL (or use Docker)
- Git
# Clone repository
git clone <your-repo-url>
cd wifi_billing
# Install dependencies
npm install
# Copy environment file
cp .env.example .env
# Configure your environment variables in .env
# Generate Prisma client
npx prisma generate
# Run database migrations
npx prisma db push
# Start development server
npm run dev
# Start frontend (in another terminal)
cd frontend && npm run devwifi_billing/
βββ config/ # Database and service configurations
βββ routes/ # API endpoints
βββ services/ # Business logic
βββ middleware/ # Authentication and security
βββ prisma/ # Database schema and migrations
βββ frontend/ # Next.js React application
βββ src/ # Shared utilities (logger, etc.)
βββ logs/ # Application logs
POST /api/auth/register- User registrationPOST /api/auth/login- User login
POST /pay- Initiate M-Pesa paymentPOST /api/mpesa/callback- M-Pesa callback handler
GET /loans/eligibility- Check loan eligibilityPOST /loans/request- Request a loanPOST /loans/repay/initiate/:loanId- Initiate loan repayment
GET /api/admin/summary- Dashboard summaryGET /admin/payments- Payment history
See .env.example for all required environment variables.
- Render (Recommended): One-click cloud deployment
- Docker: Containerized deployment
- PM2: Process management for VPS
- Manual: Direct Node.js deployment
- Node.js 18+
- PostgreSQL 15+
- PM2 (for process management)
- Docker & Docker Compose (optional)
- Linux/Windows server with at least 2GB RAM
-
Clone and setup:
git clone <repository> cd wifi_billing cp .env.example .env # Configure your environment variables
-
Run deployment script:
./deploy.sh
-
Start with PM2:
npm run pm2:start
Create a .env file with the following variables:
# Server
PORT=5000
NODE_ENV=production
# Database (PostgreSQL)
DATABASE_URL=postgresql://user:password@localhost:5432/wifi_billing
# Security
JWT_SECRET=your-secure-random-jwt-secret-here
# Admin Credentials
ADMIN_USERNAME=your_admin_username
ADMIN_PASSWORD=your_secure_admin_password
ADMIN_EMAIL=admin@yourdomain.com
# M-Pesa Integration
MPESA_ENABLED=true
MPESA_CONSUMER_KEY=your_mpesa_consumer_key
MPESA_CONSUMER_SECRET=your_mpesa_consumer_secret
MPESA_SHORTCODE=your_mpesa_shortcode
MPESA_PASSKEY=your_mpesa_passkey
MPESA_CALLBACK_URL=https://yourdomain.com/api/mpesa/callback
# MikroTik Integration
MIKROTIK_ENABLED=true
MIKROTIK_HOST=192.168.88.1
MIKROTIK_USER=your_mikrotik_user
MIKROTIK_PASSWORD=your_mikrotik_password
MIKROTIK_PORT=8728
# Loan Configuration
LOAN_WIFI_DURATION_HOURS=1Render provides managed PostgreSQL and automatic deployments from Git.
-
Connect Repository:
- Go to Render Dashboard
- Click "New" β "Blueprint"
- Connect your GitHub repository
- Select the
render.yamlfile
-
Configure Secrets: In Render Dashboard β Settings β Environment:
JWT_SECRET: your-secure-random-jwt-secret ADMIN_USERNAME: your_admin_username ADMIN_PASSWORD: your_secure_admin_password ADMIN_EMAIL: admin@yourdomain.com MPESA_CONSUMER_KEY: your_mpesa_consumer_key MPESA_CONSUMER_SECRET: your_mpesa_consumer_secret MPESA_SHORTCODE: your_mpesa_shortcode MPESA_PASSKEY: your_mpesa_passkey MPESA_CALLBACK_URL: https://your-render-app.onrender.com/api/mpesa/callback MIKROTIK_ENABLED: true MIKROTIK_HOST: your_mikrotik_ip MIKROTIK_USER: your_mikrotik_username MIKROTIK_PASSWORD: your_mikrotik_password MIKROTIK_PORT: 8728 -
Deploy:
- Render will automatically create PostgreSQL database
- Deploy the web service
- Update M-Pesa callback URL with your Render domain
- β Free tier available
- β Managed PostgreSQL
- β Automatic SSL certificates
- β Global CDN
- β Automatic deployments on git push
# Install PM2 globally
npm install -g pm2
# Start application
npm run pm2:start
# Check status
npm run pm2:monit
# View logs
npm run pm2:logs# Build and start
docker-compose up -d
# View logs
docker-compose logs -f app
# Stop
docker-compose down# Start
npm start
# Or with PM2
pm2 start index.js --name wifi-billing-
Create PostgreSQL database:
CREATE DATABASE wifi_billing; CREATE USER wifi_user WITH PASSWORD 'secure_password'; GRANT ALL PRIVILEGES ON DATABASE wifi_billing TO wifi_user;
-
Run migrations:
npx prisma db push
- Change default JWT secret
- Use strong admin passwords
- Configure firewall (allow only ports 80, 443, 5000)
- Enable SSL/TLS with Let's Encrypt
- Set up log rotation
- Configure backup strategy
- Monitor system resources
- Set up fail2ban for SSH protection
# PM2 monitoring
npm run pm2:monit
# Application health check
curl http://localhost:5000/welcome
# Database connection
npx prisma db execute --file check-db.sql# Database backup
pg_dump wifi_billing > backup_$(date +%Y%m%d_%H%M%S).sql
# Application logs
tar -czf logs_$(date +%Y%m%d).tar.gz logs/-
Database connection fails:
- Check DATABASE_URL format
- Ensure PostgreSQL is running
- Verify user permissions
-
M-Pesa callbacks not working:
- Verify callback URL is accessible
- Check M-Pesa credentials
- Review firewall settings
-
MikroTik connection issues:
- Verify IP address and credentials
- Check network connectivity
- Ensure API is enabled on MikroTik
- Application logs:
logs/ - PM2 logs:
~/.pm2/logs/ - System logs:
/var/log/
- Set Node.js memory limit:
node --max-old-space-size=1024 index.js - Configure PostgreSQL connection pool
- Enable gzip compression
- Set up Redis for session storage (future enhancement)
For issues, check:
- Application logs
- PM2 status:
pm2 status - Database connectivity
- Network configuration
- JWT authentication with expiration
- Rate limiting on sensitive endpoints
- Input validation and sanitization
- SQL injection prevention
- XSS protection
- Helmet.js security headers
- CORS configuration
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
ISC License - see LICENSE file for details.
For support, strictly create an issue in the GitHub repository. Am done up to the point of testing with real Mikrotik RB750UPr, Currently am working on DDDOS management on the system. Contact me only for paid consultations regarding Mpesa-Based_Wi-Fi-Hotspot_Billing_System repository.