Con le API di WHMCS possiamo ottenere i servizi attivi di un cliente.

Possiamo implementare la seguente soluzione.


function get_client_active_services($client_id) {
    $services = [];

    if(!ctype_digit($client_id) || !filter_var($client_id, FILTER_VALIDATE_INT)) {
        return $services;
    }
    $command = 'GetClientsProducts';
    $data = [
        'clientid' => $client_id,
        'limitnum' => 10000,
        'stats' => false
    ];
    $results = localAPI($command, $data);
    if($results['result'] !== 'success') {
        return $services;
    }
    $client_services = $results['products']['product'];
    if(count($client_services) > 0) {
        foreach($client_services as $client_service) {
            if($client_service['status'] === 'Active') {
                $services[] = $client_service;
            }
        }
    }
    return $services;
}