Receipt Printer
The office PC prints a receipt for every new order, wholesale request, fundraiser final order, contact form, sign-up and live chat request.
Receipt Printer
The office PC has an 80mm USB thermal receipt printer. A PowerShell script on that PC asks the storefront for anything new every 30 seconds and prints it:
| Receipt | Printed for | Source |
|---|---|---|
| Online Sale | Paid website orders, including the main BigCommerce store's order copies | Order (salesChannel = WEBSITE) |
| Fundraising Sale | Paid orders from the fundraising store, with the group and salesperson | Order (salesChannel = FUNDRAISER), its fundraiser, participant and sellerName |
| Contact Form | Contact form messages (spam-flagged ones are skipped) and other website forms | Conversation (main contact form), ContactSubmission |
| New Fundraiser | Fundraiser sign-up applications | FundraiserSignupRequest |
| Wholesale Sale | Paid wholesale orders entered in the admin | Order (salesChannel = WHOLESALE) |
| Wholesale Order | Requests from the wholesale order form, priced if staff have priced them, otherwise TBD | WholesaleOrderRequest |
| Fundraiser Final Order | A community fundraiser's signed final order from fundraising.josemadridsalsa.com/submit, with ship-to, flavors, payment method and amount due | EngagementRequest (source = site:fundraising-submit) |
| Live Chat Request | Every time a visitor asks for a person in the website chat; prints only the date and time | ChatThread |
An order prints once it is paid, so a checkout that is paid later prints then. Cancelled, refunded and exchange orders never print, nor do POS, kiosk, phone or other in-person orders. A wholesale request that staff later enter as a wholesale order prints twice, once for each.
Order receipts start with the sale-type header and the business block (name, address, phone, email and both websites), then the customer's name, address, phone, email and the order time (Eastern), the products, the customer's notes, the sale type (with the group and salesperson for fundraiser orders) and the totals.
How it works
| Part | Where |
|---|---|
| Layouts (48 characters a line) | apps/storefront/lib/receipt-printer/format.ts |
| What to print | apps/storefront/lib/receipt-printer/feed.ts |
| Feed | GET /api/receipt-printer/feed?since=<ISO time> with Authorization: Bearer <RECEIPT_PRINTER_API_KEY> |
| Printer script | apps/receipt-printer/ReceiptPrinter.ps1 (Windows PowerShell 5.1, nothing to install) |
The feed returns each receipt as ready-made lines (text, alignment, bold, double size). The script turns them into ESC/POS commands and writes them straight to the USB printer, so the printer needs no Windows print queue or driver.
Every poll asks for the last 72 hours (never earlier than when the script was first started, so
the first run does not print the backlog). The script appends each printed receipt's id to
printed.log and skips ids already there, so a receipt prints exactly once even though it
appears in many polls. If the PC or the internet is down, the next poll prints what was missed
in that window. The feed sends at most 100 receipts of each kind at a time; when a kind is full
it returns nextSince, and the script keeps asking from there until everything has printed.
Setup
-
Generate a key with
openssl rand -hex 32and set it asRECEIPT_PRINTER_API_KEYin Vercel (Production), then redeploy. -
On the office PC, create
C:\ProgramData\JoseMadridReceiptPrinter\config.json:{ "feedUrl": "https://www.josemadridsalsa.com/api/receipt-printer/feed", "apiKey": "<the same key>", "pollSeconds": 30 } -
Plug in and switch on the printer, then print a sample:
powershell -ExecutionPolicy Bypass -File apps\receipt-printer\ReceiptPrinter.ps1 -TestPrint -
Start it automatically at sign-in (a scheduled task named Jose Madrid Receipt Printer):
powershell -ExecutionPolicy Bypass -File apps\receipt-printer\ReceiptPrinter.ps1 -Install-Uninstallremoves the task;-Onceruns a single poll.
Errors (printer unplugged, no internet, a rejected key) are written to receipt-printer.log in
the same folder; the script keeps polling and prints once the problem is fixed.
To reprint a receipt, delete its line from printed.log; it prints on the next poll if it is
still inside the 72-hour window. To revoke the PC, change RECEIPT_PRINTER_API_KEY.
How is this guide?
Last updated on