A dynamic web platform where users can register, verify their phone, pay an activation fee via M-Pesa, play games to earn points, and withdraw earnings. Built with PHP, MySQL, Bootstrap, and JavaScript, featuring a modern, responsive, and professional front-end design.
- User Registration: Sign up with full name, username, phone, email (optional), password, and unique referral code.
- Phone Verification: Receive and verify a 6-digit SMS code (Africa’s Talking API).
- M-Pesa Payment: Pay activation fee via M-Pesa STK Push (Daraja API).
- Account Activation: Activate account post-payment.
- Login System: Log in with username or phone.
- Dashboard: Displays logged-in user’s points, wallet balance, referrals, and recent activities.
- Password Management: Update password with strong validation (8+ characters, uppercase, number, special character).
- Referrals: Share referral link, track referred users, and view referral count.
- Achievements: View user achievements and leaderboard rankings (top 10 by points).
- Modern UI: Bootstrap 5, Font Awesome, Poppins font, gradient buttons, animations, and mobile-friendly sidebar/bottom nav.
- Backend: PHP, MySQL
- Frontend: HTML, CSS (Bootstrap 5), JavaScript
- APIs:
- Africa’s Talking SMS (sandbox for testing)
- M-Pesa Daraja (STK Push, sandbox)
- Database: MySQL (users, wallet, transactions, verification_codes; optional: points)
looma/
├── api/
│ ├── register.php # User registration
│ ├── login.php # User login
│ ├── verify_phone.php # Phone verification
│ ├── initiate_payment.php # M-Pesa STK Push
│ ├── mpesa_callback.php # M-Pesa callback handler
│ ├── check_activation.php # Check account activation
├── assets/
│ ├── css/
│ │ └── style.css # Shared styles
│ ├── js/
│ │ └── main.js # Frontend logic
├── includes/
│ ├── db.php # Database connection
│ ├── mpesa.php # M-Pesa API helper
├── index.php # User dashboard (points, balance, referrals, activities)
├── register.php # Registration form
├── login.php # Login form
├── verify.php # Phone verification form
├── payment.php # Payment initiation
├── settings.php # Password update
├── referrals.php # Referral link and referred users
├── achievements.php # Achievements and leaderboard
├── wallet.php # Earnings dashboard (placeholder)
├── games.php # Games page (placeholder)
├── questions.php # Quizes page (placeholder)
├── README.md
- PHP 7.4+
- MySQL 5.7+
- Web server (Apache, Nginx, or
php -S) - Africa’s Talking sandbox credentials
- M-Pesa Daraja sandbox credentials
-
Clone the Repository:
git clone https://github.com/galaxie-dev/affiliate-mkt.git cd looma -
Configure Database:
- Create a MySQL database (
looma). - Import the schema:
CREATE TABLE users ( user_id INT AUTO_INCREMENT PRIMARY KEY, full_name VARCHAR(100) NOT NULL, username VARCHAR(50) UNIQUE NOT NULL, phone VARCHAR(15) UNIQUE NOT NULL, email VARCHAR(100), password VARCHAR(255) NOT NULL, referral_code VARCHAR(8) UNIQUE, referred_by VARCHAR(8), is_verified BOOLEAN DEFAULT FALSE, is_activated BOOLEAN DEFAULT FALSE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (referred_by) REFERENCES users(referral_code) ); CREATE TABLE wallet ( wallet_id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, balance DECIMAL(10,2) DEFAULT 0.00, FOREIGN KEY (user_id) REFERENCES users(user_id) ); CREATE TABLE transactions ( transaction_id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, amount DECIMAL(10,2) NOT NULL, description VARCHAR(255), type ENUM('deposit', 'withdrawal') NOT NULL, status ENUM('pending', 'completed', 'failed') DEFAULT 'pending', mpesa_code VARCHAR(50), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(user_id) ); CREATE TABLE verification_codes ( code_id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, code VARCHAR(6) NOT NULL, status ENUM('pending', 'verified', 'expired') DEFAULT 'pending', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, expires_at TIMESTAMP NOT NULL, FOREIGN KEY (user_id) REFERENCES users(user_id) ); -- Optional: For points tracking CREATE TABLE points ( point_id INT AUTO_INCREMENT PRIMARY KEY, user_id INT, points INT DEFAULT 0, FOREIGN KEY (user_id) REFERENCES users(user_id) );
- Update
includes/db.phpwith your credentials:$host = 'localhost'; $db = 'looma'; $user = 'your_db_user'; $pass = 'your_db_password';
- Create a MySQL database (
-
Configure APIs:
- Africa’s Talking:
- Get sandbox credentials.
- Update
api/register.phpwith API key and username.
- M-Pesa Daraja:
- Get sandbox credentials (consumer key, secret, shortcode, passkey).
- Update
includes/mpesa.phpwith credentials and callback URL.
- Africa’s Talking:
-
Run the Server:
php -S localhost:8000
-
Access the Site:
- Open
http://localhost:8000/index.php. - Register, verify phone, pay, log in, or access dashboard.
- Open
- Dashboard (
index.php): View points (defaults to 0 ifpointstable missing), wallet balance, referral count, and recent transactions (empty iftransactionstable missing). - Register (
register.php): Enter details → receive SMS code. - Verify (
verify.php): Enter code → proceed to payment. - Pay (
payment.php): Initiate M-Pesa STK Push → activate account. - Login (
login.php): Access dashboard. - Settings (
settings.php): Update password with strong validation. - Referrals (
referrals.php): Copy referral link, view referred users’ names, usernames, and join dates. - Achievements (
achievements.php): View earned achievements and top 10 leaderboard (requirespointstable). - Wallet (
wallet.php): Placeholder for earnings overview. - Games (
games.php): Placeholder for gameplay. - Quizes (
questions.php): Placeholder for quizzes.
- APIs:
curl -X POST http://localhost:8000/api/register.php \ -H "Content-Type: application/json" \ -d '{"full_name":"John Doe","username":"johndoe","phone":"+254712345678","email":"john@example.com","password":"secure123"}'
- Front-End:
- Navigate to
http://localhost:8000/register.php. - Use DevTools (Network tab) to verify JSON responses.
- Test dashboard (
index.php) after login to confirm user details, stats, and no errors.
- Navigate to
- Sandbox:
- Test SMS with Africa’s Talking sandbox.
- Simulate M-Pesa payments with Daraja sandbox.
- Missing Tables:
points: Defaults to 0 points if missing. Create table for tracking.transactions: Shows “No recent activity” if missing. Create for activity logs.
- Non-JSON responses may occur if:
includes/db.phpcredentials are incorrect.- API files are misplaced.
- PHP isn’t executing (check server logs).
games.phpandquestions.phpare placeholders (no functionality).
- Implement
games.phpfor gameplay mechanics. - Build
questions.phpfor quiz functionality. - Enhance
wallet.phpwith balance, withdrawal UI, and transaction history. - Add
withdraw.phpfor M-Pesa withdrawals. - Implement
logout.phpto clear sessions. - Add CSRF tokens for form security.
- Style
verify.phpandpayment.phpto matchregister.phpandlogin.php. - Add achievements table for
achievements.phpfull functionality.
- Fork the repo.
- Create a branch (
git checkout -b feature/your-feature). - Commit changes (
git commit -m "Add your feature"). - Push (
git push origin feature/your-feature). - Open a pull request.
MIT License. See LICENSE for details.
Built with 💻 by Collins & Evans.