Title is pretty self explanatory. Installed the PHP SDK via composer, using the sample code provided from Square’s own github here: connect-api-examples/connect-examples/v2/php_payment/process-payment.php at master · square/connect-api-examples · GitHub
Whenever I try to test my code, I run into
PHP Fatal error: Uncaught Error: Call to undefined method Square\SquareClient::getPaymentsApi()
Here’s the relevant code in question
$square_client = new SquareClient(
token: $_ENV['SQUARE_ACCESS_TOKEN'],
options: ['baseUrl' => Environments::Sandbox->value // Used by default
]
);
$payments_api = $square_client->getPaymentsApi();
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
Cash App Payments
https://developer.squareup.com/docs/oauth-api/walkthrough
https://developer.squareup.com/docs/payments-overview
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.
I have literally cloned the SDK, and done a case-insensitive search across the entire tree for “getPaymentsApi” and the only mention of it is in…README.md.
x@MacStudio connect-php-sdk % grep -i -r getPaymentsApi ./*
./README.md:$payments_api = $api_client->getPaymentsApi();
How is this possible? Am I the only one on the planet attempting to use the PHP SDK?
The error you’re encountering, “PHP Fatal error: Uncaught Error: Call to undefined method Square\SquareClient::getPaymentsApi()”, suggests that the method getPaymentsApi() is not available in the version of the Square PHP SDK you are using.
This could be due to a few reasons:
-
SDK Version: Ensure that you are using the latest version of the Square PHP SDK. The latest version as per the documentation is 43.0.1.20250716. If you are using an older version, it might not have the getPaymentsApi() method.
-
Namespace and Class Usage: Double-check that you are correctly using the namespaces and classes as per the latest SDK documentation. The SquareClient class should have the getPaymentsApi() method if the SDK is correctly installed and up-to-date.
-
Installation Issues: Verify that the SDK is properly installed via Composer. You can try removing the existing installation and reinstalling it to ensure all files are correctly set up.
-
Documentation and Examples: Make sure you are following the latest examples and documentation from Square’s official resources. The GitHub link you provided might be outdated or not aligned with the latest SDK changes.
If you have verified all the above and the issue persists, it might be worth checking the release notes or migration guides provided by Square to see if there have been any changes to the method names or class structures in recent updates.
This answer was reviewed by @Bryan-Square.
Ah, AI. And @Bryan-Square …this is riddled with inaccuracies.
First off, I grabbed the very latest version of your SDK from composer, and confirmed with github. The latest version is 43.0.2.20250820, not 43.0.1.20250716.
So, rather than dive in deeper, I’d like to at least see some ack that the doc is WAY out of sync with the actual code.
What errors are you getting? 
^ that. it does not exist in the latest version of your php SDK on your github.
Your code quote seems…blank?
Hmm, I’m not able to post my example. 
Woof guys. Not a great look.
If you try this does it work?
<?php
require_once 'vendor/autoload.php';
use Square\SquareClient;
use Square\Environment;
use Square\Exceptions\ApiException;
// Configuration
$access_token = 'ACCESS_TOKEN'; // Replace with your actual access token
$environment = Environment::PRODUCTION; // Use Environment::PRODUCTION for live
$payment_id = 'PAYMENT_ID'; // Replace with the actual payment ID
try {
// Initialize the Square client
$client = new SquareClient([
'accessToken' => $access_token,
'environment' => $environment
]);
// Get the Payments API instance
$paymentsApi = $client->getPaymentsApi();
// Call getPayment
$response = $paymentsApi->getPayment($payment_id);
if ($response->isSuccess()) {
$payment = $response->getResult()->getPayment();
echo "Payment retrieved successfully!\n";
echo "Payment ID: " . $payment->getId() . "\n";
echo "Amount: " . $payment->getAmountMoney()->getAmount() . " " . $payment->getAmountMoney()->getCurrency() . "\n";
echo "Status: " . $payment->getStatus() . "\n";
echo "Created At: " . $payment->getCreatedAt() . "\n";
// Print the full payment object as JSON for detailed inspection
echo "\nFull Payment Object:\n";
echo json_encode($payment, JSON_PRETTY_PRINT) . "\n";
} else {
echo "Error retrieving payment:\n";
$errors = $response->getErrors();
foreach ($errors as $error) {
echo "- " . $error->getCategory() . ": " . $error->getDetail() . "\n";
}
}
} catch (ApiException $e) {
echo "API Exception occurred:\n";
echo "Response Code: " . $e->getResponseCode() . "\n";
echo "Response Body: " . $e->getResponseBody() . "\n";
} catch (Exception $e) {
echo "General Exception occurred: " . $e->getMessage() . "\n";
}
?>```