# RezoPay Admin Panel — Installation & Deployment Guide

Yeh guide aapke existing cPanel shared hosting setup (jaise `mytoolshub.co.in`)
par RezoPay Admin Panel + Backend deploy karne ke liye hai.

---

## 1. Kya mila hai is delivery mein

```
rezopay/
├── database/
│   ├── schema.sql          → Sab 28 tables + zaroori seed data
│   └── create_admin.php    → Pehla super admin banane ka CLI script
├── admin/                  → Poora Admin Panel (Core PHP + MySQL)
├── api/                    → REST API - Flutter app isi se baat karta hai
├── config-server/
│   └── config.php          → Dynamic domain/config bootstrap endpoint
├── flutter_app/             → Flutter mobile app source (lib/ + pubspec.yaml)
└── docs/
    └── INSTALLATION.md     → Yeh file
```

Admin Panel, REST API, aur Config Server — teeno fully built aur tested
hain (real HTTP requests se, MySQL ke against). Flutter app ka poora code
bhi diya gaya hai, lekin is environment mein Flutter SDK available nahi
tha isliye compile-test nahi ho paya — `flutter_app/README.md` mein setup
steps hain, wahan se `flutter analyze` zaroor chalayein.

---

## 2. cPanel par upload karna

1. `admin/` folder ko apne domain ke public_html ke andar ek subfolder mein
   daalein, jaise `public_html/rezopay-admin/`.
2. `config-server/` ko ek **subdomain** bana ke uska document root banayein —
   jaise `config.rezopay.com` → `public_html/config-server/`. Ye permanent
   rehna chahiye, kabhi mat hataiyega, kyunki Flutter app hamesha isी se
   startup config maangega.
3. `database/create_admin.php` ko temporarily upload karein, run karein, phir
   **turant delete kar dein** (neeche step 5 mein detail hai).

---

## 3. Database setup

1. cPanel → MySQL Databases mein naya database banayein (jaise
   `mytoolsh_rezopay`), naya user banayein, user ko database se attach karein
   (ALL PRIVILEGES).
2. phpMyAdmin kholein, apna naya database select karein, **Import** tab mein
   `database/schema.sql` upload karein aur run karein.
3. Verify: 28 tables create honi chahiye, aur `service_categories`,
   `referral_settings`, `domain_configurations`, `app_settings` mein kuch
   default rows already honi chahiye.

---

## 4. Config files update karna (ZAROORI)

`admin/includes/config.php` kholein aur ye values apne real cPanel setup ke
hisaab se change karein:

```php
define('APP_ENV', 'production');   // 'development' se 'production' karein
define('DB_HOST', 'localhost');
define('DB_NAME', 'mytoolsh_rezopay');   // apna real DB name
define('DB_USER', 'mytoolsh_rzpuser');   // apna real DB user
define('DB_PASS', 'YourRealPassword');   // apna real DB password

define('APP_ENCRYPTION_KEY', '...');     // 32-character random string —
                                          // API keys/passwords isi se
                                          // encrypt hote hain. Neeche diye
                                          // command se generate karein:
                                          // php -r "echo bin2hex(random_bytes(16));"
```

**IMPORTANT:** `APP_ENV` ko `production` set karne se session cookies
`secure` flag ke saath set hongi — matlab HTTPS zaroori hai. Agar aapka
domain SSL certified hai (cPanel AutoSSL se free milta hai), to koi dikkat
nahi hogi.

---

## 5. Pehla Super Admin banana

SSH ya cPanel Terminal se:

```bash
cd public_html/rezopay-admin/database
php create_admin.php <username> <email> <password> "<Full Name>"
```

Example:
```bash
php create_admin.php samir samir@rezopay.com "MyStrongPass@2026" "Samir Kumar"
```

Ye chalane ke baad **`create_admin.php` file ko turant delete kar dein** ya
public_html ke bahar move kar dein — warna koi bhi internet se naya admin
account bana sakta hai.

---

## 6. SMS/Email OTP Gateway connect karna

Abhi 2FA OTP sirf DEV MODE mein screen par dikhta hai (jab `APP_DEBUG=true`
ho). Production mein ye box automatically gayab ho jayega kyunki
`APP_ENV=production` set karne se `APP_DEBUG` false ho jaata hai.

Real SMS/Email bhejne ke liye `admin/login.php` aur `admin/2fa-verify.php`
mein `TODO: Plug real SMS/Email gateway here` comment dhundein, aur wahan
apna MSG91 (jo aap UniTopper mein use karte hain) ya SMTP integration daal
dein.

---

## 7. Domain/API Config set karna

Login karke → **Domain / App Config** page mein jaayein → apna asli backend
API URL daalein (jaise `https://mytoolshub.co.in/rezopay-api/`). Ye row
Flutter app ke config-server call ko serve hoti hai.

