From 95d3925cc6cf4a87ac0c0ba7b7ee9acf14ecb912 Mon Sep 17 00:00:00 2001 From: Sn0wCrack <442287+Sn0wCrack@users.noreply.github.com> Date: Tue, 9 Jan 2024 10:43:36 +1100 Subject: [PATCH] fix: resolve issues retrieving balance feat: add error message when balance checking fails --- .../synergywholesale_balance.php | 2 +- modules/widgets/synergywholesale_balance.php | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/addons/synergywholesale_balance/synergywholesale_balance.php b/modules/addons/synergywholesale_balance/synergywholesale_balance.php index 3a850a2..8101408 100755 --- a/modules/addons/synergywholesale_balance/synergywholesale_balance.php +++ b/modules/addons/synergywholesale_balance/synergywholesale_balance.php @@ -7,7 +7,7 @@ function synergywholesale_balance_config() return [ 'name' => 'Synergy Wholesale Account Balance', 'description' => 'View your Synergy Wholesale account balance via WHMCS', - 'version' > SW_ACCOUNT_BALANCE_WIDGET_VERSION, + 'version' => SW_ACCOUNT_BALANCE_WIDGET_VERSION, 'author' => 'Synergy Wholesale', 'fields' => [ 'api_key' => ['Type' => 'text', 'Size' => '60', 'FriendlyName' => 'API Key'], diff --git a/modules/widgets/synergywholesale_balance.php b/modules/widgets/synergywholesale_balance.php index 969675c..9555af5 100755 --- a/modules/widgets/synergywholesale_balance.php +++ b/modules/widgets/synergywholesale_balance.php @@ -2,7 +2,7 @@ use WHMCS\Database\Capsule as DB; -define('SW_ACCOUNT_BALANCE_API_ENDPOINT', '{{API}}'); +define('SW_ACCOUNT_BALANCE_API_ENDPOINT', 'https://{{API}}'); define('SW_ACCOUNT_BALANCE_WIDGET_NAME', 'synergywholesale_balance'); class SynergyWholesaleAccountBalanceWidgetAPI @@ -14,7 +14,7 @@ class SynergyWholesaleAccountBalanceWidgetAPI public function __construct($resellerID, $apiKey) { $this->soap = new SoapClient(null, [ - 'location' => SW_ACCOUNT_BALANCE_API_ENDPOINT, + 'location' => SW_ACCOUNT_BALANCE_API_ENDPOINT . '/?wsdl', 'uri' => '', 'trace' => true ]); @@ -25,8 +25,8 @@ public function __construct($resellerID, $apiKey) public function request($command, $params = []) { - $params['resellerID'] = $this->apiKey; - $params['apiKey'] = $this->resellerID; + $params['resellerID'] = $this->resellerID; + $params['apiKey'] = $this->apiKey; try { $response = $this->soap->$command($params); @@ -87,8 +87,13 @@ public function generateOutput($result) $api = new SynergyWholesaleAccountBalanceWidgetAPI($result['reseller_id'], $result['api_key']); $apiResult = $api->balanceQuery(); - if ($balance = $apiResult->balance) { + + $balance = $apiResult->balance ?? null; + + if (!is_null($balance)) { $content .= '
Balance: $' . number_format($balance, 2) . '
'; + } else { + $content .= '
An error ocurred retrieving account balance: ' . $apiResult->errorMessage ?? 'An unknown error occurred' . '
'; } return $content;