Gift cards and store credit are deceptively simple features from a customer's perspective, redeem a code, get a discount, but implementing them correctly in a headless commerce backend requires careful thought around balance tracking, expiration, partial redemption, and how they interact with your existing pricing and discount logic. Medusa.js provides the building blocks for this, but the implementation details matter.
Gift Cards vs Store Credit: A Useful Distinction
Though often used interchangeably, gift cards and store credit typically serve different purposes and benefit from being modeled distinctly. Gift cards are usually purchased by one customer as a product to give to another, carrying their own SKU and checkout flow. Store credit, by contrast, is typically issued by the merchant directly, refunds, loyalty rewards, or goodwill gestures, without going through a standard purchase flow. Medusa's gift card module can support both use cases, but keeping the distinction clear in your data model avoids confusion later when reporting on redemption sources.
Component | What It Handles | Key Consideration |
|---|---|---|
Gift card product | Purchasable card with a defined value | Should not decrement standard inventory |
Balance tracking | Remaining redeemable amount per card | Must support partial redemption |
Redemption at checkout | Applying card balance to an order total | Must support partial redemption |
Handling Partial Redemption Correctly
A gift card rarely gets used in a single transaction that exactly matches its balance. The implementation needs to support applying part of a gift card's balance to an order, deducting only that amount, and preserving the remaining balance for future use. This sounds straightforward but requires careful transaction handling to avoid race conditions where a gift card's balance could be double-spent if two orders are processed against it in close succession, a genuine risk under concurrent checkout traffic that needs to be handled at the database transaction level rather than assumed away.
Interaction with Discounts and Promotions
Gift card redemption needs a clearly defined order of operations relative to other discounts applied at checkout. Most implementations apply percentage or fixed discounts to the order subtotal first, then apply gift card balance against the discounted total, since applying it in the reverse order can produce confusing final totals that do not match customer expectations. Documenting this order explicitly in your checkout logic, rather than leaving it to whatever order the code happens to execute in, prevents subtle pricing bugs.
Expiration and Compliance Considerations
Depending on your jurisdiction, gift card expiration may be legally restricted or prohibited entirely, which makes this a decision worth confirming with legal guidance rather than assuming based on common ecommerce practice elsewhere. If expiration is permitted and desired, building it as a configurable field on the gift card record, rather than a hardcoded global rule, gives flexibility to adjust policy without a code deployment.
A Practical Build Sequence
1. Decide whether gift cards and store credit need separate data models or can share one with a source flag
2. Implement balance tracking with transaction-safe deduction to prevent race conditions
3. Define and document the discount-then-gift-card order of operations at checkout
4. Confirm expiration policy against applicable regulations before implementing any expiry logic
Medusa's commerce modules documentation outlines the underlying module structure gift card and pricing logic builds on top of, and reviewing it alongside your specific redemption and discount interaction rules before development starts avoids rework later. Teams building this out for the first time can also review Askan's Medusa.js implementation work for reference on how balance tracking has been handled across previous merchant builds.
Written by
Kannan Rajendiran
CEO
