# UPI Deposit System - Installation Guide

## Prerequisites
- PHP 7.4+ with PDO MySQL extension
- MySQL 5.7+ / MariaDB 10.3+
- XAMPP, LAMP, or similar PHP hosting
- Existing binary-options platform installed

## Installation Steps

### 1. Run Database Migration
```bash
mysql -u root -p binary_options < database/upi_deposit_migration.sql
```
Or import `database/upi_deposit_migration.sql` via phpMyAdmin.

This creates:
- `admin_logs` table
- `api_tokens` table
- Adds `auto_verified`, `ip_address`, `device_info`, `verification_notes` columns to `upi_payments`
- Adds `utr_number`, `auto_verified`, `device_info` columns to `deposits`

### 2. Configure UPI Settings
Go to **Admin Panel → UPI Settings** (`admin/upi-settings.php`) and set:
- **UPI ID**: Your merchant UPI ID (e.g., `merchant@ybl`)
- **Merchant Name**: Display name
- **Min/Max Deposit**: Amount limits
- **Payment Timeout**: Session duration (default: 600 seconds)
- **UPI Status**: Set to "Active" to enable

### 3. Files Overview

| File | Purpose |
|------|---------|
| `user/deposit.php` | User deposit page (4-step UPI flow) |
| `includes/UpiVerifier.php` | Auto-verification engine |
| `includes/ApiAuth.php` | API token authentication |
| `api/payment/create.php` | Create UPI payment API |
| `api/payment/submit-utr.php` | Submit UTR + auto-verify API |
| `api/deposit/status.php` | Check deposit status API |
| `api/user/transactions.php` | Transaction history API |
| `admin/deposits.php` | Admin deposit management |
| `admin/upi-payments.php` | Admin UPI payment management |

### 4. Mobile App API Usage

**Authentication**: Use Bearer token from login:
```
POST /api/user/login.php
→ Returns token

GET /api/user/balance.php
Authorization: Bearer <token>
```

**Deposit Flow**:
```
1. POST /api/payment/create.php    { amount: 500 }
2. User pays via QR/UPI link
3. POST /api/payment/submit-utr.php { payment_ref, utr_number }
4. GET  /api/deposit/status.php    ?payment_ref=PAY...
```

### 5. How Auto-Verification Works
1. User enters deposit amount → System generates UPI QR + deep links
2. User pays via GPay/PhonePe/Paytm
3. User submits UTR number
4. System validates: UTR format (6-30 alphanumeric) → Duplicate check → Auto-approve + credit balance
5. If checks fail → Flagged for admin manual review
