# 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 (admin panel se, no code)

Backend mein ab ek **Generic HTTP Provider** system hai — kisi bhi
REST-style Recharge/BBPS/Payment/Gift Card API ko poori tarah **Admin
Panel se hi** configure kar sakte hain, koi PHP code likhne/edit karne ki
zaroorat nahi.

**Pehle: agar aapne live database par purana `schema.sql` already import
kar rakha hai**, to naye columns add karne ke liye
`database/migration_generic_provider.sql` ko phpMyAdmin se import karein
(sirf ek baar, existing data safe rehta hai). Naya install kar rahe hain
to sirf `schema.sql` hi kaafi hai — usme ye columns already hain.

**Provider add karne ke steps:**

1. Admin Panel → **API Settings** → **+ Add Provider**
2. Provider ki API documentation dekhkar fields bharein:
   - **Request URL Template** — jaise `https://api.provider.com/recharge`
   - **Request Body Template** — placeholders ke saath, jaise:
     ```json
     {"mobile":"{mobile_number}","operator":"{operator_code}","amount":{amount},"ref":"{txn_ref}"}
     ```
     Available placeholders: `{mobile_number}` `{operator_code}`
     `{biller_code}` `{consumer_number}` `{amount}` `{txn_ref}` `{api_key}`
     `{api_username}` `{api_password}`
   - **Auth Type** — API key header mein jaata hai ya query param mein ya
     Basic Auth — jo bhi provider bole
   - **Response Mapping** — provider ka response JSON dekhkar batayein
     kaunsa field "success" batata hai (jaise `status`), aur kya value
     success maani jaaye (jaise `SUCCESS`)
3. Save karein, phir **"Test Connection"** button se real request bhejkar
   verify karein — koi transaction record nahi banta, sirf debug ke liye.
4. Sab sahi lage to **Active** toggle ON karein (2FA OTP maangega).

**SMS/Email OTP gateway** abhi bhi code se connect karna padta hai (ye
alag cheez hai, HTTP-template se nahi ho sakta kyunki SMS gateways ka
tarika bahut alag hota hai): `api/v1/auth/send-otp.php` aur
`api/v1/auth/delete-account.php` mein `TODO: Plug real SMS/Email gateway`
comment dhundein.

Jaise hi ek provider Active hota hai, us type ke transactions
automatically real success/failure dikhana shuru kar denge.

---

## 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 Admin Panel se configure + "Test Connection" se verify + 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