Jab bhi backend domain change karna ho — bas yahan se URL update kar dijiye,
naya APK build karne ki zaroorat nahi.

---

## 8. REST API deploy karna

`api/` folder ko bhi apne domain ke public_html ke andar daalein (jaise
`public_html/rezopay-api/`). `api/includes/config.php` mein wahi DB
credentials + ek **alag** `JWT_SECRET` (random, long string) set karein:

```php
define('DB_NAME', 'mytoolsh_rezopay');
define('DB_USER', 'mytoolsh_rzpuser');
define('DB_PASS', 'YourRealPassword');
define('JWT_SECRET', '...'); // php -r "echo bin2hex(random_bytes(32));"
define('APP_ENV', 'production');
```

`APP_ENV=production` set karne se OTP dev-preview automatically band ho
jayega — real SMS gateway zaroori hoga (neeche section 10 dekhein).

Phir Admin Panel → **Domain / App Config** mein `api_base_url` ko is
API ke real URL par point karein (jaise
`https://mytoolshub.co.in/rezopay-api/`), aur **UPI Collection VPA** +
**Payee Name** bhi wahin set karein — Flutter app ka Pay button isi se
UPI intent banata hai.

---

## 9. Real provider integrations connect karna

Backend ka provider architecture (`api/providers/`) ready hai, lekin abhi
tak koi **real** Recharge/BBPS/Payment/SMS provider connect nahi hai — is
wajah se transactions abhi `API_FAILED` par rukte hain (jaan-bujh kar,
"never fake success" rule follow karte hue).

Real provider connect karne ke steps:

1. **Recharge/BBPS/Payment Verification/Gift Card provider** choose karein
   (jaise PaySprint, RechargeKit, ya koi bhi jiske paas aap account banayein).
2. Us provider ka PHP class likhein jo `api/providers/interfaces.php` mein
   diye gaye interface (`RechargeProviderInterface` etc.) ko implement kare.
3. `api/providers/ProviderFactory.php` ke `$registry` array mein apni class
   register karein:
   ```php
   private static array $registry = [
       'PaySprint' => PaySprintRechargeProvider::class,
   ];
   ```
4. Admin Panel → **API Settings** mein us provider ka naam, URL, key/password
   daalein aur **Active** toggle ON karein (`provider_name` field bilkul
   wahi hona chahiye jo registry array ki key hai).
5. **SMS/Email OTP gateway**: `api/v1/auth/send-otp.php` aur
   `api/v1/auth/delete-account.php` (jahan bhi `TODO: Plug real SMS/Email
   gateway` comment hai) mein apna MSG91/SMTP integration daalein.

Jaise hi ek provider active + registered hota hai, us type ke transactions
automatically real success/failure dikhana shuru kar denge — koi aur
code change nahi chahiye.

---

## 10. Flutter App

`flutter_app/README.md` mein poora setup guide hai. Short version:

```bash
flutter create --org com.mtohsolutions --project-name rezopay rezopay_shell
cp -r rezopay/flutter_app/lib/* rezopay_shell/lib/
cp rezopay/flutter_app/pubspec.yaml rezopay_shell/pubspec.yaml
cd rezopay_shell && flutter pub get && flutter analyze
```

`lib/config/app_config.dart` mein `configServerUrl` ko apne real
config-server subdomain se update karein.

---

## 11. Legal Content

`api/v1/legal/terms.php`, `privacy.php`, `refund-policy.php` mein
template legal content hai — **[PLACEHOLDER]** wale hisse (company name,
date, support email) fill karein. Payment-facilitation app hone ki wajah
se, publish karne se pehle ek lawyer se RBI/PPI compliance check karwana
zaroori hai.

---

## 12. Security Checklist (deploy se pehle)

- [ ] `APP_ENV` = `production` (dono `admin/includes/config.php` AND
      `api/includes/config.php` mein)
- [ ] `APP_ENCRYPTION_KEY` (admin) aur `JWT_SECRET` (api) — dono alag,
      random, 32+ character strings se replace kiye
- [ ] `create_admin.php` delete/move kar diya
- [ ] Domain par SSL/HTTPS active hai
- [ ] Database user ke pass sirf zaroori database ka access hai
- [ ] `admin/includes/`, `database/` folders `.htaccess` se web-access block
      kiye ja sakte hain (optional extra layer):
      ```apache
      # admin/includes/.htaccess
      Deny from all
      ```
- [ ] Real SMS/Email OTP gateway connect kiya (dono admin 2FA aur user OTP)
- [ ] UPI Collection VPA + Payee Name Admin Panel me set kiya
- [ ] Kam se kam ek real Recharge/BBPS provider connect + active kiya
- [ ] Legal pages (`api/v1/legal/*.php`) ke placeholders fill kiye, lawyer
      review karwaya
- [ ] `flutter_app` par `flutter analyze` chala kar clean confirm kiya
