Documentation

FusionPBX AutoSuspend Testing Guide

Complete guide for testing the AutoSuspend script. Follow the proper sequence to avoid stuck states.

FusionPBX AutoSuspend Testing Guide

Overview

The FusionPBX AutoSuspend script automatically suspends/unsuspends client services based on their credit balance. It tracks suspension state in the mod_fusionpbx_suspend_account database table to prevent duplicate operations.

Important: The script uses state tracking to determine if a service is already suspended. Testing must follow the proper sequence to keep the database state synchronized with the actual gateway status.

How It Works

  1. Suspension Trigger: When client credit ≤ $0 or outstanding invoices exceed credit
  2. State Tracking: Script records suspend = 'yes' in mod_fusionpbx_suspend_account
  3. Skip Logic: If already marked as suspended, script skips (prevents duplicate API calls)
  4. Unsuspension: When credit is restored, script sets suspend = 'no' and re-enables gateway

⚠️ Critical Testing Rules

✅ DO ❌ DON'T
Always complete the full suspend → unsuspend cycle Manually enable gateway in FusionPBX UI during testing
Use the autosuspend script for all state changes Directly modify mod_fusionpbx_suspend_account table during testing
Run in browser debug mode first to verify logic Skip the unsuspend step before testing suspend again
Check debug output for "Already suspended - skipping" Assume the script failed without checking state table
Verify gateway status directly in FusionPBX tenant Use ictVoIPBilling Client Services / Gateways to verify

Where to Verify Gateway Status

✅ CORRECT: Check the gateway status directly in the FusionPBX tenant UI:
  • Login to FusionPBX → Gateways → Check if gateway is Enabled/Disabled
  • Check Sofia Status to confirm gateway is running/stopped
❌ INCORRECT: Do NOT use ictVoIPBilling → Client Services → Gateways to verify:
  • This view is not live - it shows cached/synced data
  • Must be manually resynced to reflect current FusionPBX state
  • Will show stale data if gateway was changed by autosuspend

Proper Testing Sequence

Test 1: Initial Suspension

Step Action Expected Result
1 Set test client credit to $0.00 Credit balance shows $0.00 in WHMCS
2 Run autosuspend in browser: https://yourwhmcs.com/modules/servers/fusionpbx/autosuspend.php Debug output shows "SUSPENSION TRIGGERED"
3 Verify debug output Shows "SERVICE SUSPENDED SUCCESSFULLY - Gateway disabled"
4 Check FusionPBX Gateway shows as Disabled
5 Verify Sofia status Gateway should be stopped (not just disabled)

Test 2: Unsuspension

Step Action Expected Result
1 Add credit to test client (e.g., $50.00) Credit balance shows $50.00 in WHMCS
2 Run autosuspend again Debug output shows "Service was previously suspended, attempting to unsuspend..."
3 Verify debug output Shows "SERVICE UNSUSPENDED SUCCESSFULLY - Gateway re-enabled"
4 Check FusionPBX Gateway shows as Enabled
5 Verify Sofia status Gateway should be running

Test 3: Re-Suspension (Full Cycle Complete)

Step Action Expected Result
1 Set test client credit back to $0.00 Credit balance shows $0.00
2 Run autosuspend Debug output shows "SUSPENSION TRIGGERED" (not "Already suspended")
3 Verify suspension works Gateway disabled and stopped

Troubleshooting: Stuck State

Symptoms

  • Client has $0 credit but script shows "Already suspended - skipping".
  • Gateway is actually enabled in FusionPBX but script won't suspend.

Cause

The mod_fusionpbx_suspend_account table has suspend = 'yes' but the gateway was manually re-enabled outside of the autosuspend script.

Resolution

1. Check current state:

SELECT * FROM mod_fusionpbx_suspend_account
WHERE userid = [CLIENT_ID];

2. If suspend = 'yes' but gateway is enabled, reset the state:

UPDATE mod_fusionpbx_suspend_account
SET suspend = 'no', updated_at = NOW()
WHERE userid = [CLIENT_ID] AND serviceid = [SERVICE_ID];

3. Re-run autosuspend:

https://yourwhmcs.com/modules/servers/fusionpbx/autosuspend.php

CRON Setup

Once testing is complete, configure the CRON job:

*/5 * * * * TZ=America/Toronto curl -s "https://yourwhmcs.com/modules/servers/fusionpbx/autosuspend.php?runfrom=cron" >/dev/null 2>&1

Parameters:

  • ?runfrom=cron - Suppresses HTML output, returns plain text summary
  • Recommended interval: Every 5 minutes

Debug Mode vs CRON Mode

Mode URL Output
Browser (Debug) /autosuspend.php Full HTML with detailed status for each client
CRON (Silent) /autosuspend.php?runfrom=cron Plain text summary only
Always test in browser debug mode first to verify the script logic before enabling CRON.

Database Tables

mod_fusionpbx_suspend_account

Column Type Description
id int Primary key
userid int WHMCS client ID
serviceid int WHMCS service/hosting ID
domain_name varchar FusionPBX tenant domain
suspend varchar Current state: 'yes' or 'no'
created_at timestamp First suspension time
updated_at timestamp Last state change

Script Version: 1.1.0

Author: ictVoIP Canada