Walkthrough (Integrating Square in Website) Error

Howdy!

I’m going through the walkthrough for integrating square payments in a website.

Everything through step 1 works great. I see the CC input form, I enter the 4111 test CC and hit Pay, and I am alerted the nonce. It appears to work as expected.

I continue through the walkthrough by modifying server.js with my access token, and replacing the nonce alert with the backend server processing code provided by the walkthrough. And the trouble begins.

After I enter the 4111 CC and hit Pay, it errors saying the payment failed and to check the developer console. At first, I had the following:

VM149:1 GET https://****/process-payment/ 404 (Not Found)
(anonymous) @ VM149:1
cardNonceResponseReceived @ (index):90
mt._cardNonceResponseReceived @ paymentform:1
mt.receiveMessageCallback @ paymentform:1
(index):114 SyntaxError: Unexpected end of JSON input
at (index):105

So I tried to figure out why /process-payment wasn’t being found. I ended up adding a location block in nginx on my server to that directory, although I don’t think that should be necessary.

So my assumption is nodejs isn’t creating the endpoint /process-payment/ for some reason? And thus it appears to be invalid?

After I added a location block in nginx for it, it removed the error but I still get the “Unexpected end of JSON input” error. So I’m led to believe the nginx adjustment is likely not necessary, and something else is creating the problem.

To provide additional info, if I alert the JSON.stringify({ nonce: nonce }), it shows:

{“nonce”:“cnon:CBASEKBhcwr091WbBmMH2gho8-Q”}

So it appears the JSON is formatted correctly, even though it’s complaining about the unexpected end of JSON input?

Thanks for any help!

1 Like

Would it be possible to share your NGINX config for the node app?

It seems like it would be more likely not routing the request to the node app if you have copied everything over from the example.

Howdy, I have a very similar issue and I wonder if this was solved? @lancevs @wootmoot

I hadn’t looked at an NGINX config, so its hard to say what exactly isn’t working here.

My initial question would be to ask if the site is being served on the same domain and/or port as where the Node application is running?

I know the example has since been updated to work with the new Node SDK, but I just cloned and tested it, and it appears to be working.

If either of you could share some examples here, I’d be happy to take a look to help figure out why the 404 is happening.