# 🏦 Bank Transfer Setup Guide
**Quick Testing & Production Setup**

## ✅ Bank Transfer is Now Active!

Bank transfer is now visible on your deposit page. Here's what you need to know:

### 🎯 Current Status

- ✅ Bank Transfer service enabled
- ✅ Showing on deposit page
- ⚠️ Using **test bank accounts** (need to update)
- ⚠️ Manual verification required

---

## 🚀 Quick Setup (5 Minutes)

### Step 1: Update Bank Accounts

Edit `/services/payments/BankTransferService.js` (lines 13-32):

```javascript
this.bankAccounts = [
  {
    bank_name: 'Your Bank Name 1',
    account_number: 'XXXXXXXXXX',
    account_name: 'WakaTraffic Business Account',
    bank_code: '044' // Bank code (e.g., 044 for Access Bank)
  },
  {
    bank_name: 'Your Bank Name 2 (Optional)',
    account_number: 'XXXXXXXXXX',
    account_name: 'WakaTraffic Business Account',
    bank_code: '058'
  }
];
```

**Common Bank Codes:**
- Access Bank: 044
- GTBank: 058
- First Bank: 011
- Zenith Bank: 057
- UBA: 033
- Kuda Bank: 090267
- Opay: 100004
- PalmPay: 100033
- Moniepoint: 50515

### Step 2: Restart Server

```bash
cd /mnt/c/xampp/htdocs/waka_traffic
npm run dev
```

### Step 3: Test Deposit Flow

1. Go to: http://localhost:5000/deposit.html
2. Select "Bank Transfer" from payment methods
3. Enter amount (e.g., ₦1000)
4. Click "Proceed to Payment"
5. You'll see your bank account details
6. Upload payment proof (optional for testing)

---

## 📋 How Bank Transfer Works

### User Flow:

1. **User selects Bank Transfer**
   - Sees your bank account details
   - Gets unique reference number
   - Gets payment instructions

2. **User makes transfer**
   - Transfers exact amount to your account
   - Takes screenshot of receipt
   - Returns to platform

3. **User uploads proof** (optional)
   - Uploads payment screenshot
   - Adds note/details
   - Status changes to "Verifying"

4. **Admin approves**
   - Admin reviews proof in dashboard
   - Checks if payment received
   - Approves or rejects

5. **User gets credited**
   - Wallet updated automatically
   - Transaction recorded
   - Email notification sent

---

## 🎯 Best Approach for Going Live

I recommend **Option 2** for best results:

### Option 1: Manual Bank Transfer Only (Simplest)
**Pros:**
- ✅ No API integration needed
- ✅ No monthly fees
- ✅ Works with any bank account
- ✅ Already implemented

**Cons:**
- ❌ Manual verification required
- ❌ 5-10 minute processing time
- ❌ Admin workload increases

**Best for:**
- Small scale (< 50 deposits/day)
- Testing phase
- Budget constraints

### Option 2: Automated + Manual Hybrid (RECOMMENDED) ⭐
**Setup:**
```javascript
// Keep these active in payment_methods table:
✅ Korapay (automated card/bank - instant)
✅ Cryptomus (crypto - 5 min)
✅ Bank Transfer (manual - 10 min backup)
```

**Pros:**
- ✅ 90% automated (Korapay/Crypto)
- ✅ Manual backup for flexibility
- ✅ Multiple payment options
- ✅ Better conversion rate

**Cons:**
- ⚠️ Need Korapay API setup
- ⚠️ Small transaction fees

**Best for:**
- Medium to large scale
- Professional operation
- Going live recommended

### Option 3: Fully Automated with Virtual Accounts (Premium)
**Setup:**
```javascript
✅ Moniepoint Virtual Accounts (instant)
✅ Kuda Virtual Accounts (instant)
✅ Korapay (card/bank - instant)
✅ Cryptomus (crypto - 5 min)
✅ Bank Transfer (manual backup)
```

**Pros:**
- ✅ 100% automated
- ✅ Instant crediting
- ✅ No admin intervention
- ✅ Scales infinitely

**Cons:**
- ⚠️ Requires API setup (3 providers)
- ⚠️ Monthly fees
- ⚠️ More complex setup

**Best for:**
- High volume operations
- Enterprise level
- Maximum automation

---

## ⚡ Recommended: Quick Production Setup

For **going live today**, here's my suggestion:

### Primary Method: Korapay (Automated)
- Already configured in your .env
- Accepts cards, bank transfers, USSD
- Instant verification
- 1.5% fee (industry standard)

### Backup Method: Manual Bank Transfer
- No API needed
- Free (no fees)
- 10-minute manual verification
- Use when automation fails

### Setup Steps:

```bash
# 1. Update bank accounts (this file, Step 1 above)
# 2. Verify Korapay credentials in .env
KORAPAY_MODE=live
KORAPAY_PUBLIC_KEY_LIVE=pk_live_your_live_key
KORAPAY_SECRET_KEY_LIVE=sk_live_your_live_key

# 3. Enable all methods on deposit page
# Edit /public/deposit.html line 684-686:
paymentMethods = data.data.filter(m =>
  m.code === 'korapay' || m.code === 'cryptomus' || m.code === 'bank_transfer'
);

# Or show ALL methods:
paymentMethods = data.data; // Show all active methods

# 4. Restart server
npm run dev
```

