FISCALHUB ZIMBABWE v1.3.0
Outright Digital Tech

INSTALLATION (cPanel; no terminal required)
1. Create a MySQL database and database user in cPanel > MySQL Databases.
2. Grant ALL PRIVILEGES to that user for the database.
3. Upload the ZIP contents into your domain/subdomain folder.
4. Visit https://your-domain/install.php and complete the setup wizard.
5. Sign in, then delete install.php.
6. If upgrading from v1.2, run /upgrade.php once as administrator and then delete it.
6. Enable HTTPS. PHP 8.1+ (8.2 recommended), PDO MySQL, cURL, OpenSSL and JSON are required.

UPGRADE FROM v1.2.0
1. Back up your database and application folder.
2. Upload and replace the application files with this release (do not overwrite config.php).
3. Sign in as administrator and visit /upgrade.php once.
4. Confirm the upgrade completion message, then DELETE upgrade.php.
5. Test in the Fiscal Services test environment before any live use.

FISCAL SERVICES CONNECTION
Each customer connects their own Fiscal Services account through the FiscalHub API. The upstream credentials are sent over HTTPS, encrypted server-side with AES-256-GCM and are never returned to the client. FiscalHub obtains the upstream lifetime Bearer token on the server during connection and stores it encrypted for subsequent requests. Keep cPanel config.php private and back up the database securely. Changing DB credentials changes the vault encryption key; export/reconnect provider accounts before changing those values.

API AUTHENTICATION
Use the FiscalHub API key generated in Developer Tools:
Authorization: Bearer fh_test_...
Content-Type: application/json
Accept: application/json

Connect upstream account (test key connects to test environment; live key to live):
POST /api/v1/provider/connect
{"email":"your-fiscal-services-email","password":"your-password"}

Check connection:
GET /api/v1/provider/status

Register device (active FiscalHub subscription required):
POST /api/v1/devices
{"device_id":"POS-001","company_name":"Example Pvt Ltd","activation_key":"ZIMRA-activation-key","serial_number":"SERIAL-001","number_of_terminals":1,"is_tax_inclusive":true}

List devices: GET /api/v1/devices
Device operations: GET /api/v1/devices/{device}/status; POST /api/v1/devices/{device}/ping; POST /api/v1/devices/{device}/open-day; POST /api/v1/devices/{device}/close-day

Submit invoice / receipt / credit note:
POST /api/v1/invoices
Idempotency-Key: a-unique-invoice-request-id
The request body follows the Fiscal Services published invoice schema, including device_id, terminal_id, invoice_no, type (FiscalInvoice, CreditNote, PosReceipt, PosCreditNote), currency, total, vattotal, buyer (optional) and items. Keep invoice_no unique per device. A successful response is saved in FiscalHub's invoice audit table.

Lookup: GET /api/v1/invoices/{invoice-number}
Bulk: POST /api/v1/invoices/bulk with a JSON array of invoices.

LIMITS AND IMPORTANT SAFEGUARDS
- FiscalHub subscriptions and upstream Fiscal Services charges are separate. Fiscal Services documentation says live mode requires an annual USD 50 subscription per device. Verify current terms directly with the provider.
- Do not sell or activate live access until your reseller/partner rights, customer account delegation, upstream fees, data responsibilities and support obligations are confirmed in writing.
- This build uses the published Fiscal Services API; it is not a direct ZIMRA FDMS implementation or a certification of regulatory compliance.
- Invoice submissions are sent synchronously to Fiscal Services. The bulk endpoint is asynchronous upstream. The app records successful single-invoice responses and prevents duplicate invoice numbers per customer/device; idempotency keys are supported for successful replay responses. A full durable retry queue, signed payment gateway callbacks, SMTP email delivery and full bulk-job polling remain future work. v1.3 adds subscription event history, administrative suspend/restore/cancel controls, payment reconciliation records and scheduled in-app renewal reminders.
- Never test with real fiscal receipts until you have validated payloads, tax treatment, invoice sequencing, credit-note references and provider account permissions in test mode.
- Live API key means FiscalHub live environment only; it is not evidence that a customer/device is approved for live fiscalisation.
- Do not expose provider credentials or Fiscal Services tokens in browser code or logs.

