# ⚡ MOLAK v2.0 - Quick Configuration Guide

## 🚀 5-Minute Setup

### Step 1: Copy Environment File (5 seconds)
```bash
cp config/.env.example config/.env
```

---

## ✏️ What to Change - Quick Reference

### 1️⃣ Database (`config/database.php`)

**Lines to change:**
```php
Line ~45:  'host' => 'localhost',           // Your database host
Line ~61:  'database' => 'molak_v2',        // Your database name
Line ~75:  'username' => 'root',            // Your DB username (NOT 'root' in production!)
Line ~89:  'password' => '',                // Your DB password (MUST set in production!)
```

**Example:**
```php
'host' => 'localhost',
'database' => 'molak_production',
'username' => 'molak_user',
'password' => 'MyStr0ng!Password',
```

---

### 2️⃣ Application (`config/app.php`)

**Lines to change:**
```php
Line ~24:  'url' => 'http://localhost',                    // Your domain URL
Line ~44:  'env' => 'development',                         // 'production' when live
Line ~57:  'debug' => true,                                // false in production
Line ~256: 'email' => 'support@molak.ae',                  // Your email
Line ~257: 'phone' => '+971-4-123-4567',                   // Your phone
Line ~278: 'name' => 'MOLAK',                              // Your company
```

**Example:**
```php
'url' => 'https://molak.ae',
'env' => 'production',
'debug' => false,
'email' => 'support@mycompany.com',
'phone' => '+971-50-123-4567',
```

**🔴 DON'T CHANGE:**
```php
Line ~84:  'maintenance_fee_rate' => 30.0,      // ❌ Keep 30%
Line ~85:  'online_payment_fee_rate' => 3.1,    // ❌ Keep 3.1%
```

---

### 3️⃣ Email (`config/mail.php`)

**For Gmail (Most Common):**
```php
Line ~48:  'host' => 'smtp.gmail.com',          // Keep for Gmail
Line ~63:  'port' => 587,                       // Keep for Gmail
Line ~80:  'username' => 'your-email@gmail.com',     // ✏️ Your Gmail
Line ~95:  'password' => 'your-app-password',        // ✏️ 16-char app password
Line ~116: 'address' => 'noreply@molak.ae',          // ✏️ Your sending email
```

**Gmail App Password Setup:**
1. Go to: https://myaccount.google.com/apppasswords
2. Generate App Password (16 characters)
3. Copy it to config

**Example:**
```php
'username' => 'myemail@gmail.com',
'password' => 'abcd efgh ijkl mnop',  // 16-char from Google
'address' => 'noreply@mycompany.com',
```

---

### 4️⃣ Stripe (`config/stripe.php`)

**Lines to change:**
```php
Line ~26:  'mode' => 'test',                    // 'live' in production
Line ~42:  'public_key' => 'pk_test_...',       // ✏️ From Stripe dashboard
Line ~55:  'secret_key' => 'sk_test_...',       // ✏️ From Stripe dashboard
Line ~68:  'webhook_secret' => 'whsec_...',     // ✏️ From Stripe webhooks
```

**Get Keys:**
- Test: https://dashboard.stripe.com/test/apikeys
- Live: https://dashboard.stripe.com/apikeys
- Webhooks: https://dashboard.stripe.com/webhooks

**Example:**
```php
'mode' => 'live',
'public_key' => 'pk_live_51ABCdef...',
'secret_key' => 'sk_live_51ABCdef...',
'webhook_secret' => 'whsec_123abc...',
```

**🔴 DON'T CHANGE:**
```php
Line ~102: 'platform_fee_rate' => 3.1,    // ❌ Keep 3.1%
```

---

### 5️⃣ Twilio (`config/twilio.php`) - Optional

**If using SMS:**
```php
Line ~24:  'enabled' => false,                  // ✏️ true to enable
Line ~38:  'account_sid' => 'ACxxxx...',        // ✏️ From Twilio
Line ~50:  'auth_token' => 'your_token',        // ✏️ From Twilio
Line ~64:  'from_number' => '+15551234567',     // ✏️ Your Twilio number
```

**Get Credentials:**
- Dashboard: https://console.twilio.com/

**Example:**
```php
'enabled' => true,
'account_sid' => 'AC123abc...',
'auth_token' => 'abc123...',
'from_number' => '+971501234567',
```

---

## 🔒 Security Checklist

Before going live:

- [ ] Set `APP_ENV` to `'production'`
- [ ] Set `APP_DEBUG` to `false`
- [ ] Use strong database password
- [ ] Change database username from `'root'`
- [ ] Use HTTPS (`https://`)
- [ ] Use Stripe live keys (not test)
- [ ] Test all configurations

---

## 🧪 Test Your Configuration

```bash
# Start PHP server
php -S localhost:8000

# Open in browser
http://localhost:8000/test_config.php
```

This will show you:
- ✅ What's configured correctly
- ❌ What needs to be changed
- ⚠️ Security warnings

---

## 📋 Alternative: Use .env File

Instead of editing config files, you can edit `.env`:

```bash
# 1. Copy example
cp config/.env.example config/.env

# 2. Edit .env file
nano config/.env  # or use any text editor
```

**Example `.env`:**
```env
# Database
DB_HOST=localhost
DB_DATABASE=molak_production
DB_USERNAME=molak_user
DB_PASSWORD=MyStr0ng!Password

# App
APP_URL=https://molak.ae
APP_ENV=production
APP_DEBUG=false

# Email
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=abcd efgh ijkl mnop

# Stripe
STRIPE_MODE=live
STRIPE_PUBLIC_KEY=pk_live_...
STRIPE_SECRET_KEY=sk_live_...
```

---

## ⚠️ CRITICAL REMINDERS

### ❌ NEVER Commit These Files to Git:
```
config/database.php
config/app.php
config/mail.php
config/stripe.php
config/twilio.php
.env
```

### ✅ OK to Commit:
```
config/.env.example
.gitignore
```

The `.gitignore` file is already configured to protect your sensitive data!

---

## 🔢 Fee Rates (DO NOT CHANGE)

### Maintenance Fee = **30%** (from Provider)
```
Work Order: 1,000 AED
Platform Fee: 300 AED → MOLAK
Provider Gets: 700 AED
```

### Online Payment Fee = **3.1%** (from Owner - Optional)
```
If Enabled:
  Tenant Pays: 5,000 AED
  Platform Fee: 155 AED → MOLAK
  Owner Gets: 4,845 AED

If Disabled:
  Tenant Pays: 5,000 AED
  Platform Fee: 0 AED
  Owner Gets: 5,000 AED
```

---

## 🆘 Common Issues

### Database Connection Failed?
✅ Check: host, database name, username, password

### Emails Not Sending?
✅ Use Gmail App Password (not regular password)
✅ Check: https://myaccount.google.com/apppasswords

### Stripe Not Working?
✅ Keys must match mode (test keys for test mode, live keys for live mode)

### SMS Not Sending?
✅ Set `enabled` to `true`
✅ Phone number format: `+971501234567` (with + and country code)

---

## 📚 Full Documentation

For detailed explanations, see:
- **CONFIG_README.md** - Complete configuration guide
- **test_config.php** - Interactive configuration tester

---

**⚡ That's it! 5 minutes to configure everything.**

**✅ Section 1.3 Complete!**

Next: **Section 1.4 - Database Setup**
