Error when integrating new API

Fatal error : Uncaught TypeError: Argument 1 passed to Square\ApiHelper::appendUrlWithTemplateParameters() must be of the type string, null given, called in D:\vhosts\nac-issa.org\httpdocs\SquareEcom\vendor\square\square\src\SquareClient.php on line 304 and defined in D:\vhosts\nac-issa.org\httpdocs\SquareEcom\vendor\square\square\src\ApiHelper.php:47 Stack trace: #0 D:\vhosts\nac-issa.org\httpdocs\SquareEcom\vendor\square\square\src\SquareClient.php(304): Square\ApiHelper::appendUrlWithTemplateParameters() #1 D:\vhosts\nac-issa.org\httpdocs\SquareEcom\vendor\square\square\src\Apis\LocationsApi.php(176): Square\SquareClient->getBaseUri() #2 D:\vhosts\nac-issa.org\httpdocs\SquareEcom\utils\location-info.php(34): Square\Apis\LocationsApi->retrieveLocation() #3 D:\vhosts\nac-issa.org\httpdocs\SquareEcom\utils\location-info.php(60): LocationInfo->__construct() #4 D:\vhosts\nac-issa.org\httpdocs\SquareEcom\index.php(3): include(‘D:\vhosts\nac-i…’) #5 {main} thrown in D:\vhosts\nac-issa.org\httpdocs\SquareEcom\vendor\square\square\src\ApiHelper.php on line 47

I have verified that all information is correctly where it needs t

WHen I finally get the form to parse correctly from the php, I then get this error…

“square.js:1 Errorsq-payment: SyntaxError: Unexpected token ‘<’, “

”… is not valid JSON”

API logs shows a status 200 transaction so I am unsure as to why we are getting the JSON error, this needs to be addressed ASAP!!!

So the payment is being processed and your getting the JSON error? What example are you using and did you make any adjustments? :slightly_smiling_face:

The payment never hit the bank. I used the PHP example, this is a out of the box error. Changed nothing except .env values.

What’s your application ID? :slightly_smiling_face:

sq0idp-DcG4BcJ7DSyEW1-6eedgEw

I get that error so the page crashes and I never get the call back for good or failed transaction due to that invalid JSON error.

Are you testing in production or sandbox? Also can I do a test payment with our example in your sandbox? :slightly_smiling_face:

I am testing in production, I however cannot get a call back due to that invalid JSON error, I have tracked all through code and cannot figure out where the bad json is coming from.

Please see this…

https://nac-issa.org/squareecom2/

I am at the end of my development budget and am running out of ideas.

Yes please do your test

In vendor\square\square\src\SquareClient.php on line 290 to 306 does the function look like:

    /**
     * Get the base uri for a given server in the current environment
     *
     * @param  string $server Server name
     *
     * @return string         Base URI
     */
    public function getBaseUri(string $server = Server::DEFAULT_): string
    {
        return ApiHelper::appendUrlWithTemplateParameters(
            static::ENVIRONMENT_MAP[$this->environment][$server],
            [
                'custom_url' => $this->customUrl,
            ],
            false
        );
    }
/**
 * Get the base uri for a given server in the current environment
 *
 * @param  string $server Server name
 *
 * @return string         Base URI
 */
public function getBaseUri(string $server = Server::DEFAULT_): string
{
    return ApiHelper::appendUrlWithTemplateParameters(
        static::ENVIRONMENT_MAP[$this->environment][$server],
        [
            'custom_url' => $this->customUrl,
        ],
        false
    );
}

yes I believe its a match

If you try it using localhost does it work. :slightly_smiling_face:

Negative. Does not work localhost. I am on a windows server fyi. If that helps. If you can just figure out where that JSON error is coming from I could perhaps bypass it or fix the error.

I believe it’s on the CreatePayment request. That error means the request body isn’t in valid JSON which is why its failing and not making it to Square. I see the ListLocations call in your API logs so we know that calls are succeeding. Its just the POST to CreatePayment isn’t valid JSON. :slightly_smiling_face:

What script do I address that in. How can I correct that.

It’s here where CreatePayment is being called. Somehow the request body that’s being sent to Square is malformed and isn’t valid JSON which is causing the error. If you print it you can check the JSON. Or json_encode it again prior to sending it to Square. :slightly_smiling_face:

print what? What variable should I be trying to print or convert back into json?