Coupons

This guide explains how to work with subscription coupons in the merchant system.

Overview

The coupons system allows you to create and manage discount codes for merchant subscriptions. Two types of discounts are supported:

  • Fixed amount discounts (e.g., $10 off)
  • Percentage discounts (e.g., 20% off)

Creating Coupons

Coupons can be created through the database seeder or through the system's API endpoints.

Coupon Properties

PropertyDescription
nameDisplay name of the coupon
codeUnique code that merchants will enter
typeEither FIXED or PERCENTAGE
discountAmountFixed amount to discount (for FIXED type)
percentageDecimal percentage to discount (for PERCENTAGE type)
applicablePlansArray of plan IDs the coupon can be used with
usageLimitTotal number of times the coupon can be used
userUsageLimitNumber of times a single user can use the coupon
activeBoolean indicating if the coupon is currently valid

Example: Creating Coupons via Seeder

// In /prisma/commands/seed.dev.js
 
// Fixed Amount Coupon ($10 off)
await prisma.coupon.create({
  data: {
    name: "$10 Discount Coupon",
    code: "DISCOUNT10",
    discountAmount: 10,
    applicablePlans: planIds,
    usageLimit: 100,
    userUsageLimit: 10,
    active: true,
    type: CouponType.FIXED,
  },
})
 
// Percentage Coupon (20% off)
await prisma.coupon.create({
  data: {
    name: "20% Discount Coupon",
    code: "DISCOUNT20",
    percentage: 0.2, // 20%
    applicablePlans: planIds,
    usageLimit: 50,
    userUsageLimit: 5,
    active: true,
    type: CouponType.PERCENTAGE,
  },
})

Frontend Integration

The coupon redemption flow is handled by the PromoModal component in PlansTab.jsx. This modal:

  1. Allows merchants to enter coupon codes
  2. Validates the coupon against the selected plan
  3. Applies the discount to the subscription price

API Integration

The coupon validation and application processes are handled through the system's API. Refer to the API documentation for detailed information about the available endpoints and their usage.