Php_payment example - stuck on ApiHelper error

I’m migrating to Web Payments SDK and trying to learn how by running the example found here: connect-api-examples/connect-examples/v2/php_payment at master · square/connect-api-examples · GitHub

I uploaded the code, ran the composer commands, made a .env file with our sandbox credentials in it, etc. In the error message below, in stack trace #2, it looks like the location is being retrieved correctly - i don’t understand what the problem could be. Has anyone seen this before? How did you fix it?

[12-Dec-2022 22:06:49 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to Square\ApiHelper::appendUrlWithTemplateParameters() must be of the type string, null given, called in /home/<my_account>/public_html/php_payment/vendor/square/square/src/SquareClient.php on line 304 and defined in /home/<my_account>/public_html/php_payment/vendor/square/square/src/ApiHelper.php:47
Stack trace:
#0 /home/<my_account>/public_html/php_payment/vendor/square/square/src/SquareClient.php(304): Square\ApiHelper::appendUrlWithTemplateParameters(NULL, Array, false)
#1 /home/<my_account>/public_html/php_payment/vendor/square/square/src/Apis/LocationsApi.php(176): Square\SquareClient->getBaseUri()
#2 /home/<my_account>/public_html/php_payment/utils/location-info.php(31): Square\Apis\LocationsApi->retrieveLocation(‘DAW…’)
#3 /home/<my_account>/public_html/php_payment/utils/location-info.php(50): LocationInfo->__construct()
#4 /home/<my_account>/public_html/php_payment/index.php(10): include(‘/home/<my_account>/…’)
#5 {main}
thrown in /home/<my_account>/public_html/php_payment/vendor/square/square/src/ApiHelper.php on line 47

Hmm, it should work as long as you followed all the setup steps in the README.md. Can you confirm that you did everything? :slightly_smiling_face:

What version of PHP are you running? It requires 7.2+ which I think ‘composer update’ enforces?

we have PHP Version 7.4.33 on a linux server.

Still a mystery - i did a local installation, ran the local php dev server, and it worked. just uploaded all of that to our webserver, wiping out my original experiment, and now it works on the server, too.

could have been some dotenv weirdness? i don’t know.

Wow! Glad to hear you got it to work. :slightly_smiling_face: