Payment form issues

Close - it’s a node.js app, so everything is written in Javascript, not PHP; you have the correct premise, though. It’s a simple call-and-response back end that interacts with Square’s API. It’s the equivalent of the server.js file you are referencing, but as a full standalone application for decoupled/microservices environment.

I’m still working on finishing up the documentation by adding a full walkthrough of the app, but almost all of the scripts/routes are fully commented with an explanation of what each does.

models/cart.js is used to abstract data for handling orders and parse BigInt. In Javascript, regular numbers can only go so high, and as a result, big integers are required to prevent overflow. Unfortunately, Javascript’s native JSON.parse() functions cannot handle BigInt types, so without the wrappers I made in in this file, it throws an error. You can check out more info in this thread:

util/square-client.js is the backbone of the app. This sets up credentials for accessing Square’s API, and initializes an instance of each of the required APIs (Orders, Payments, etc.)

The create-invoice and payment routes are two different paths that the checkout flow can take. If you want to capture payment right there on the spot, generate a nonce through the front-end (as you did,) and then send a POST request with that nonce, the order_id (Javascript does not play well with underscores, so order_id = orderId, location_id = locationId,) and the idempotency_key (idempotencyKey) that was generated on the checkout page.

If, on the other hand, you want the order to be visible outside of your application (i.e. in the Square dashboard or POS app) then you will need to create an invoice. Unpaid orders through the API are only visible within the app, so you can’t just create an order on a website and have someone pay for it in-store. Instead, you need to generate an invoice for that order and then access the order via the invoice to complete payment.

Let me know if you have any other questions. I would not call this app production ready, but it can at least be used as a base for testing/building your own backend, since a lot of the Square examples from GitHub are a few versions behind.