I’m trying to migrate a payment form from the Square Payments Form to the new method as advised.
I’m working off the example at:
However, when adding those to my webserver, pulling in all the relevant vendor libraries hitting index.php, I simply get the following error:
Fatal error: Uncaught TypeError: Argument 1 passed to Square\ApiHelper::appendUrlWithTemplateParameters() must be of the type string, null given, called in /home/customer/www/[mydomain.com]/public_html/php_payment/vendor/square/square/src/SquareClient.php on line 302 and defined in /home/customer/www/[mydomain.com]/public_html/php_payment/vendor/square/square/src/ApiHelper.php:25
My .env credentials are correct (sandbox currently)
Not a hardcore developer, so need any help I can get with this, as the current payment form (which I have working happily) is being killed off in a few months.
According to the error an argument was pass to the ApiHelper when it should have been a string in your SquareClient.php. The line it references is attempting to pull the server_url for the environment, but given that’s an invalid environment you’re passing, it will fail and return null. You’ll want to do this instead:
If you print the client do you get the correct values? Also do you have the link to the file utils/location-info.php that you say is provided by Square? I don’t see it in the SDK or examples.
I totally missed that. You’re right. I haven’t been able to replicate the error. Did you make any other adjustments to the sample prior to getting this error and was it working as expected prior?
Fatal error: Uncaught TypeError: Argument 1 passed to Square\ApiHelper::appendUrlWithTemplateParameters() must be of the type string, null given, called in /Users/ben/Desktop/Square Update/connect-api-examples-master/connect-examples/v2/php_payment/vendor/square/square/src/SquareClient.php on line 302 and defined in /Users/ben/Desktop/Square Update/connect-api-examples-master/connect-examples/v2/php_payment/vendor/square/square/src/ApiHelper.php:25
Stack trace:
#0 /Users/ben/Desktop/Square Update/connect-api-examples-master/connect-examples/v2/php_payment/vendor/square/square/src/SquareClient.php(302): Square\ApiHelper::appendUrlWithTemplateParameters(NULL, Array, false)
#1 /Users/ben/Desktop/Square Update/connect-api-examples-master/connect-examples/v2/php_payment/vendor/square/square/src/Apis/LocationsApi.php(181): Square\SquareClient->getBaseUri()
#2 /Users/ben/Desktop/Square Update/connect-api-examples-master/connect-examples/v2/php_payment/utils/location-info.php(37): Square\Apis\LocationsApi->retrieveLocation('LPMGH....'.... in /Users/ben/Desktop/Square Update/connect-api-examples-master/connect-examples/v2/php_payment/vendor/square/square/src/ApiHelper.php on line 25
Glad to hear you got it to work. Since the amount is hard coded on the backend you can pass it in as a variable since the amount charged will be different for each customer. If your passing it to the backend from the form your customers putting the card information in you can include it in the POST to the payment request with the source_id.
the issue I’m having is that the data doesn’t seem to be reaching the process-payment.php page.
I am attempting to access the field via POST (this doesn’t work as it’s the result of a javascript ‘fetch’ action), and by the $data->amount option (where $data is the contents of the file_get_contents(php://input) that is used to retrieve the token), i.e. this part of Square’s sample code:
(‘token’ is arriving correctly, but ‘amount’ doesn’t seem to exist)
How do I access the other form variables (along with the amount, I will need address, etc for SCA once I finally get the basics working)
Totally lost as to how to access the form fields, as it seems the sample code is only submitting the nested form in the iframe generated by square.js, ignoring the parent form fields.
Hello can you help me pass the environment please, i got error : “TypeError: Argument 1 passed to Square\BearerAuthManager::__construct() must be of the type string, bool given, called in C:\Users\User\Documents\projet-laravel\divineTransportation\vendor\square\square\src\SquareClient.php on line 121 in file C:\Users\User\Documents\projet-laravel\divineTransportation\vendor\square\square\src\BearerAuthManager.php on line 21”