Gift Cards Architecture & Technical Specs
Atomic balance operations, unique idempotency keys, AES-256-GCM PIN encryption, split-payment math, scheduled delivery, expiration handling, auto-reload triggers, and native Billing gateway registration — all backed by a durable background job engine for reliable async work.
1. Gift Card Code Generation (Cryptographic Security)
| Prefix | Usage |
|---|---|
| `GC` | Standard purchased gift cards (default) |
| `SC` | Store credit wallets |
| custom | Bulk/promotional batches can specify their own prefix; falls back to `GC` if none is given |
2. Purchase Flow (Pending → Active)
A gift card purchase starts in a pending state until payment is confirmed, then transitions to active.
What happens on purchase:
- One or more cards are generated for the requested quantity, each with its own code, PIN, and expiration date.
- A purchase transaction is logged against each card with a unique idempotency key, so a retried request never creates duplicate cards or duplicate charges.
- If a promotional template was used, its usage count and total value generated are updated for analytics.
- The response returns the new card(s) with a
pending_paymentstatus.
Activation (after payment):
- Once payment is confirmed, the card transitions from
pendingtoactiveand an activation timestamp is recorded. - An activation transaction is logged for the audit trail.
- If the card has an email delivery method and a recipient, a delivery event fires — this is what triggers the recipient's email (immediately or on a scheduled date).
See the Getting Started guide for exact request/response shapes.
3. Redemption with Split-Payment Math
Redemption calculates exactly how much to deduct from the gift card and how much remains for the primary payment method — as a true partial payment, not a discount that silently changes the order total.
How it works:
`
Order total: $100, Gift card balance: $30 → chargedAmount: $30 (max available on card) → remainingOrderAmount: $70 (passed to your payment gateway) → isPartial: true (gift card couldn't cover the full order)
If the card had $100 and the order was $80: → chargedAmount: $80 (full order covered by card) → remainingOrderAmount: $0 (no split payment needed) → isPartial: false
`
Every redemption carries a unique idempotency key built from the order and card, so a retried request (a flaky connection at checkout, a double-tap on submit) never double-charges a card.
Balance checks validate the code, PIN, card status, and available balance before returning how much of a given amount the card can cover.
4. Reload with Concurrency Protection
Reloading a card's balance is an atomic operation — if two reload requests land at the same time (a double-click, a retried request), exactly one succeeds and the other is safely rejected as a conflict rather than corrupting the balance.
What's enforced automatically:
- Reloads are blocked on canceled, expired, or non-reloadable cards
- A configurable maximum balance cap prevents overfunding a card
- Every reload is logged as its own transaction with a before/after balance snapshot
- A confirmed final balance is always returned, even under concurrent load
If a conflict is detected, the API returns a clear conflict response so the client can safely retry.
5. Transfer Flow
Gift cards can be transferred to another recipient — useful for re-gifting or correcting a delivery mistake.
What happens on transfer:
- The previous owner's code and PIN are immediately invalidated.
- A new code and PIN are generated for the recipient.
- The transaction is logged with both sender and recipient details for a full audit trail.
- A notification fires so the new recipient can be delivered their card by email.
6. Store Credit / Customer Wallet
Store credit is modeled as its own wallet type, distinct from purchased gift cards, so finance teams can separate real financial liability (purchased cards) from goodwill or return credit in reporting.
How issuance works:
- If the customer already has an active store-credit wallet in that currency, the new credit is added to it atomically.
- If not, a new wallet is created automatically with its own unique code.
- Every issuance is logged as its own transaction, tagged with a reason (e.g., "Return — item not as described") and linked to the originating order.
This distinction — store credit vs. purchased gift card — is what powers accurate liability vs. breakage reporting for finance teams.
7. Scheduled Delivery + Expiration Processing
A durable background job engine handles time-based gift card operations reliably, independent of any single request:
Scheduled Delivery: Cards with a future delivery date are delivered automatically once that time arrives — useful for birthday or holiday gifts purchased in advance. Delivery is tracked per card so nothing goes out twice.
Expiration Handling runs on a daily cycle:
- 7-day reminder — cards approaching expiration get a one-time "expiring soon" notification.
- Auto-expiry — cards past their expiration date automatically transition to
expired.
Both processes are idempotent and safe to run repeatedly — a card is never reminded or expired twice.
8. Auto-Reload Trigger
When a card's balance drops to or below a customer-configured threshold, an auto-reload can fire automatically — topping up the balance without the customer re-entering payment details.
Configuration per card:
- Enable/disable auto-reload
- Reload amount (e.g., $25)
- Low-balance threshold (e.g., trigger at $10 or below)
- Payment method to charge
Auto-reload uses the same atomic, concurrency-safe balance update as manual reloads, and every auto-reload is logged as its own transaction in the customer's history.