Bahari KYC for Blesta
=====================

Requirements: Blesta 5.3 or newer (5.x), PHP 7.4 or newer with curl.

Install
1. Upload the contents of this zip to the Blesta root folder. It creates plugins/bahari_kyc/.
2. In Blesta admin open Settings > Company > Plugins > Available, find Bahari KYC and click Install.
3. Click Manage on the plugin. 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 on the
   Manage page (https://<your Blesta>/plugin/bahari_kyc/webhook/index/). Copy the signing
   secret (whsec_...) into the plugin settings and save.
5. The Manage page tests the connection with the saved key. Connection should say OK.
6. Open Tools > Bahari KYC for the overview.

Client area
  Clients verify at client/plugin/bahari_kyc/client_main/ (the plugin adds
  "Identity verification" to the client menu).
  A widget on the client dashboard shows until the client is verified (can be turned off).

Staff area
  Tools > 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 has an "Identity verification" widget with the status, reason codes
  and a link to the session in the Bahari KYC dashboard.

Settings
  Require verification at checkout   Off, all orders, or only packages in the listed package group ids.
                                      Unverified clients are sent from the order checkout to the
                                      verification page before the order is created.
  Hold setup for unverified clients   Automatic setup of pending services is stopped until the client
                                      is approved. The service is set to In Review and the module is
                                      not called. Orders can still be placed and paid.
  Run held setup after approval       Held services go back to Pending when the client is approved.
                                      The "Provision Paid Pending Services" task sets up the paid
                                      ones on its next run (client group setting must allow it).
  Staff can run setup manually        A staff member activating a pending service is not stopped.
  Declined clients can try again      Otherwise they need to contact support.
  Widget 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 plugin then reads the current status from the API, so repeated or out of order events
  are safe. The cron task "Bahari KYC re-check" (every 10 minutes) re-checks open sessions in
  case a webhook was missed.

Limits on Blesta 5
  Blesta 5 events cannot cancel an order, so the checkout rule works by sending the client to
  the verification page when they open the checkout. Orders placed through the API or by staff
  are not checked. The setup hold covers the automatic "pending to active" step.

Data
  Only the session id, status and reason codes are stored, in the table bahari_kyc_status.
  Held service ids are kept in bahari_kyc_holds until they are released.
  Photos and document data stay in Bahari KYC. Uninstalling removes the settings and keeps
  the tables.

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