Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX SIO-3639 fix product upgrade/downgrade #68

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ Minimum required **PHP** version is 7.4.

Open the Account page in the SolusIO user-area to generate an API Token.

![Account](./modules/servers/solusiovps/docs/account.png)
![Account](./docs/account.png)

Configure SolusIO API access by adding a new server in WHMCS. Required fields are `Hostname` and `Password`.

`Hostname` must contain URL without https, e.g. "www.solus.io"

SolusIO API Token should be saved in the password field.

![Server](./modules/servers/solusiovps/docs/server.png)
![Server](./docs/server.png)

Create a server group in WHMCS and assign the server which was created on the previous step.

![Server group](./modules/servers/solusiovps/docs/server-group.png)
![Server group](./docs/server-group.png)

## Product Configuration

![Product](./modules/servers/solusiovps/docs/product.png)
![Product](./docs/product.png)

Create a product in WHMCS and select `SolusIO VPS` as the linked module and the server group you configured previous.

Expand All @@ -55,15 +55,15 @@ Select the `Plan`, `Default Location` and `Default Operating System` or `Applica

The module gives the ability to select a specific location on ordering of a product. This is done in the form of configurable options.

![Location](./modules/servers/solusiovps/docs/option-location.png)
![Location](./docs/option-location.png)

Create a configurable option named `Location`. Add options with the following convention: `locationId|locationName`. This will take priority over selected location in product module settings.

#### Operating Systems

The module gives the ability to select a specific operating system on ordering of a product. This is done in the form of configurable options.

![Operating System](./modules/servers/solusiovps/docs/option-os.png)
![Operating System](./docs/option-os.png)

Create a configurable option named `Operating System`. Add options with the following convention: `osId|osName`. This will take priority over selected operating system in product module settings.

Expand All @@ -77,6 +77,11 @@ Create a custom field named `SSH Key` and type `Text Area`.

Create corresponding product custom fields for applications with the same property names as defined in SolusIO.

## Product upgrade/downgrade

It is possible to use product Upgrade/Downgrade feature to change product type in admin area. To do this select `New Product/Service` with another SolusIO package in Upgrade/Downgrade dialog of admin area.
After order is complete this will trigger server resize action on SolusIO side.

## Other configurations

There are several options that can be configured within module config file `config.php`
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
8 changes: 3 additions & 5 deletions modules/servers/solusiovps/lib/WhmcsAPI/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class Product
{
public const MODULE_NAME = 'solusiovps';
public const CONFIG_OPTIONS_TYPE = 'configoptions';
public const PACKAGE_OPTIONS_TYPE = 'package';

public static function updateDomain(int $serviceId, string $domain): void
{
Expand All @@ -33,18 +33,16 @@ public static function upgrade(int $upgradeId): void
$upgrade = Upgrade::getById($upgradeId);
$serviceId = (int) $upgrade->relid;

if ($upgrade->type !== self::CONFIG_OPTIONS_TYPE) {
if ($upgrade->type !== self::PACKAGE_OPTIONS_TYPE) {
return;
}

list($newProductId, $paymentType) = explode(',', $upgrade->newvalue);

$newProduct = ProductModel::getById($newProductId);

if (empty($newProduct) || $newProduct->type !== self::MODULE_NAME) {
if (empty($newProduct) || $newProduct->servertype !== self::MODULE_NAME) {
return;
}

$newPlanId = (int) $newProduct->configoption1;
$hosting = Hosting::getByServiceId($serviceId);
$server = SolusServer::getByServiceId($serviceId);
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/WhmcsAPI/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public function testUpgrade(): void
$newPlanId = 25;
$this->upgrade->shouldReceive('getById')->with($this->upgradeId)
->andReturn((object)[
'type' => Product::CONFIG_OPTIONS_TYPE,
'type' => Product::PACKAGE_OPTIONS_TYPE,
'relid' => $this->relid,
'newvalue' => implode(',', [ (string)$this->newProductId, $this->paymentType ]),
]);

$productModel = Mockery::mock('overload:WHMCS\Module\Server\SolusIoVps\Database\Models\Product');
$productModel->shouldReceive('getById')->with($this->newProductId)
->andReturn((object)[
'type' => Product::MODULE_NAME,
'servertype' => Product::MODULE_NAME,
'configoption1' => $newPlanId,
]);

Expand Down Expand Up @@ -78,14 +78,14 @@ public function testUpgradeWrongModuleName(): void
{
$this->upgrade->shouldReceive('getById')->with($this->upgradeId)
->andReturn((object)[
'type' => Product::CONFIG_OPTIONS_TYPE,
'type' => Product::PACKAGE_OPTIONS_TYPE,
'relid' => $this->relid,
'newvalue' => implode(',', [ (string)$this->newProductId, $this->paymentType ]),
]);

$productModel = Mockery::mock('overload:WHMCS\Module\Server\SolusIoVps\Database\Models\Product');
$productModel->shouldReceive('getById')->with($this->newProductId)
->andReturn((object)[ 'type' => 'other module' ]);
->andReturn((object)[ 'servertype' => 'other module' ]);
self::assertNull(Product::upgrade($this->upgradeId));
}

Expand All @@ -94,7 +94,7 @@ public function testUpgradeNoProduct(): void

$this->upgrade->shouldReceive('getById')->with($this->upgradeId)
->andReturn((object)[
'type' => Product::CONFIG_OPTIONS_TYPE,
'type' => Product::PACKAGE_OPTIONS_TYPE,
'relid' => $this->relid,
'newvalue' => implode(',', [ (string)$this->newProductId, $this->paymentType ]),
]);
Expand Down