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);
}
I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:
Additional Documentation
Using the Square PHP SDK
Make your First API Call
Using the REST API
If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.
The error you’re encountering is because there’s no getBalanceApi()
method available in the Square PHP SDK. The Square API does not currently provide a direct way to retrieve the balance of a client or customer.
The code you’ve written seems to be trying to access a non-existent BalanceApi
class. Square’s PHP SDK currently includes APIs such as CustomersApi
, OrdersApi
, PaymentsApi
, etc., but there’s no BalanceApi
.
If you’re trying to retrieve transaction history or payment details, you might want to use the PaymentsApi
or OrdersApi
instead. However, please note that these won’t provide a “balance” in the traditional sense, but rather a history of transactions or orders.
This answer was reviewed by @Bryan-Square.
Thank you for the reply! Maybe i should clarify my question. So all im trying to do is show the clinet how much is avilable to transfer to the bank account if the client wants to transfer i want to give the option to do so using a button.
See image that show the function what we have on the square app!Im trying to show the same option using the PHP/POS front end!
Processing: image.png…
Right, at this time the ability to get the available balance that will be transferred to the account by API isn’t currently available.
ohh ok! So another way to know this amount is if we add up all the transactions between a given date using the API call , I would think to do that way!
But can we use the API to do instant transfer IF enabled using an API button?
At this time there isn’t a way to accurately report the available balance with our APIs. This is because the default close of day for ACH payments is 5pm PST. Any payment after will go in the next days payout. Sellers can adjust this which may can change balance based on close of day. Additionally, there isn’t a way to get a sellers close of day with our APIs to try an calculate the sales for a payout balance.
Lastly, the ability to initiate a payout with our APIs isn’t currently possible. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team.