Skip to content

Commit

Permalink
fix: resolve issues retrieving balance
Browse files Browse the repository at this point in the history
feat: add error message when balance checking fails
  • Loading branch information
Sn0wCrack committed Jan 8, 2024
1 parent 53d7d6f commit 95d3925
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
15 changes: 10 additions & 5 deletions modules/widgets/synergywholesale_balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
]);
Expand All @@ -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);
Expand Down Expand Up @@ -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 .= '<div style="text-align: center; color: green; font-weight: bold; font-size: 18px; padding: 16px;">Balance: $' . number_format($balance, 2) . '</div>';
} else {
$content .= '<div style="text-align: center; color: red; font-weight: bold; font-size: 18px; padding: 16px;">An error ocurred retrieving account balance: ' . $apiResult->errorMessage ?? 'An unknown error occurred' . '</div>';
}

return $content;
Expand Down

0 comments on commit 95d3925

Please sign in to comment.