Loading…
Implementing Android POS Receipt Printing on Shopify
2023-10-18
- Source
- Shopify
- Published
- Added to Yomu
Summary
Shopify’s Android POS lacked printed-receipt support until March 2019, leaving merchants who needed it to use iPads. The design targets a pragmatic, adaptive, composable, maintainable, and highly testable API, while handling more than 8 billion possible receipt content combinations across discounts, tips, transactions, gift cards, refunds, payment methods, and regional requirements. Its six-step pipeline aggregates models from SQLite or GraphQL, transforms them into a PrintableReceipt, defines view-based sections, creates printer-agnostic PrintRequest objects, renders section bitmaps at the required resolution, and passes them through the Hardware SDK to vendor-specific integrations. The PrintableReceiptComposer contains most business logic, with unit tests covering features and edge cases, while screenshot tests compare rendered output pixel by pixel in CI. This componentized separation isolates printer support from receipt generation and allows new printer models to be added in a couple of hours.
Context
Shopify POS released first for iOS, leaving Android merchants who required printed receipts with no choice but to switch to an iPad. Receipt generation also had to account for more than 8 billion combinations affected by POS features, payment methods, countries, and printer variations.
Approach / What changed
The implementation uses a six-step printing pipeline: Data Aggregation, Content Generation, Sections Definition, Print Request Creation, Content Rendering, and Receipt Printing. Receipt data is transformed into a PrintableReceipt, sections are represented by Android views and binders, printer-agnostic requests are passed to the Hardware SDK, and rendered bitmaps are delivered through vendor-specific integrations. Unit, test-driven, and screenshot testing enforce correctness.
Takeaways
- Data Aggregation asynchronously fetches raw models from the local SQLite database or GraphQL API, using coroutines to run requests in parallel.
- The Hardware SDK separates receipt generation from printer integrations and supports different vendors and connectivity interfaces, including Wi-Fi, Bluetooth, and USB.
- Content Generation has more than 80 unit test cases, while CI screenshot tests compare receipt bitmaps pixel by pixel against recorded baselines.