Technical Documentation v1.0.0 WHMCS 9.1.x · PHP 8.2–8.4

Haikhavan WordPress-WHMCS Bridge & Headless Storefront

Complete architecture reference, installation guide, database schema, hooks, and troubleshooting.

Quick Installation

  1. Purchase the module and download haikhavan_wp_bridge-ioncube-8.2-1.0.0-install.zip from your VPSrv Client Area Downloads.
  2. Upload and extract the ZIP into your WHMCS root directory so files land in modules/addons/haikhavan_wp_bridge/.
  3. Verify PHP 8.2–8.4 with ionCube PHP Loader 14+ / 15.5+ is enabled on your server.
  4. Go to System Settings → Addon Modules in WHMCS Admin, click Activate next to Haikhavan WordPress-WHMCS Bridge & Headless Storefront, and assign administrator role access.

Version: 1.0.0
WHMCS Compatibility: WHMCS 8.10 – 9.1.2+ (PHP 8.1 – 8.4)
Bundled Companion Plugin: haikhavan-whmcs-bridge/haikhavan-whmcs-bridge.php (WordPress 6.0+)


Technical Documentation — Haikhavan WordPress-WHMCS Bridge & Headless Storefront (haikhavan_wp_bridge)

1. Architecture & Directory Structure

modules/addons/haikhavan_wp_bridge/
├── whmcs.json                      # WHMCS Marketplace schema 1.0 manifest
├── haikhavan_wp_bridge.php         # Lifecycle hooks (_config, _activate, _deactivate, _upgrade, _output, _clientarea) & PSR-4 autoloader
├── api.php                         # Standalone Headless Storefront REST API & embed.js endpoint
├── hooks.php                       # AdminHomeWidgets, ClientAreaPrimaryNavbar, DailyCronJob (nonce pruning)
├── lib/
│   ├── Database.php                # 6-table schema installer, starter seeder, AES-256-CBC+HMAC secret cipher
│   ├── StorefrontApi.php           # Products, TLDs, Domain Check, Content, Cart Link, Tracking & embed.js engine
│   ├── SsoService.php              # HMAC-SHA256 signer/verifier, TTL guard, single-use nonce replay guard & audit logger
│   ├── AnalyticsService.php        # Impressions/Clicks/Checkouts funnel & per-widget attribution aggregations
│   ├── AdminController.php         # 5-tab Admin Studio dispatcher & CSRF-protected AJAX mutations
│   └── ClientController.php        # SSO login handler (?action=sso) & Client Connected Sites Portal
├── templates/
│   ├── admin/app.php               # Admin 5-tab Studio UI
│   └── client/portal.tpl           # Smarty Client Area template
└── assets/
    ├── css/haikhavan_wp_bridge.css # Scoped .wpb-wrap design system
    └── js/haikhavan_wp_bridge.js   # Zero-CDN Canvas charts, live preview designer & AJAX handlers

haikhavan-whmcs-bridge/
└── haikhavan-whmcs-bridge.php            # Ready-to-install WordPress Companion Plugin

2. Database Schema (6 Custom Tables)

All tables are prefixed with mod_hk_wpb_ and created idempotently via Haikhavan\WpBridge\Database::install().

Table Purpose Key Columns
mod_hk_wpb_sites Registered WordPress / Webflow / Next.js storefronts id, name, site_url, platform, cors_origin, api_key_prefix, api_key_hash (SHA-256), sso_secret_enc (AES-256-CBC+HMAC), rate_limit_min, userid, status, last_seen_at
mod_hk_wpb_widgets Visual pricing tables, domain search & order button embeds id, slug (UNIQUE), name, widget_type, theme, accent_color, product_group_id, billing_cycle, currency_code, config_json, impressions, clicks, checkouts
mod_hk_wpb_sso_nonces Single-use consumed SSO nonces (replay guard) id, nonce (UNIQUE), site_id, email, whmcs_userid, status, ip_address, created_at
mod_hk_wpb_events Granular widget impression/click/checkout event log id, widget_id, site_id, event_type, product_id, domain, referrer, ip_address, created_at
mod_hk_wpb_api_logs Headless API request & latency audit log (also powers rate limiter) id, site_id, endpoint, http_status, ip_address, origin, latency_ms, created_at
mod_hk_wpb_sso_audit Security audit trail for verified & blocked SSO attempts id, site_id, email, whmcs_userid, action, status, message, ip_address, created_at

