17 — Gift Cards

Creation, balance, redemption, POS tender, batches

CEO Summary

Gift cards are a revenue driver and customer retention tool. Create, activate, reload, redeem. Used as POS tender. Business value: Upfront cash, repeat visits. Key metrics: Outstanding liability, redemption rate, batch utilization. If this breaks: POS cannot accept gift card payments; customers cannot redeem.

Architecture

flowchart TB subgraph client [Client] POS[POS Tender] Admin[Admin UI] end subgraph api [API] GC[giftcards.routes] GCM[giftCardManagement.routes] POSR[pos.routes] end subgraph svc [Services] GCS[giftCard.service] GCMS[giftCardManagement.service] end subgraph db [Tenant DB] GCards[(gift_cards)] GTxns[(gift_card_txns)] Batches[(gift_card_batches)] end POS --> POSR Admin --> GC Admin --> GCM GC --> GCS GCM --> GCMS POSR --> GCS GCS --> GCards GCS --> GTxns GCMS --> Batches

Overview

Gift cards are stored-value instruments. Customers purchase, reload, or receive them; they redeem at POS. All amounts in cents.

File Structure

backend/
├── routes/
│   ├── giftcards.routes.js       # Public API: create, balance, redeem, reload
│   ├── giftCard.routes.js       # Alternate routes
│   ├── giftCardManagement.routes.js  # Admin: batches, CRUD
│   └── admin.programs.routes.js # Admin programs (gift card overlap)
├── services/
│   ├── giftCard.service.js
│   └── giftCardManagement.service.js
├── models/
│   ├── giftCardTxn.model.js
│   ├── giftCardTransaction.model.js
│   └── (gift_cards table in tenant DB)
└── jobs/
    └── giftcards.expirer.js    # Expire cards past expiresAt

API Endpoints

MethodPathPurpose
POST/api/giftcardsCreate gift card (initialValueCents, code, activate, customerId, expiresAt, mode, reloadable, batchId)
GET/api/giftcards/:idGet by ID
GET/api/giftcards/code/:codeLookup by code
POST/api/giftcards/:id/reloadReload (add value)
POST/api/giftcards/:id/redeemRedeem (deduct)
POST/api/giftcards/balanceCheck balance by code
POST/api/pos/carts/:id/tender/giftcardPOS tender: apply gift card payment

Database Schema

Table: gift_cards (tenant main DB)

ColumnPurpose
idUUID
orgIdOrganization
codeHuman-readable code (e.g. XXXX-XXXX-XXXX-XXXX)
moderetail
reloadabletrue/false
statusactive, inactive, expired
initialValueCentsOriginal value
balanceCentsCurrent balance
currencyUSD
batchIdOptional batch
customerIdOptional customer
activatedAtActivation timestamp
expiresAtExpiration

Gift Card Lifecycle

  1. Create — POST /api/giftcards with initialValueCents, code (or auto-gen), activate
  2. Activate — Set activatedAt on create
  3. Reload — POST /api/giftcards/:id/reload (add value)
  4. Redeem — POST /api/giftcards/:id/redeem or POS tender
  5. Expire — giftcards.expirer job marks cards past expiresAt

POS Integration

POS tender: gift card payment. Route: POST /api/pos/carts/:id/tender/giftcard. Deducts balance, adds to cart payments. See 06 — POS & Invoicing.

Batches

giftCardManagement.routes — Create batches, bulk issue. GiftCardBatches table. Used for reporting and liability.

Audit

giftCard.service creates AuditEvent for giftcard.issue, giftcard.reload, giftcard.redeem. See 20 — Audit.

Integration Points

SystemConnection
POSTender type: giftcard
PaymentsPayment hub — giftcard in availableMethods
AuditAuditEvent for issue/reload/redeem
Admin Liabilityadmin.liability.routes — gift card liability

Key Paths

PathPurpose
backend/routes/giftcards.routes.jsMain gift card API
backend/services/giftCard.service.jsBusiness logic
backend/jobs/giftcards.expirer.jsExpiration job