I have a set of customers entered in Square along with their cards. Square’s web UI allows me to pick a client from a list then do a quick charge, which we do at the end of each counseling session. I have a separate node.js app where I track counseling sessions, money owed, and money paid for each customer. I’d like that app to be able to automatically charge the customer at the end of a counseling session, similar to how I can do it via Square’s web UI.
The only thing I can find in the Square API that allows me to initiate a charge involves allowing the Square API to display a form prior to submitting a charge, which is different from the manual process that we are now doing in Square. What part of the API should I be looking at instead?
TL,DR: you’ll want the Customer API, Orders API, and Invoices API.
I would check out this script: connect-api-examples/invoice.js at master · square/connect-api-examples · GitHub
It generates an invoice that’s assigned to a customer, and then captures payment using a card on file. The invoice is generated from an order that is created, so the only arguments needed are the location_id, order_id, and customer_id. You can schedule invoices to capture payment down to the minute (I believe), so you could create the invoice, and then schedule it capture payment 1 hour after the session ends.
Of note here is that the above script is only compatible with version <9 of the SDK, since they switched over to using big integers for total amounts in that version. You can read more about that in this thread: BigInt Type Error on new Node SDK which includes fixes for both React Native and Express.