I’m trying to implement square webpayments using this page here web-payments-quickstart/card.html at main · square/web-payments-quickstart · GitHub
It all renders correctly but no matter how I try when I click ‘pay’ to submit it I get the error:
square.js:1 Unexpected token < in JSON at position 2
Any suggestions please ?
env.sandbox correctly configured with the sandbox access token? Also are you using
http://localhost:3000 when trying to make the payment?
Sorry I’m not setup as the entire web project with node etc I’m purely setup that one html page
Okay, then that would be the issue. A backend is required when submitting a payment request. If you inspect the page and check the Network tab you can confirm if you’re getting the token back from the form. If you are you’re on the right track and just need to setup the backend.
Yes I do get the token back but no matter what card I test with it’s payment failed ?
Great! That’s the expected response cause the example is trying to send the token to /payment which is in server.js. of the example. Once you get a backend running the payments will process.
Thanks so because I’m migrating from paymentform to web payment how do I capture that token ?
Currently it’s passed as form variable in payment form
Once you’ve got the token you can do the same and pass it as a variable to the
thank you, just one more thing please. How can I test with a UK card and postcode ? so the Zip changes to postcode for UK ?
6011 0000 0020 1016 value will show postcode in the form.
hi again, using that card number the postcode does show up but when submitting the payment it gives
Authorization error: ‘CARD_NOT_SUPPORTED’
would you have a visa card number with UK postcode please ?
Hmm, I was able to replicate and I’m reaching out to the team.
No need to worry now it’s all solved you can close the issue thanks