---

## 🔧 Admin Verification Process

### Approve Bank Transfer Deposits:

1. **Check Admin Dashboard**
   - Go to: http://localhost:5000/admin
   - Click "Transactions" → "Deposit History"
   - Filter: Status = "Verifying"

2. **Review Payment Proof**
   - View uploaded screenshot
   - Check bank account for actual payment
   - Verify amount matches

3. **Approve or Reject**
   ```javascript
   // Approve endpoint (already implemented):
   POST /api/admin/deposits/:id/approve

   // Reject endpoint:
   POST /api/admin/deposits/:id/reject
   ```

4. **User Gets Credited**
   - Wallet updated automatically
   - Transaction recorded
   - Email sent (if configured)

---

## 📊 Testing Checklist

Before going live, test these:

- [ ] User can see bank transfer option
- [ ] Correct bank accounts displayed
- [ ] Payment proof upload works
- [ ] Admin can approve deposits
- [ ] Wallet credits correctly
- [ ] Transaction records created
- [ ] Email notifications sent (if enabled)
- [ ] Reference numbers are unique
- [ ] Korapay live keys configured
- [ ] All payment methods tested

---

## 🎨 Customization Options

### Change Processing Time Display

Edit `/database/seeders/payment_methods_seeder.sql` line 127:

```sql
processing_time_minutes = 10  -- Change to 5, 15, etc.
```

### Change Transaction Fees

```sql
transaction_fee_percentage = 0.00,  -- Add 1.5 for 1.5% fee
transaction_fee_fixed = 0.00,       -- Add 50 for ₦50 flat fee
```

### Add More Bank Accounts

Edit `/services/payments/BankTransferService.js`:

```javascript
this.bankAccounts = [
  {
    bank_name: 'Access Bank',
    account_number: '0123456789',
    account_name: 'WakaTraffic Ltd',
    bank_code: '044'
  },
  {
    bank_name: 'GTBank',
    account_number: '0987654321',
    account_name: 'WakaTraffic Ltd',
    bank_code: '058'
  },
  {
    bank_name: 'Kuda Bank',
    account_number: '1234567890',
    account_name: 'WakaTraffic Ltd',
    bank_code: '090267'
  }
  // Add as many as you want
];
```

---

## 🚨 Common Issues

### Issue: Bank Transfer not showing on deposit page
**Solution:**
```javascript
// Check deposit.html line 684-686 has bank_transfer in filter
m.code === 'bank_transfer'
```

### Issue: Payment proof upload fails
**Solution:**
```javascript
// Check uploads folder exists and is writable
mkdir -p /mnt/c/xampp/htdocs/waka_traffic/uploads
chmod 755 uploads
```

### Issue: Admin approval doesn't credit wallet
**Solution:**
```sql
-- Check deposits table has amount_credited column
SELECT amount_credited FROM deposits LIMIT 1;
```

---

## 📱 Mobile Responsiveness

Bank transfer modal is fully responsive:
- ✅ Works on mobile browsers
- ✅ Bank details easy to copy
- ✅ File upload from camera
- ✅ Reference number highlight

---

## 🔒 Security Features

Already implemented:
- ✅ Unique references per transaction
- ✅ Amount verification before approval
- ✅ Admin authentication required
- ✅ Transaction logging
- ✅ Duplicate prevention
- ✅ Expiry times (24 hours)

---

## 📞 Support

**Need Help?**
- Check `/services/payments/BankTransferService.js` - Main logic
- Check `/routes/depositRoutes.js` - API endpoints
- Check `/public/deposit.html` - Frontend display

**Test Endpoints:**
```bash
# Get payment methods
curl http://localhost:5000/api/deposits/methods \
  -H "Authorization: Bearer YOUR_TOKEN"

# Initialize deposit
curl -X POST http://localhost:5000/api/deposits/initialize \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"payment_method_id": 6, "amount": 1000}'
```

---

## ✅ Production Deployment

When deploying:

1. **Update .env for production:**
```env
NODE_ENV=production
KORAPAY_MODE=live
KORAPAY_PUBLIC_KEY_LIVE=pk_live_xxxxx
KORAPAY_SECRET_KEY_LIVE=sk_live_xxxxx
```

2. **Remove test filters:**
```javascript
// deposit.html - show ALL active methods
paymentMethods = data.data;
```

3. **Update bank accounts:**
- Use real business account details
- Verify account names match
- Test with small amount first

4. **Enable email notifications:**
- Configure SMTP (see NAMECHEAP_EMAIL_SETUP.md)
- Test deposit confirmation emails

5. **Set up admin monitoring:**
- Check deposits every 30 minutes
- Enable push notifications (optional)
- Set up alert system for pending deposits

---

**Ready to go live!** Update your bank accounts in `BankTransferService.js` and restart the server.

For questions, check the code comments or create an issue.
