# FamAPI - Setup Instructions

## 📁 Folder Structure
Upload the ENTIRE `fampay-project` folder contents to your domain's root folder
(e.g. `public_html/` or wherever `adityahost.in` points to).

## ⚙️ Required Setup Steps (IMPORTANT — do these before using)

### 1. Enable IMAP extension
cPanel → "Select PHP Version" → Extensions → check `imap` → Save.

### 2. Set folder permissions
The `data/` folder MUST be writable by PHP.
In cPanel File Manager: right-click `data` folder → Permissions → set to `755` or `777`.

### 3. Change the encryption key
Open `includes/functions.php`, find this line near the top:
```
define('ENCRYPTION_KEY', 'ChangeThisToYourOwnSecretKey_9273');
```
Change `'ChangeThisToYourOwnSecretKey_9273'` to your own random secret string.
This key encrypts everyone's Gmail App Passwords — keep it safe and never share it.

### 4. Change the admin password (recommended)
Same file, `includes/functions.php`:
```
define('ADMIN_USERNAME', 'Aditya268');
define('ADMIN_PASSWORD', 'Aditya@2627');
```
You can change these to whatever you like.

### 5. Enable HTTPS (SSL)
Check that your domain has an SSL certificate active (cPanel → SSL/TLS Status).
Most cPanel hosts provide free "AutoSSL" — make sure it's turned on.
This matters because users will be typing Gmail passwords into your site.

## 🔑 First-Time Use

1. Visit `yourdomain.com/` → this is the landing page.
2. Click "Grab API Now" → register a free account (auto-logs you in).
3. In the Dashboard, connect your OWN FamPay Gmail + App Password + UPI ID
   (this is only needed if YOU want to test the API yourself as a regular user).
4. Visit `yourdomain.com/login.php` and log in with the admin username/password
   to reach the Admin Panel.
5. In Admin → Settings, enter YOUR FamPay Gmail + App Password + UPI ID.
   This is the account that RECEIVES money when users buy plans.

## 📄 Pages Overview

| File | Purpose |
|---|---|
| `index.php` | Landing page with pricing |
| `register.php` | User signup (auto-login after) |
| `login.php` | Login for both users AND admin (same page) |
| `dashboard.php` | User dashboard - API key, stats, Gmail connect, buy plan |
| `docs.php` | Developer documentation with copy buttons |
| `pay.php` | Hosted checkout page (for merchants' customers) |
| `api/qr.php` | Public API - create order + QR |
| `api/verify_order.php` | Public API - verify payment |
| `admin/dashboard.php` | Admin overview + chart |
| `admin/users.php` | Admin - list all users |
| `admin/user_edit.php` | Admin - manage single user |
| `admin/plans.php` | Admin - edit pricing plans |
| `admin/settings.php` | Admin - set Gmail/UPI for receiving plan payments |

## ⚠️ Important Notes

- All data is stored in JSON files inside `data/` — no database needed.
- The `data/.htaccess` file blocks direct browser access to your JSON files. Do not delete it.
- Every user's Gmail App Password is encrypted before being saved.
- Admin session never expires until manual logout. Regular user sessions last 7 days.