3. Headless Storefront REST API Specification (api.php)

Base URL: {SystemURL}/modules/addons/haikhavan_wp_bridge/api.php

Authentication & CORS

  • Header: Authorization: Bearer <api_key> or X-Haikhavan-Bridge-Key: <api_key>
  • API keys are never stored in plaintext; StorefrontApi::authenticateSite() hashes the incoming key with hash('sha256', $key) and looks up mod_hk_wpb_sites.api_key_hash.
  • CORS Allowlist: Incoming Origin headers are matched against active mod_hk_wpb_sites.cors_origin rows. Preflight OPTIONS requests return 204 No Content.
  • Rate Limiting: Rolling 60-second window checked against mod_hk_wpb_api_logs. Exceeding site.rate_limit_min returns HTTP 429 Too Many Requests.

Endpoints

action Auth Required Query Parameters Response Payload (data)
products Yes group (int), currency (e.g. USD) currency, groups[] with products[] (monthly/quarterly/annually pricing + cart URLs)
tlds Yes currency (optional) tlds[] (tld, register, transfer, renew)
domain_check Yes domain (e.g. novacloud.io) domain, available (bool), price, cart_url
content Yes limit (optional) knowledgebase[], announcements[]
cart_link Yes pid, billingcycle, domain, promocode checkout_url, params
track Yes widget (slug), event (impression|click|checkout), product_id, domain tracked: true
embed_js Public widget (slug) application/javascript self-mounting zero-dependency storefront widget

4. Signed HMAC-SHA256 SSO Protocol (SsoService)

Endpoint: {SystemURL}/index.php?m=haikhavan_wp_bridge&action=sso

Canonical Signature String

canonical = "{site_id}|{lowercase_trimmed_email}|{unix_timestamp}|{nonce}|{redirect}"
sig       = hash_hmac('sha256', canonical, sso_secret)

Verification Pipeline (SsoService::verifyAndConsume())

  1. Parameter validation: Rejects missing site_id, malformed email, or nonce < 12 chars with HTTP 400.
  2. Open-redirect guard: Strips any redirect containing :// or leading //, falling back to clientarea.php.
  3. Short-TTL enforcement: Enforces abs(time() - $ts) <= sso_ttl_seconds (configurable 30–900s, default 300s). Expired links return HTTP 401.
  4. Constant-time HMAC check: Decrypts mod_hk_wpb_sites.sso_secret_enc (AES-256-CBC + HMAC-SHA256 using WHMCS $cc_encryption_hash) and compares via hash_equals(). Mismatches return HTTP 401.
  5. Single-use Nonce Replay Guard: Checks mod_hk_wpb_sso_nonces for nonce. If previously consumed, logs status='replayed' in mod_hk_wpb_sso_audit and returns HTTP 409 Conflict.
  6. Session establishment: Matches active tblclients account, inserts consumed nonce, logs status='success', and either returns JSON (&format=json) or sets WHMCS client session and redirects to redirect.

5. WHMCS Hooks (hooks.php)

  1. AdminHomeWidgets — Renders live KPI summary card (Connected Sites, Impressions, Clicks, Checkouts, CTR %, Verified SSO Sign-Ins) with direct shortcut to the Bridge Studio.
  2. ClientAreaPrimaryNavbar — Injects Services -> Connected Sites & Embeds (index.php?m=haikhavan_wp_bridge) for authenticated agency clients when enabled.
  3. DailyCronJob — Automatically purges consumed SSO nonces older than 48 hours from mod_hk_wpb_sso_nonces.

6. Security Hardening Summary

  • CSRF Protection: Both Admin AJAX ($_SESSION['hk_wpb_admin_csrf']) and Client Portal AJAX ($_SESSION['hk_wpb_client_csrf']) require hash_equals() validation and reject invalid tokens with HTTP 403.
  • SQL Injection Prevention: 100% Eloquent / WHMCS\Database\Capsule parameterized queries.
  • Secret Storage: API keys stored exclusively as SHA-256 hashes (shown once on creation/rotation); SSO shared secrets encrypted at rest using AES-256-CBC + HMAC-SHA256.
  • XSS Prevention: All Admin PHP templates escape via htmlspecialchars(..., ENT_QUOTES, 'UTF-8'); Smarty templates escape via |escape.
  • Zero External CDNs: Charts use native HTML5 <canvas> and vanilla ES6 JS; no third-party script dependencies.