WHMCS-VIMEXX

Why this post?

I ran into problems while automating domain registration using WHMCS and my registrar VIMEXX. VIMEXX does provide a registrar module but it does not work out of the box with my version of WHMCS. I was able to get it to work and thought it would a good idea to share my experience along with a updated version of the module.

About WHMCS

WHMCS isĀ an all-in-one client management, billing & support solution for online businesses. Handling everything from signup to termination, WHMCS is a powerful automation & support tool.

About the problem

The module is fairly straightforward to install and configure but in its current form is unable to communicate successfully with the VIMEXX API as any attempt results in the following error: “api.invalid_version”. The module log shows the data being sent and the response:

Array
(
    [requesttype] => POST
    [url] => https://api.vimexx.nl/apitest/v1/whmcs/domain/register
    [postdata] => Array
        (
            [body] => Array
                (
                    [sld] => example
                    [tld] => nl
                )

            [version] => 8.5.1-release.1
        )

    [result] => {"message":"api.invalid_version","result":false,"data":[]}
    [httpcode] => 200
)

From the logs we conclude that WHMCS version “8.5.1-release.1” is not supported by VIMEXX at this moment and we will have to find a version that is. According to the documentation provided the last supported version at the moment is: “8.4.0-release.1”. So changing the VersionWhmcs parameter in the registrar module would solve our problem right? Sadly, it seems there is no such thing as a free lunch as the module ignores our change and uses the previous version resulting in the same error. At this point it seems there is a problem with the module itself so the next step is to look at the code.

Our failing code resides in “vimexx.php” and can be found below:

/**
 * Register a new domain
 *
 * @param $params
 * @return array
 */
function vimexx_RegisterDomain($params)
{
    $clientId   = $params['ClientID'];
    $clientKey  = $params['ClientKey'];
    $username   = $params['Username'];
    $password   = $params['Password'];
    $apiUrl     = $params['ApiUrl'];
    $endpoint   = $params['Site-version'];
    $testmode   = $params['TestMode'];
    $sld        = $params['sld'];
    $tld        = $params['tld'];

    $vimexx     = new Vimexx_API();
    $vimexx->setApi_login($clientId, $clientKey, $username, $password, $apiUrl, $endpoint);
    $vimexx->setApi_testmodus($testmode);

    $response = $vimexx->request('POST', '/whmcs/domain/register', [
        'sld' => $sld,
        'tld' => $tld
    ], $params['whmcsVersion']);

    if(!$response['result']) {
        $message = $response['message'];

        if (is_array($response['message'])) {
            $message = implode("\r\n", $response['message']);
        }

        return array('error' => $message);
    } else {
        return array(
            'success' => true,
        );
    }
}

Analysing this piece of code shows that it first declares some variables that in turn get their data from an array called “params”. The version number gets used on line 115 but returns “8.5.1-release.1” despite setting it to “8.4.0-release.1” in the module config indicating that something is not working as expected. Next up is the code that defines the “params” array:

/**
 * Set vimexx module config settings
 *
 * @return array
 */
function vimexx_getConfigArray($params)
{
    return array(
        'ClientID' => array(
            'Type' => 'text',
            'Size' => '25',
            'Default' => '',
            'Description' => 'Enter your client ID',
        ),
        'ClientKey' => array(
            'Type' => 'text',
            'Size' => '100',
            'Default' => '',
            'Description' => 'Enter your key',
        ),
        'Username' => array(
            'Type' => 'text',
            'Size' => '100',
            'Default' => '',
            'Description' => 'Enter your username',
        ),
        'Password' => array(
            'Type' => 'password',
            'Size' => '100',
            'Default' => '',
            'Description' => 'Enter your password ',
        ),
        'ApiUrl' => array(
            'Type' => 'text',
            'Size' => '100',
            'Default' => '',
            'Description' => 'API URL',
        ),
        'Site-version' => array(
            'Type' => 'dropdown',
            'Options' => array(
                '.nl' => 'NL',
            ),
            'Description' => 'Choose which Vimexx API you want to connect to',
        ),
        'TestMode' => array(
            'Type' => 'dropdown',
            'Options' => array(
                'true' => 'On',
                'false' => 'Off',
            ),
            'Description' => 'Choose one',
        ),
        'VersionWhmcs' => array(
            'Type' => 'text',
            'Size' => '100',
            'Default' => $params['whmcsVersion'],
            'Description' => '<b>NIET AANPASSEN!</b>',
        ),
    );
}

Of interest here is the last part of the array concerning “VersionWhmcs”. As shown the default value is “$params[‘whmcsVersion’]” or “8.5.1-release.1” which is expected and also immediately explains why our input is ignored. Examining the domain register code from before shows that it does not take the version from the module configuration but from somewhere else.

    $response = $vimexx->request('POST', '/whmcs/domain/transfer', [
        'sld'   => $sld,
        'tld'   => $tld,
        'token' => $token
    ], $params['whmcsVersion']);

Changing “$params[‘whmcsVersion’]” to “$params[‘VersionWhmcs’]” will ensure that the version configured in the module is used from now on.

And that is it! An updated version of the VIMEXX module can be found here: https://github.com/tomvanveen/WHMCS-VIMEXX

References:

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.