Variable-amount gift cards purchasable with any payment method. Code-based redemption at checkout (applied to cart like coupons). Partial use across multiple purchases, never expire. Shop owners control min/max amounts and can disable individual cards. Models: GiftCard, GiftCardTransaction, CartGiftCard + migration. Views: purchase page, cart apply/remove, shop admin manage/detail/toggle. Templates: gift_card.j2, gift_card_manage.j2, gift_card_detail.j2. Cart integration: gift cards deduct after coupons in all checkout paths. Tests: 10 new unit tests covering model logic (677 total pass).
2.4 KiB
MPS-13: Gift Card System — Shop Admin & Settings
Problem
Shop owners need to enable/configure gift cards and view issued cards with their balances and transaction history.
Solution
Shop settings: gift card configuration
New gift-card-settings form section in shop settings:
- Enable Gift Cards toggle (
gift_card_enabled) - Minimum Amount input (
gift_card_min_in_cents, displayed as dollars) - Maximum Amount input (
gift_card_max_in_cents, displayed as dollars)
Validation:
- Min must be >= $1.00 (100 cents)
- Max must be >= min
- Max must be <= $10,000.00 (1000000 cents) — reasonable upper bound
Gift card management page
New route: /shop/{slug}/gift-cards/manage (shop owner only)
Displays a table of all issued gift cards:
| Code | Amount | Balance | Purchaser | Recipient | Date | Status |
|---|
Features:
- Sort by date (newest first)
- Show active vs fully redeemed vs disabled
- Click a card to see its transaction history
- Disable/enable toggle per card (admin kill switch)
Gift card detail view
/shop/{slug}/gift-cards/{card_id} (shop owner only)
Shows:
- Card details (code, amounts, emails)
- Transaction history table (date, invoice, amount deducted, remaining balance)
- Disable toggle
Buyer's gift card view
Buyers who purchase gift cards can see their purchased cards and remaining balances on their account page. Recipients (who redeem codes) can check balance by entering the code on the shop's gift card page.
Balance check
On the gift card purchase page (/shop/{slug}/gift-card), add a "Check Balance"
section where anyone can enter a code and see the remaining balance. No account
required — the code IS the identity.
Files Changed
| File | Change |
|---|---|
views/shop.py |
gift-card-settings form handler |
views/gift_card.py |
Management page, detail view, balance check |
templates/shop_settings.j2 |
Gift card settings form section |
templates/gift_card_manage.j2 |
New: gift card list for shop owner |
templates/gift_card_detail.j2 |
New: single card detail + transactions |
templates/gift_card.j2 |
Add balance check section |
routes.py |
Add management + detail routes |
tests/test_functional.py |
Settings save, gift card CRUD, balance check |
Depends On
MPS-10 (models), MPS-11 (purchase flow creates cards to manage).