FINANCE + TON AUTO-READY SETUP (BDIX Shared Hosting)

1) Upload files (replace existing project)

2) Run DB upgrade:
   - Open phpMyAdmin -> select your database
   - Run: api/UPGRADE_TON_FINANCE_AUTO_READY.sql

3) Admin Panel -> Settings:
   Master automation
   - auto_system_enabled: 1 (master enable for all auto jobs)

   Deposit / TON
   - Toncenter API key (from toncenter.com)
   - Toncenter base URL (default: https://toncenter.com)
   - Merchant wallet address (TON address that receives deposits)
   - Auto deposit enabled: 1

   Limits
   - Min deposit (TON)
   - Min withdraw (TON)

   Withdraw fee
   - withdraw_fee_type: none | percent | fixed
   - withdraw_fee_value: number (e.g. 2 for 2% or 0.01 for fixed)

   Auto withdraw (optional)
   - withdraw_autosend: 1 (enable)
   - withdraw_sender_mode: local_node | external_http
   - withdraw_sender_endpoint: URL (if external_http)
   - withdraw_mode: manual | auto (informational; sender setting controls actual autosend)

   Sensitive (stored encrypted in DB):
   - merchant_private_key
   - merchant_seed
   NOTE: On shared hosting it's safer to keep autosend OFF.

4) Cron jobs (optional but recommended)
   - Verify deposits:
     /usr/bin/php -q /home/USER/public_html/api/cron_verify_deposits.php
   - Retry autosend for approved withdrawals (if enabled):
     /usr/bin/php -q /home/USER/public_html/api/cron_auto_withdraw.php


AUTO DEPOSIT FIX
- cron_verify_deposits.php now auto-approves matching pending deposits.
- If no pending request exists, it creates an approved deposit row automatically.
- This removes the need for manual admin approval for memo-based deposits.
- Run api/UPGRADE_AUTO_DEPOSIT_FIX.sql once if chain_deposits table is missing.


OPTION A UPDATE (shared wallet memo deposit)
- User no longer needs to enter deposit amount before sending.
- User sends any TON amount to the merchant wallet.
- User must include memo/comment equal to their Telegram user id.
- cron_verify_deposits.php now credits the exact blockchain amount directly and creates an approved deposit row automatically.


AUTO WITHDRAW FIX
- local_node mode now uses saved merchant_seed + toncenter settings automatically.
- shared hosting should still prefer external_http.
- new optional settings: withdraw_sender_token, withdraw_node_binary.
- cron writes diagnostics to api/withdraw_autosend.log when autosend fails.