CRON
Expiry job (daily):
php -q /home/CPANELUSER/public_html/fiscalhub/cron/expire.php

Renewal reminders (daily):
php -q /home/CPANELUSER/public_html/fiscalhub/cron/reminders.php

Set both jobs in cPanel > Cron Jobs. Use a daily schedule such as 15 7 * * * and 30 7 * * * respectively.
Replace CPANELUSER and the path with your cPanel account path. Add this in cPanel > Cron Jobs.

API ENDPOINTS
GET /api/v1/health
GET /api/v1/me
GET /api/v1/usage
GET /api/v1/subscriptions
POST /api/v1/provider/connect
GET /api/v1/provider/status
GET /api/v1/devices
POST /api/v1/devices
GET /api/v1/devices/{device}
GET /api/v1/devices/{device}/status
POST /api/v1/devices/{device}/ping
POST /api/v1/devices/{device}/open-day
POST /api/v1/devices/{device}/close-day
POST /api/v1/invoices
GET /api/v1/invoices/{invoice}
POST /api/v1/invoices/bulk


V1.3 BILLING OPERATIONS
- Admins can suspend, restore (only while unexpired) or cancel subscriptions.
- Payment verification is transaction-locked to reduce duplicate activation from concurrent clicks.
- Verified payments are recorded in a reconciliation trail with the admin actor.
- Renewal reminders are created in-app 7, 3 and 1 days before expiry.
- Configure the reminders cron separately from the expiry cron.
- Email and gateway automation are not enabled until SMTP settings and verified gateway adapters/merchant credentials are configured. Do not accept browser redirects as proof of payment.


FISCALHUB ZIMBABWE v1.4.0 - PAYMENT CHECKOUT
--------------------------------------------------
New in v1.4:
- Paynow hosted checkout initiation using merchant Integration ID/Key.
- SHA-512 hash verification for outbound and inbound Paynow messages.
- Signed callback event de-duplication and provider polling before activation.
- Payment checkout URL, poll URL and gateway status tracking.
- AES-256-GCM encrypted gateway credentials at rest.
- Gateway configuration screen for Paynow test/live credentials.

Upgrade:
1. Back up files and database.
2. Upload/extract v1.4 over the existing installation; preserve config.php.
3. Sign in as administrator and run /upgrade.php once.
4. Delete upgrade.php.
5. Confirm PHP cURL and OpenSSL extensions are enabled and HTTPS is active.
6. Configure Paynow TEST credentials in Settings. Test with low-value sandbox transactions before enabling LIVE.
7. Ensure the public callback URL /gateways/paynow_result.php is reachable over HTTPS.

Important:
- A browser return is NOT proof of payment. Only a signed callback plus provider poll showing Paid activates a subscription.
- Paynow production credentials and merchant approval are required.
- Pesepay and DiscHub adapters are not active in this release. No claim is made that they are connected.
- No customer card/mobile wallet credentials are stored by FiscalHub.
- Do not enable live mode until you have completed provider-side tests and verified settlement.

v1.5.0 — Customer onboarding and billing records
- Public customer signup, customer-only role, password hashing and CSRF checks.
- Email ownership is not verified; public signup is intended for controlled rollout until email verification and abuse throttling are added.
- Printable billing statements and paid receipts with tenant authorization. Browser Print / Save PDF. Not fiscal tax invoices.
- Subscription and payment creation are transactional.
- Upgrade: back up database and files, overwrite application files except config.php, sign in as admin, open upgrade.php, then delete upgrade.php.
- Paynow remains the only implemented payment gateway. Pesepay and DiscHub remain disabled pending verified integration.
