Skip to main content
All CollectionsWHMCS Upsell Module by Monarx
Adding Support for Custom Server Modules
Adding Support for Custom Server Modules
Pete Bishop avatar
Written by Pete Bishop
Updated over a month ago

The WHMCS Upsell Module provides a way for upsell-program users to configure the module for servers/control panels which are not supported out of the box.

To achieve this, you need to implement a very simple Module Information Provider. This provider will allow the module to retrieve important information that allows automated actions such as activation of Active Protection to occur.

How to Implement a Custom Information Provider

As an example, we'll add an Information Provider for a custom control panel that has a very easily defined schema. Your own modules may require a more complicated solution to retrieve data such as home directories.

First you need to name your class in the exact same manner that your server is named. For example, the cpanel server module requires an Information Provider named Cpanel.php (Note only the first character is capitalised).

We have a module named customserver so we would create Customserver.php with the following content:

<?php

namespace WHMCS\Module\Addon\Monarx\Service\Information;

use WHMCS\Module\Addon\Monarx\Exception\GetUsersNotSupportedException;
use WHMCS\Product\Server;
use WHMCS\Service\Addon;
use WHMCS\Service\Service;

class Customserver implements ModuleInformationProvider
{
/**
* @var Server
*/
private $server = null;

/**
* @var Service
*/
private $service = null;
/**
* @var Addon
*/
private $addon = null;

public function __construct(?Addon $model, Server $server)
{
if ($model) {
$model->load([
'productAddon',
'productAddon.moduleConfiguration',
'productAddon.customFields',
'service',
'service.product',
'service.product.customFields',
'client',
]);
$this->addon = $model;
$this->service = $this->addon->service;
}

$this->server = $server;
}

/**
* Returns the machine name of your server module.
* This is typically your servers filename, minus '.php'
*/
public function getWhmcsModuleName(): string
{
return 'customserver';
}

/**
* Return the home directory of the service provided.
* In this example, if the service domain is example.com,
* it would return /var/www/example.com/.
*
* This string should ALWAYS return with a trailing slash. (/)
*/
public function getHomeDirectory(): string
{
return '/var/www/' . $this->service->domain . '/';
}

/**
* Return an array of usernames for the "List Users" functionality.
* Some modules do not or cannot support this. In those cases, you can
* throw a GetUsersNotSupportedException to have the upsell module
* handle this gracefully.
*
* @throws GetUsersNotSupportedException
*/
public function getUsers(): array
{
throw new GetUsersNotSupportedException(
'This method is not currently supported by ' . __CLASS__
);

return [
'user1',
'user2',
];
}
}

This file should then be uploaded into the /modules/addons/monarx/lib/Service/Information directory as /modules/addons/monarx/lib/Service/Information/Customserver.php

The upsell module will automatically recognise your Custom Information Provider and use it whenever it is required. This is usually when an upsell is made for a Monarx product on a service that is utilising your custom server module.

Did this answer your question?