Square Payment Form Not Working In Sandbox

I have a production version of the Square Payment Form that is working just fine. I’ve replicated the working version and replaced the production location ID, application ID, and access token in the sqpaymentform.js and process-card files. I’m getting a “Request Not Authorized” error. I’ve verified the Sandbox credentials many times and still getting the error.

Hi @mcburrows welcome to the forums!

Did you update the JS domain to point to sandbox as well? The Javascript library source should be “https://js.squareupsandbox.com/v2/paymentform” instead of “https://js.squareup.com/v2/paymentform”.

Thank you. I missed that. I’m no longer getting the “Request Not Authorized” error. However, I am getting some error when processing the default test card info. How can I see what the error is?

I’m sorry but I’m very new to setting up a Square Payment Form integration. I need the code to display the plain language errors the form is generating.

If it’s when calling CreatePayment, then that is after the payment form and on your backend. What language/SDK are you using?

The language I’m using is PHP.

Are you using our SDK? If so you should just be able to do something like:

...
if ($apiResponse->isSuccess()) {
        // do whatever you want with success
    } else {
        // or print out the errors
        print_r($apiResponse->getErrors());
    }
...

I had assistance building it so I’m not sure if I’m using your SDK. Would that code go in the process-card.php file?

Here is the code I’m using to catch errors at the end of my process-card.php file:


catch (\SquareConnect\ApiException e) { _SESSION[‘payment_success’] = “no”;
echo “Exception when calling TransactionApi->charge:”;
header(“Location: index.php?urlId=” . base64_encode($clientId) . “&error=1#donate”);
var_dump($e->getResponseBody());
}

So this line var_dump($e->getResponseBody()); should be printing the error to your console. What is your application id? I can also look up in our logs if you need to find out what the error is.

Application ID:

sandbox-sq0idb-lENdxebZSsVFqra3AeY-yQ

What do you mean by “console”? Is there a place in the Developer area where I can view the errors?

I’m not seeing any errors on our side so I’m not sure what you’re running into. I see the card nonce for the test card being successfully created, although I never see it hit the CreatePayment endpoint. So, if an error is happening it’s after the card nonce is being created, but before the payment is being created (and this never hits the server so it’s not making it that far).

Console or terminal of whatever is running your PHP server. We currently do not have a place where you can see the errors in the Square Developer Dashboard, so it’s up to you to log the errors appropriately at this moment.