This is another instance of how AI tools like ChatGPT can help quickly debug issues and increase developer productivity. It also shows how clearly instructed and well-articulated prompts can help in quickly resolving coding problems. In this case, I turned to ChatGPT for an uncommon problem related to an Payment Gateway SDK published by Square, a financial services platform.
I was experimenting with the Square Web Payment SDK available on GitHub. After downloading the SDK, I completed the basic configuration in the .env
file using NodeJS, including setting the ACCESS_TOKEN
. When I executed the code for card_payment.html
on port 3000, I encountered an authentication error. This issue puzzled me because running the code seemed straightforward, and I expected it to work without any issues.
Determined to resolve the problem, I, being a novice NodeJS developer, spent almost an hour troubleshooting the issue on my own. I double-checked the configuration settings, server.js file, ensured that the APPLICATION_ID
and LOCATION_ID
were correctly set to my project, and verified that the SQUARE_ACCESS_TOKEN
was accurately updated in the .env
file. Despite these efforts, I continued to receive the "Payment failed" error. The detailed error message in the console indicated an AUTHENTICATION_ERROR
with the code UNAUTHORIZED
, suggesting that the request could not be authorized.
Feeling perplexed, I turned to ChatGPT for assistance. I explained my issue to ChatGPT using the following prompt:
Prompt: I am using the SQUARE web-payments-quickstart SDK available on this GitHub URL "github.com/square/web-payments-quickstart.git". In the SDK, there is an example code for different modes of payments available in this folder "web-payments-quickstart/public/examples". I am using card-payment.html to make the card payment. I have changed the APPLICATION_ID and LOCATION_ID in my project. I have also created a .env file and updated "SQUARE_ACCESS_TOKEN" in the file. However, when I am running "card-payment.html" on port 3000, I am getting a "Payment failed" error when clicking "Pay $1.00". Please suggest what can be the issue. I guess it may be an issue with "SQUARE_ACCESS_TOKEN" not being used anywhere in the "server.js" file.
This is the detailed error message in the console: [ [Object: null prototype] { category: 'AUTHENTICATION_ERROR', code: 'UNAUTHORIZED', detail: 'This request could not be authorized.' } ]
This is the server.js file code [server.js code was provided here]
ChatGPT diagnosed the issue in the first instance and suggested that the problem might be related to the SQUARE_ACCESS_TOKEN
not being used correctly in the server.js
file. ChatGPT generated an updated server.js
file. I didn't even review the code and replaced the existing server.js
code with the newly generated code. With these changes, I was able to successfully test the Square Web Payment SDK, resolving the authentication error and completing the card payment process smoothly.
GitHub Link: https://github.com/rajpachori/SquarePaymentSDK