A sophisticated Node.js application for automated Safaricom payment processing with scheduling capabilities, real-time monitoring, and web-based configuration.
- Automated Scheduling: Process payments every 4 hours (configurable) up to 6 times per day
- Manual Job Execution: Run payment jobs on-demand
- Real-time Monitoring: Live progress tracking with WebSocket updates
- Web Interface: Clean, responsive dashboard for configuration and monitoring
- Load Balancing: Distributes requests between primary and fallback Safaricom servers
- Clean Logging: Server responses with progress bars, no unnecessary clutter
- Job History: Track all processing jobs with detailed statistics
The easiest way to run this application is with Docker, which includes an isolated MySQL database:
-
Prerequisites
- Docker (20.10 or higher)
- Docker Compose (2.0 or higher)
-
Setup
# Clone the repository git clone <repository-url> cd easysmsnode # Create .env file from example cp .env.example .env # Edit .env with your Safaricom API credentials nano .env
-
Configure Environment Variables
Edit
.envand update the following required fields:SMS_API_USERNAME=your_safaricom_username SMS_API_PASSWORD=your_safaricom_password CPID=your_cpid DEFAULT_OFFER_CODE=your_offer_code CHARGE_AMOUNT=10 SESSION_SECRET=your-secure-random-secret
-
Start the Application
# Build and start all services docker-compose up -d # View logs docker-compose logs -f # Check status docker-compose ps
-
Access the Application
- Web Interface: http://localhost:3000
- MySQL Database: localhost:3307 (mapped to avoid conflicts with system MySQL)
Note: The Docker MySQL runs on port 3307 on your host machine to avoid conflicts with any existing MySQL installation on port 3306. The application container connects to MySQL internally via the Docker network on port 3306.
-
Useful Docker Commands
# Stop services docker-compose down # Rebuild after code changes docker-compose up -d --build # View application logs docker-compose logs -f app # View database logs docker-compose logs -f mysql # Execute commands in container docker-compose exec app sh docker-compose exec mysql mysql -u safaricom -p # Access MySQL from host machine mysql -h 127.0.0.1 -P 3307 -u safaricom -p # Reset everything (including database) docker-compose down -v
# Install dependencies
npm install
# Setup MySQL database
mysql -u root -p < init-db.sql
# Configure environment
cp .env.example .env
nano .env
# Change DB_HOST to 127.0.0.1 or localhost
# Run Prisma migrations
npx prisma migrate deploy
npx prisma generate
# Start application
npm startsudo ./deploy.sh
sudo nano /opt/safaricom-payment-processor/.env
sudo systemctl start safaricom-payment-processorEdit .env file with your database and Safaricom API credentials:
# Database
DB_HOST=127.0.0.1
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_NAME=nurcana_sdp
# Safaricom API
SAFARICOM_USERNAME=your_username
SAFARICOM_PASSWORD=your_password- Access web interface:
http://localhost:3000 - Configure scheduling parameters
- Start/stop scheduler or run manual jobs
- Monitor real-time progress and view job history
POST /api/scheduler/start- Start schedulerPOST /api/scheduler/stop- Stop schedulerPOST /api/jobs/manual- Run manual jobGET /api/scheduler/status- Get statusGET /api/jobs/history- Get job history
- Modular Design: Clean separation of services, controllers, and utilities
- Event-Driven: Real-time updates via WebSocket
- Scalable: Concurrent processing with load balancing
- Secure: Input validation, token management, environment-based config
- Monitored: Comprehensive logging and progress tracking
The Docker setup includes:
- MySQL 8.0: Isolated database with persistent volume storage
- Node.js App: Application container with Puppeteer/Chromium support
- Health Checks: Automatic monitoring of both services
- Automatic Database Migrations: Prisma migrations run on container startup
- Persistent Data: Database data is stored in Docker volumes
- Network Isolation: Services communicate on a private Docker network
- Timezone Configuration: Set to Africa/Nairobi
- Non-root User: Application runs as unprivileged user for security
- Log Persistence: Application logs are mounted to host filesystem
mysql_data: Database files (persistent)./uploads: User uploads (shared with host)./logs: Application logs (shared with host)
- Systemd service integration
- Log rotation
- Health checks
- Graceful shutdown
- Resource limits
- Security hardening
MIT License
Complete Ubuntu server installation:
sudo apt-get update && sudo apt-get install -y \
chromium-browser \
chromium-codecs-ffmpeg \
fonts-liberation \
libasound2t64 \
libatk-bridge2.0-0t64 \
libatk1.0-0t64 \
libatspi2.0-0t64 \
libcups2t64 \
libdbus-1-3 \
libdrm2 \
libgbm1 \
libgtk-3-0t64 \
libnspr4 \
libnss3 \
libwayland-client0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
xdg-utils
Then verify Chromium path:
which chromium-browser