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
Property | Description |
---|---|
name | Display name of the coupon |
code | Unique code that merchants will enter |
type | Either FIXED or PERCENTAGE |
discountAmount | Fixed amount to discount (for FIXED type) |
percentage | Decimal percentage to discount (for PERCENTAGE type) |
applicablePlans | Array of plan IDs the coupon can be used with |
usageLimit | Total number of times the coupon can be used |
userUsageLimit | Number of times a single user can use the coupon |
active | Boolean 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:
- Allows merchants to enter coupon codes
- Validates the coupon against the selected plan
- 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.