# cPanel / Node Deployment — Paid AI V2

1. Create a separate app directory/subdomain. Do not overwrite an existing production site's operating system.
2. Create a Node.js 22+ application in cPanel.
3. Upload this project into the Node application root.
4. Startup file: `server.mjs`.
5. No `npm install` is required for runtime.
6. Configure the environment variables from `.env.example` in cPanel; do not expose a real `.env` publicly.
7. Set the OpenAI values.
8. Set the Paddle values from `PADDLE_PAYMENT_SETUP.md`.
9. Keep `TRUST_PROXY=1` when your normal cPanel/reverse-proxy layer supplies forwarded client IPs.
10. Restart the Node application.
11. Visit `/api/health` and verify AI + payment state.
12. In Paddle, set the webhook destination to `https://YOUR-DOMAIN/api/webhooks/paddle`.
13. First test the entire purchase flow in Paddle Sandbox.
14. Add an hourly cron for `npm run cleanup`.
15. Back up `storage/payments.json` because it contains unused anonymous card credits and idempotency records.

## Live switch

Only after Paddle website/domain approval and Sandbox testing:

- `PADDLE_ENV=live`
- live `PADDLE_CLIENT_TOKEN`
- live `PADDLE_PRICE_ID`
- live notification destination `PADDLE_WEBHOOK_SECRET`

Restart the app and perform one real low-value checkout test.

## Rollback

Keep the previous known-good ZIP plus the private environment-variable record. Restore the project directory and persistent payment ledger, then restart the Node app.
