Just finished successfully the squareup demo payment, but when I tried to change it to production payment got this error: (after hooked up the 401 unauthorized error)
Error: Bad Request
at createError (C:\xampp\htdocs\web-payments\node_modules\micro\lib\index.js:20:14)
at createPayment (C:\xampp\htdocs\web-payments\server.js:24:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
When you switched to production did you complete all the deployment tasks:
Get production application credentials. In the Get Sandbox application credentials section, you obtained Sandbox credentials. Follow the steps to open the Developer Dashboard, but this time choose Production mode, and then copy the production application ID and access token.
Update script references. In the ADD SCRIPT REFERENCES section, you added script references in index.html. Update the domain string in the JavaScript reference from sandbox.web.squarecdn.com/v1/square.js to web.squarecdn.com/v1/square.js .
Provide your production application ID. The Web Payments SDK requires a valid application ID to return a payment token. In the Provide your application ID section, you provided a Sandbox application ID. Update the code by providing your production application ID.
Configure your backend server to use a production access token. In the Configure the backend with your access token section, you provided a Sandbox access token. Replace it with the production access token.
Yes, changed and copied the product app id, product access token and product location id
changed the script tag src to “https://web.squarecdn.com/v1/square.js”
product app id: sq0idp-8kMSx1TR4xB83iDEp8sBrw
but not sure I’ve put in the right place the production Access Token
yes done it, but when it rename to .env.production the error is 404 didn’t find the .env.sandbox now its name is .env.sandbox and the Authorization: ‘Bearer EAAAEbUirRCgjITtd9MQq4nmK_…’ is in the async function createPayment(token) {
const body = JSON.stringify({
locationId,
sourceId: token,
Authorization: ‘Bearer EAAAEbUirRCgjIT…’,
}
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly:
C:\xampp\htdocs\web-payments\server\square.js
3:23 error ‘SQUARE_ACCESS_TOKEN’ is assigned a value but never used no-unused-vars
7:15 error Insert ⏎··· prettier/prettier
2 problems (2 errors, 0 warnings)
1 error and 0 warnings potentially fixable with the --fix option.
ERROR: “lint:eslint” exited with 1.
ERROR: “lint” exited with 1.
In your createPayment you shouldn’t be passing your access token. If you create a .env.production with your production access token then run npm start it will process production payments.