SendFlow WhatsApp for WHMCS  v1.8.5
===================================

INSTALL
1. Upload the "modules" folder to your WHMCS root (merges into modules/addons/sendflow).
2. WHMCS Admin > System Settings > Addon Modules > SendFlow WhatsApp > Activate.
3. Click Configure:
   - Gateway API URL : log in at https://sendflow.pk/login > API & webhooks (ends with /api/v1)
   - API Key         : https://sendflow.pk/login > your number > API access > Copy
   - Admin WhatsApp numbers : e.g. 923001234567
   - Access Control  : tick Full Administrator
   Save.
4. Addons > SendFlow WhatsApp > Dashboard: gateway should show "connected". Send a test.
5. Copy the Webhook URL shown on the Dashboard into SendFlow > your number > Webhook URL > Save.

Done. Messages go out automatically on WHMCS events. Edit texts under "Message templates".

HOW MESSAGES ARE TRIGGERED (one trigger per message)
1. WHMCS emails: whenever WHMCS emails a client (Invoice Created, Payment Reminder, Overdue notices,
   Payment Confirmation, Welcome emails, Suspension, Domain notices, Ticket opened/reply, Signup...),
   the matching WhatsApp message is sent. If you turn an email off in WHMCS, its WhatsApp stops too.
2. Event hooks send only the messages that have no WHMCS email: invoice cancelled, service terminated,
   and all admin alerts.
Setting "Message trigger = Emails + events" also sends from events (use only if you disable WHMCS emails).
Duplicate protection stays on as a safety net.

WHAT IS SENT
Invoices: created (PDF), reminder, 1st/2nd/final overdue (final with PDF), paid (PDF receipt), card payment failed, refunded, cancelled*
Orders/services: order confirmation, activated/welcome, package upgraded/changed, suspended, restored, terminated, cancellation request
Domains: registered, transferred, renewed, renewal reminders (WHMCS schedule), expired
Support: ticket opened, staff reply, ticket closed*
Account: welcome message on signup
Admin alerts: new order, payment, package upgraded/changed, new ticket, client reply, cancellation, domain/provisioning failed, new client*, admin login*
(* = off by default, switch on under Message templates)

OPTIONAL
- Separate WhatsApp number per client: create a client custom field (e.g. "WhatsApp Number") and enter its name in Configure.
- Opt-out: create a client tickbox custom field "Disable WhatsApp notifications" and enter its name in Configure.

RELIABILITY
- If the gateway is offline, messages wait in WHMCS and are retried by the WHMCS cron (every run, up to 6 times).
- The gateway itself paces messages with your delay / daily limit / quiet-hour settings.
- Errors never block WHMCS; they appear in Utilities > Logs > Module Log (module "sendflow").

TROUBLESHOOTING
- Dashboard says "HTTP 403" or a Cloudflare page: in Cloudflare (your SendFlow domain) > Security, turn off Bot Fight Mode
  or add a WAF Skip rule for hostname of your API URL (e.g. sendflow.pk) and path starting with /api/.
- "HTTP 401": API key wrong or regenerated - paste the current key in Configure.

UPDATES
Dashboard > Updates shows your version and the latest one on your SendFlow gateway.
- Once a day the WHMCS cron asks your gateway if there is a new version (one small request; WHMCS pages never wait for it).
- Automatic updates (on by default for new installs; switch on the Dashboard or in Configure): when a new version is found it the new version from your gateway, checks its SHA-256 fingerprint and version, backs up
  the current files and installs. You get a WhatsApp on your admin numbers. "Roll back" puts the previous version back.
- "Update now" does the same with one click. Needs the PHP zip extension and write access to modules/addons/sendflow;
  otherwise use "Download zip" and upload the files over the old ones.
Settings, templates and logs are never touched by an update.

STORED LOGS
Dashboard > Stored data: keep the message log, replies and event records for 48 hours (default), 7, 30 or 90 days.
Older records are deleted every hour by the WHMCS cron (never while a page loads). "Empty logs now" deletes everything stored.
Messages still waiting to be sent are always kept.

v1.8.5  Fix: updates failed with "Download address is not your SendFlow gateway" when your API URL and the SendFlow
        website use different addresses. The update now always downloads from your API URL's address (the fingerprint
        check still proves the file is genuine).
v1.8.3  Named simply "SendFlow"; "Log in to SendFlow" button and setup tips link to https://sendflow.pk/login;
        new installs default to https://sendflow.pk/api/v1.
v1.8.2  Update check once a day from the WHMCS cron only; addon pages never contact the gateway for updates or run clean-up,
        so WHMCS is never slowed down. "Check now" still checks straight away.
v1.8.1  Safer updates: every new PHP file is code-checked first, the backup is saved before anything changes,
        new files are written beside the old ones and switched in one quick step (hooks.php last), only one update
        runs at a time, and if the addon files ever fail to load, WHMCS keeps working and SendFlow is skipped.
v1.8.0  New dashboard design. Package upgrade/downgrade messages (client + admin alert, with old and new package).
        Automatic updates with fingerprint check and roll back. Stored logs deleted after 48 hours by default, "Empty logs now".
        Note: 1.7.0 can't update itself — upload 1.8.1 once by hand; later versions can install automatically.
v1.7.0  One trigger per message: client messages are sent only when WHMCS sends the matching email
        (new setting "Message trigger"). Event hooks only send messages that have no email.
v1.6.2  Fix: double messages are now always blocked (even with Duplicate protection = 0); skipped messages logged once;
        "&amp;amp;" in templates fixed (WHMCS escaped the text on every save).
v1.6.1  Fix: no more double messages when WHMCS fires the invoice event and the email at the same moment.
v1.6.0  Update notifications, SendFlow branding.
