Bahari KYC for FOSSBilling
==========================

Requirements: FOSSBilling 0.8 or newer (tested on 0.8.9), PHP 8.2 or newer with curl.

Install
1. Upload the contents of this zip to the FOSSBilling root folder. It creates modules/Baharikyc/.
2. In FOSSBilling admin open Extensions, find Bahari KYC and click Activate.
   On a brand new FOSSBilling install the event hooks are connected by the first cron run,
   so make sure the FOSSBilling cron is running (or run php cron.php once).
3. Open Extensions > Bahari KYC > Settings (or Extensions > Overview > Bahari KYC > Settings).
   Paste a secret API key from the Bahari KYC dashboard (API keys). Keys start with sk_live_.
4. In the Bahari KYC dashboard open Webhooks and add an endpoint with the URL shown in the
   settings (https://<your FOSSBilling>/baharikyc/webhook). Copy the signing secret (whsec_...)
   into the module settings.
5. Open Extensions > Bahari KYC. Connection should say OK.
6. Give staff members access under Staff > Groups if they are not full admins
   (permissions: View and Manage identity verifications).

Client area
  Clients verify at /baharikyc. Link it from your menu or emails.
  A panel on the client dashboard shows until the client is verified (can be turned off).

Admin area
  Extensions > Bahari KYC shows the connection, webhook URL, a client lookup with
  "Re-check status" and "Get verification link", and the latest verifications.
  The client profile page shows a status box with a link to the session in the
  Bahari KYC dashboard.

Settings
  Require verification at checkout   Off, all orders, or only products in the listed category ids.
  Hold setup for unverified clients   Automatic order activation is stopped until the client is approved.
                                      The order stays in Pending setup (or Failed setup) with a note.
  Run held setup after approval       Held orders are activated when the client is approved.
  Admins can run setup manually       Activate clicked by an admin (or an order created with
                                      "activate") is not stopped.
  Declined clients can try again      Otherwise they need to contact support.
  Panel on client dashboard           Shows a short panel until the client is verified.

Webhooks and cron
  Every webhook is checked against the Verify-Signature header (HMAC-SHA256 of
  "<timestamp>.<raw body>" with the signing secret, at most 5 minutes old). Bad signatures get 401.
  The module then reads the current status from the API, so repeated or out of order events
  are safe. The FOSSBilling cron re-checks open sessions in case a webhook was missed.

API
  client/baharikyc/status and client/baharikyc/start for custom themes.
  admin/baharikyc/client_get, refresh, link, sync, test_connection, get_config, save_config.

Data
  Only the session id, status and reason codes are stored, in the table mod_baharikyc.
  Held order ids are kept in mod_baharikyc_hold until they are set up.
  Photos and document data stay in Bahari KYC. Deactivating the module keeps the tables.

Help and documentation: https://kyc.baharione.com/docs#fossbilling
Support: support@baharione.com
