# Tally AutoFill – License System Setup Guide

## Step 1 – Upload server files to cPanel

1. Login to cPanel → File Manager
2. Go to `public_html`
3. Create a new folder: `tallyautofill`
4. Upload these files into it:
   - `config.php`
   - `api.php`
   - `admin.php`
   - `install.sql`

## Step 2 – Create MySQL database

1. cPanel → MySQL Databases
2. Create database: e.g. `myuser_tallylic`
3. Create user: e.g. `myuser_admin` with a strong password
4. Add user to database with ALL PRIVILEGES
5. Open phpMyAdmin → select your database → SQL tab
6. Paste contents of `install.sql` and click Go

## Step 3 – Edit config.php

Open `config.php` and fill in:
- `DB_NAME` – your database name
- `DB_USER` – your database user
- `DB_PASS` – your database password
- `API_SECRET` – any random 32-char string
- `RAZORPAY_KEY_ID` and `RAZORPAY_KEY_SECRET` – from razorpay.com
- `ADMIN_PASSWORD` – your admin panel password

## Step 4 – Edit tally_autofill.py

Change this line:
```python
API_URL = "https://yourdomain.com/tallyautofill/api.php"
```
To your actual URL, e.g.:
```python
API_URL = "https://mysite.com/tallyautofill/api.php"
```

## Step 5 – Test API

Open browser and visit:
`https://yourdomain.com/tallyautofill/api.php?action=validate&key=TEST`

You should see: `{"ok":false,"msg":"Missing key or machine_id"}`
That means the API is working!

## Step 6 – Setup Razorpay webhook

1. Login to razorpay.com → Settings → Webhooks
2. Add webhook URL: `https://yourdomain.com/tallyautofill/api.php?action=razorpay_webhook`
3. Events: select `payment.captured`
4. Copy Webhook Secret and paste in config.php as `RAZORPAY_KEY_SECRET`

## Step 7 – Rebuild EXE

Run `BUILD_EXE.bat` again to rebuild with the new license system.

## Step 8 – Admin panel

Visit: `https://yourdomain.com/tallyautofill/admin.php`
Login with your `ADMIN_PASSWORD`

From admin panel you can:
- Generate license keys manually (for WhatsApp customers)
- See all active customers
- Suspend/activate licenses
- Reset machine binding (if customer changes PC)
- Extend expiry dates
- View all activity logs

## How to sell via WhatsApp (no website needed!)

1. Create a Razorpay Payment Link at razorpay.com → Payment Links
2. Set amount (Rs. 199 / 1499 / 3999)
3. Add a note field for "Email" (mandatory)
4. Share the payment link on WhatsApp
5. After payment → webhook auto-sends license key to customer email
6. Customer opens EXE → clicks "Enter License Key" → pastes key → Done!

## Pricing suggestion
| Plan     | Price      | Duration |
|----------|-----------|----------|
| Trial    | Free       | 7 days   |
| Monthly  | Rs. 199    | 30 days  |
| Yearly   | Rs. 1,499  | 365 days |
| Lifetime | Rs. 3,999  | Forever  |
