# iTzAYDiN-BOT V8 Commerce

V8 adds an optional, multi-site Commerce layer on top of the V7 modular control plane.

## Commerce architecture
- Optional Website Connector; the bot works normally without a website.
- Per-site API Key + HMAC Webhook Secret, generated by the bot and shown only once.
- No personal domain, IP, Bot Token, API key or gateway credential is hard-coded.
- Encrypted connector secrets using a local 32-byte master key stored at `storage/.commerce_master.key`.
- Website-to-bot API at `api/commerce.php` with a signed 5-minute freshness window for stale-request rejection.
- Signed bot-to-website status callback to `/itz-commerce-webhook`.

## Product engine
Commerce products support these fulfillment modes:
- `manual`
- `core`
- `api`
- `webhook`
- `stock`

Each product can define arbitrary customer parameters with:
- key
- label
- before/after payment phase
- required/optional
- field type

This supports miscellaneous products such as reseller panels, licenses, hosting, domains and manually activated services.

## Orders and payments
- Website orders are stored in a dedicated order ledger.
- New orders, completed parameter forms and payment success/failure are reported to the Telegram admin.
- If the website supplies a Telegram user ID, the customer also receives order/payment/completion notifications in the bot.
- Payment Bridge exposes only safe gateway capability/status metadata. Gateway secrets are never returned to the website.
- A website must verify a gateway payment first, then sign and send `payment.success` to Commerce.

## PasarGuard reseller fulfillment
When a Commerce product uses:
- fulfillment type: `api`
- backend type: `pasarguard_reseller`
- a valid PasarGuard backend reference
- a valid Role ID

and the required `username` parameter is present, the Commerce worker can create the Remote Admin automatically and deliver generated credentials to the linked Telegram customer.

## Admin surfaces
- `panel/commerce.php` — sites, products, parameters, orders, payment bridge and integration docs.
- Telegram Admin → `iTz Commerce Hub` — connector creation, credential rotation, site pause/resume, product creation/toggle/parameters, order inspection/status.
- `commerce-site-kit/` — PHP SDK and signed webhook example for external websites.

## Cron
`commerce.php` is registered as a normal iTz cron job with a one-minute default schedule. It handles asynchronous Commerce fulfillment.
