/** * Changes the WebsitePanel user hosting package * * @param array $params WHMCS parameters * @throws Exception * @return string */ function websitepanel_ChangePackage($params) { // WHMCS server parameters & package parameters $serverUsername = $params['serverusername']; $serverPassword = $params['serverpassword']; $serverPort = $params['configoption6']; $serverHost = empty($params['serverhostname']) ? $params['serverip'] : $params['serverhostname']; $serverSecure = $params['serversecure']; $username = $params['username']; $clientsDetails = $params['clientsdetails']; $userId = $clientsDetails['userid']; $serviceId = $params['serviceid']; // WebsitePanel API parameters $planId = $params['configoption4']; $packageName = $params['configoption1']; try { // Create the WebsitePanel Enterprise Server Client object instance $wsp = new websitepanel_EnterpriseServer($serverUsername, $serverPassword, $serverHost, $serverPort, $serverSecure); // Get the user's details from WebsitePanel - We need the userid $user = $wsp->getUserByUsername($username); if (empty($user)) { throw new Exception("User {$username} does not exist - Cannot change package for unknown user"); } // Get the user's package details from WebsitePanel - We need the PackageId $package = $wsp->getUserPackages($user['UserId']); // Update the user's WebsitePanel package $result = $wsp->updatePackageLiteral($package['PackageId'], $package['StatusId'], $planId, $package['PurchaseDate'], $packageName, $package['PackageComments']); if ($result < 0) { // Something went wrong throw new Exception('Fault: ' . websitepanel_EnterpriseServer::getFriendlyError($result), $result); } // Log the module call websitepanel_logModuleCall(__FUNCTION__, $params, $result); // Notify success return 'success'; } catch (Exception $e) { // Error message to log / return $errorMessage = "ChangePackage Fault: (Code: {$e->getCode()}, Message: {$e->getMessage()}, Service ID: {$serviceId})"; // Log to WHMCS logactivity($errorMessage, $userId); // Log the module call websitepanel_logModuleCall(__FUNCTION__, $params, $e->getMessage()); // Notify failure - Houston we have a problem! return $errorMessage; } }