Commit Graph
1 Commits
Author SHA1 Message Date
Mao NakamotoandClaude Opus 4.8 f1d552f62a feat(promo): discount/gift-code foundation — schema + engine + seeds
Phase 1 slice 1 of the promo/gift-code system. Adds the redeemable-code
rail without wiring it into checkout yet (that's the next slice):

- Migration 115: promo_codes (typed: percent | fixed | gift_card, with
  scope, usage/per-user limits, validity window, gift-card balance) +
  promo_code_redemptions ledger. Type/scope are app enums, not DB CHECK
  lists (repo rule); only true invariants are CHECK-constrained. Seeds
  revamp100 (CHF 100 off) + revamp100p (100% off). Replays cleanly +
  idempotent (verified in a throwaway pg16).
- Pure discount engine (src/config/promo-codes.ts, 9 unit tests): caps
  fixed/gift-card at the order total (never negative), percent floors,
  enforces scope/min-order/expiry/limits.
- Redemption service (validate → compute; record consumes atomically,
  decrementing gift-card balance under a tx so limited codes can't
  overspend).

Distinct from the referral `coupons` table (per-user auto-rewards).
Next: admin issuance UI + checkout redemption (incl. 100%-off →
skip-gateway) across marketplace/workshop/appointment.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-09 12:07:33 +02:00