HI, im trying to retrive the curent balance of the client using the $client->getBalanceApi() in PHP
but I’m getting this error
Fatal error : Uncaught Error: Call to undefined method Square\Apis\TerminalApi::getBalanceApi() in /home/…
why is that ? see my code
$client = new SquareClient([
‘accessToken’ => ‘******************’,
‘environment’ => ‘production’, // or ‘production’
]);
$balanceApi = $client->getBalanceApi(); // Getting the Balance API
$response = $balanceApi->listBalances(); // Retrieve the balance details
if ($response->isSuccess()) {
$balances = $response->getResult()->getBalances(); // Get balances
foreach ($balances as $balance) {
echo "Balance Type: " . $balance->getType() . “\n”;
echo "Currency: " . $balance->getCurrency() . “\n”;
$available = $balance->getAvailable();
echo "Available Balance: " . ($available->getAmount() / 100) . " " . $balance->getCurrency() . "\n";
}
} else {
echo "Error retrieving balance: ";
echo print_r($response->getErrors(), true);
}
2 posts - 2 participants