POS Gateway - Real-Time Terminal Integration
Domain: POS Gateway
Location: api/nextango/apps/pos_gateway/
Last Updated: 2026-07-09
Overview
Renamed: This app was formerly
pos_realtime. It was refactored and renamed topos_gatewayto reflect its expanded scope beyond real-time messaging. The deprecatedpos_realtimeapp is fully removed; onlypos_gatewayis active.
The POS Gateway app provides real-time integration with POS terminals through JWT-based authentication, WebSocket connections for live updates, manager approval workflows, terminal session management, cash drawer integration, and broadcast/messaging infrastructure for hardware. Designed for high-performance retail operations.
Documentation Quick Links
Core Documentation
| File | Description |
|---|---|
| models.md | TerminalSession, InventoryReservation, ManagerApprovalRequest models |
| authentication.md | JWT terminal authentication system |
| consumers.md | WebSocket consumers for real-time connections |
| views.md | POS Gateway API endpoints |
| services.md | Gateway services and business logic |
| broadcast.md | WebSocket broadcast system |
| infrastructure.md | Redis, WebSocket, and deployment infrastructure |
| serializers.md | POS Gateway API serializers |
| signals.md | POS Gateway signals |
| examples.md | Usage examples and patterns |
Key Features
JWT-based terminal sessions. Terminals authenticate with an employee PIN and receive an 8-hour JWT session, tracked in a TerminalSession row and validated on every request via Redis-first, database-fallback lookup. See Authentication.
WebSocket real-time connections. TerminalConsumer and ManagerConsumer provide bidirectional real-time updates over Redis-backed channel groups: terminal-specific, store-wide, and manager-dashboard groups. See Consumers and Broadcast Utilities.
Manager approval workflows. A terminal can request manager sign-off for a discount, void, return, price override, cash drawer access, or refund. The request is created via REST or WebSocket, notified to managers over WebSocket, and decided by a manager on their own dashboard connection. See Consumers and Services.
Cash drawer trigger. The gateway exposes a hardware-level drawer-open trigger for the terminal. Full register lifecycle (close with variance, till count) is handled by CashDrawerViewSet in the transactions app, not here.
Startup cache warming. On app startup, GatewayInitializationService pre-warms Redis with active product variants and store configuration so the first POS request after a deploy doesn't pay a cold-cache database lookup. See Services.
Note: SKU and barcode lookup, and inventory reservation, were previously handled by dedicated gateway endpoints and services. Both were removed during the gateway refactor. The POS frontend calls the products API directly, and inventory holds are managed by the transactions app's own reservation logic. See the note under API Endpoints below.
API Endpoints
Terminal Authentication
| Endpoint | Method | Description |
|---|---|---|
/pos/auth/terminal-login/ | POST | Authenticate terminal, return JWT session token |
/pos/auth/terminal-logout/ | POST | Terminate terminal session |
Transaction Operations
| Endpoint | Method | Description |
|---|---|---|
/pos/transactions/create/ | POST | Create a new POS transaction |
/pos/transactions/{id}/payment/ | POST | Process payment for a transaction |
Manager Approvals
| Endpoint | Method | Description |
|---|---|---|
/pos/approvals/request/ | POST | Request manager approval (price override, return, void) |
/pos/approvals/status/{id}/ | GET | Poll approval request status |
Cash Drawer
| Endpoint | Method | Description |
|---|---|---|
/pos/cash-drawer/ | POST | Cash drawer operations. Only open is implemented; close, count, deposit return 501 |
Health & Audit
| Endpoint | Method | Description |
|---|---|---|
/pos/health/ | GET | Gateway health check |
/pos/audit/auth-event/ | POST | Log authentication audit event |
WebSocket Channels
| URL Pattern | Consumer | Description |
|---|---|---|
/ws/pos-gateway/terminal/{terminal_id}/ | TerminalConsumer | Terminal real-time channel: inventory updates, approval responses, heartbeat |
/ws/pos-gateway/manager/{store_id}/ | ManagerConsumer | Manager dashboard: approval requests, store-wide notifications |
Note: POS inventory lookup is handled directly by the products API:
GET /product-variants/?sku=<barcode>. The dedicatedpos_gatewayinventory endpoints (inventory/lookup/andinventory/reserve/) were removed during the gateway refactor. The POS frontend calls the products ViewSet directly.
Full endpoint documentation: views.md
Architecture Highlights
WebSocket Channels
Real-time bidirectional communication:
Terminal Channel: /ws/pos-gateway/terminal/{terminal_id}/
- Transaction updates
- Inventory notifications
- Approval responses
- Heartbeat messages
Manager Channel: /ws/pos-gateway/manager/{store_id}/
- Approval requests
- Store-wide notifications
- Dashboard updates
- Alert broadcasts
Read more: consumers.md, broadcast.md
JWT Authentication Flow
Secure terminal authentication:
- Terminal login with employee PIN
- JWT token issued with terminal session (8-hour expiration)
- Token used for API and WebSocket auth
- Session tracking and heartbeat via Redis-first, database-fallback validation
There is no token refresh endpoint; a terminal re-authenticates with the PIN when its session expires.
Read more: authentication.md
Redis-Powered Performance
Caching and channel-layer pub/sub:
- Product and store lookup cache, warmed on app startup
- Session state cache for fast JWT revalidation
- WebSocket message pub/sub via
channels_redis.pubsub.RedisPubSubChannelLayer
Read more: infrastructure.md
Service Layer Architecture
Gateway logic centralized in service classes, each a thin orchestration layer over domain services:
- GatewayInitializationService - Startup cache warming
- TransactionGatewayService - Transaction creation and payment, delegating to
TransactionServiceandPaymentService - ManagerApprovalGatewayService - Approval request creation and status
- CashDrawerGatewayService - Cash drawer open trigger
- WebSocketBroadcaster (
utils/broadcast.py) - WebSocket message distribution
Read more: services.md
Getting Started
1. Understand the Models
Start with models.md to understand:
- TerminalSession (
terminal_id,user,auth_token,last_heartbeat) - ManagerApprovalRequest (
request_type,terminal_session,requested_by,approved_by,status) - InventoryReservation and GatewayPerformanceMetric are defined but currently have no writer anywhere in the codebase
2. Review Authentication
Read authentication.md to understand:
- JWT token generation and validation
- Terminal login workflow
- Session management
- Token refresh mechanism
3. Explore WebSocket Consumers
Check consumers.md to learn:
- Terminal WebSocket consumer
- Manager WebSocket consumer
- Message handling
- Connection lifecycle
4. Study Service Layer
Review services.md for:
- Transaction creation and payment orchestration
- Manager approval workflows
- Cash drawer trigger
- Startup cache warming
Related Domains
- Users - Employee authentication and PIN validation
- Stores - Store and terminal configuration
- Transactions - POS transaction processing
- Products - Product and inventory lookup
- Payments - Payment processing integration
Key Architectural Decisions
- JWT authentication - Stateless-looking terminal sessions backed by a database row, so revocation is possible despite the JWT itself being stateless
- WebSocket real-time - Instant updates, no polling required
- Redis caching - Fast product/store lookup and session revalidation
- Delegation over duplication - Gateway services orchestrate
transactions,payments, andproductsdomain services rather than reimplementing business logic - Manager approvals - Real-time approval workflow over WebSocket
- Heartbeat monitoring - Detect stale terminal sessions
- Service layer - Business logic centralized in gateway services, testable independent of views
Common Use Cases
- Terminal login - Employee PIN authentication, JWT session creation
- Transaction processing - Create a transaction, then apply payment
- Manager approval - Request and process discount, void, return, or price override approvals
- Cash drawer - Trigger the physical drawer open
- Real-time updates - WebSocket notifications for transactions and approvals
- Terminal monitoring - Heartbeat-driven session activity tracking
- Audit logging - Client-emitted audit events for security and compliance review
Service Methods
GatewayInitializationService
initialize()- Run cache warming on app startup_warm_product_cache()- Cache active product variants by SKU and Sanity ID_warm_store_cache()- Cache store configuration by Sanity ID and database ID
TransactionGatewayService
create_transaction(terminal_session, transaction_data)- Create a sale transaction viaTransactionServiceprocess_payment(terminal_session, transaction_id, payment_data)- Apply payment viaPaymentService, committing reserved inventory when the transaction completes
ManagerApprovalGatewayService
request_approval(terminal_session, request_type, amount, reason, details)- Create aManagerApprovalRequestcheck_approval_status(request_id)- Poll approval status (fallback path; the primary notification is via WebSocket)
CashDrawerGatewayService
open_drawer(terminal_session, reason)- Trigger the physical drawer open viaCashDrawerService
WebSocketBroadcaster (utils/broadcast.py)
broadcast_transaction_created(transaction, store_id)broadcast_transaction_updated(transaction, store_id, updates)broadcast_transaction_completed(transaction, store_id, payment_method)broadcast_return_processed(return_record, store_id)broadcast_inventory_update(variant_sku, store_id, available_quantity, reserved_quantity)broadcast_system_notification(store_id, message, severity)
Full documentation: services.md
Next Steps
- Start with models.md - Understand the data structure
- Then authentication.md - Learn JWT authentication
- Review consumers.md - Explore WebSocket connections
- Study services.md - Learn business logic
- Check broadcast.md - Understand real-time messaging
- Review infrastructure.md - See Redis and WebSocket setup
- Explore views.md - See API endpoints