Welcome to the Jose Madrid Salsa developer docs — explore features, APIs, and deployment guides.
Jose Madrid SalsaJMS Docs

Discount Codes

Promo codes — types, limits, and how they are validated at checkout.

Discount Codes

Promotional codes are managed at /admin/settings/discount-codes and validated by lib/discounts.ts.

The code

DiscountCode carries:

FieldMeaning
codeUnique, matched case-insensitively (stored and compared uppercase)
typePERCENTAGE or FIXED_AMOUNT
valueThe percentage, or the dollar amount
minPurchaseMinimum pre-discount cart total
maxUses / usedCountGlobal usage cap
maxUsesPerUserPer-customer cap, counted through DiscountUsage
startsAt / expiresAtValidity window
isActiveMaster switch

DiscountUsage records each redemption, which is what makes the per-user cap enforceable.

Validation

validateDiscountCode(code, cartTotal, userId?) returns a DiscountValidationResult — never throws for a bad code. It checks, in order, that the code exists and is active, that now falls inside the validity window, that the cart clears minPurchase, and that neither the global nor the per-user usage limit has been reached. On success it returns the computed discountAmount and the code's metadata.

Passing userId is what enables the per-user check; without it only the global cap is enforced.

Interaction with other money

  • Fundraiser commission — a discount does reduce the commission base, because it genuinely reduces what was earned on the goods. See Fundraising.
  • Gift certificates — a means of payment, not a discount. They do not reduce the commission base and are not validated here. See Gift Certificates.
  • Loyalty tiers — a standing percentage from the loyalty program, applied independently of a code.
  • QuickBooks — checkout discounts are booked against discountAccountId. See QuickBooks Online.

How is this guide?

Edit on GitHub

Last updated on

On this page