Displaying Balances
WHASOLS adds the ability to display payment gateway balances directly in the WHASOLS Admin Area. By default, these balances are available for Stripe and PayPal Basic at
Billing > Balances.
By default, balance information will display in the Admin Area for admins with the Full Administrator role. To allow other admin roles to see balance information, enable View Gateway Balances for the desired role.
You can display the balances for other payment gateways through payment gateway module
_Balance function.
Example
Successful implementations of this functionality within a payment gateway module should resemble the example below.
Connecting To Gateways
Before you can retrieve balance information, connect to the desired gateway. For example:
<?php
function yourmodulename_Balance($arg = [])
{
// Gateway Parameters
$gateway_id= $arg['gateway']['id'];
$title= $arg['gateway']['title'];
//gateway parameter have gateway configuration parameters
$balanceInfo = [];
// Connect to gateway to retrieve balance information.
$postfields = [
'account'=>$arg['gateway']['apikey'],
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/api/balance');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
if(empty($response)) return ["status"=>"error","message"=>"Your Gateway error message here if exist"];
$balanceData = json_decode($response, true);
// Add Balance objects as many times as needed for each gateway
// balance type (most gateways will only have one).
foreach ($balanceData['available'] as $availableData)
{
$currencyCode = strtoupper($availableData['currency']);
$amount = ($availableData['amount'] / 100);
$balanceInfo[$currencyCode]["available"] = $amount;
}
foreach ($balanceData['pending'] as $pendingData)
{
$currencyCode = strtoupper($pendingData['currency']);
$amount = ($pendingData['amount'] / 100);
$balanceInfo[$currencyCode]["pending"] = $amount;
}
return ["status"=>"success","message"=>"Your Gateway message here if exist","response"=>$balanceInfo];
}
Required Permissions:By default, balance information will display in the Admin Area for admins with the Full Administrator role. To allow other admin roles to see balance information, enable View Gateway Balances for the desired role.