Sub topic 7
Coupon Types and the Rules That Define Them
This chapter assumes you understand percentages, basic online sales, and the difference between a course price and the amount you keep after fees. The goal is to design coupon rules that are clear to buyers and enforceable by your checkout system.
Choose the coupon type
A coupon changes the price according to a rule. The most common types are:
| Coupon type | Example | Best use |
|---|---|---|
| Percentage discount | 30% off | Campaigns where prices may vary |
| Fixed-amount discount | $20 off | A predictable saving on one course |
| Free access | 100% off | Reviewers, partners, or scholarship seats |
| Bundle discount | 25% off two or more courses | Increasing the order size |
A percentage coupon preserves the relationship between prices. A fixed discount gives a larger effective discount on a cheaper product, so check your margin before using it.
Separate the discount amount from the coupon's eligibility rules. For example, SPRING30 might mean 30% off, but it might also require a minimum order of $50, expire on April 1, and apply only to new customers.
Define the rules explicitly
A usable coupon specification answers these questions:
- Scope: Which course, bundle, or product can use it?
- Discount: Is it a percentage, fixed amount, or free-access coupon?
- Time: When does it start and expire?
- Usage: Is there a total redemption limit?
- Customer limit: Can one customer redeem it once or repeatedly?
- Eligibility: Is it public, restricted to a customer list, or tied to an email domain?
- Combination: Can it be combined with another coupon or automatic promotion?
- Minimum order: Does the cart need to reach a minimum value?
- Refund behavior: What happens to the discount if the buyer requests a refund?
Use timezone-aware times. A rule that expires at “midnight” is ambiguous unless you specify the timezone. Store coupon codes in a normalized form, such as uppercase, so spring30 and SPRING30 do not accidentally become separate codes.
from dataclasses import dataclass
from datetime import datetime, timezone
from decimal import Decimal
from typing import Optional
@dataclass
class Coupon:
code: str
percent_off: Decimal
starts_at: datetime
expires_at: datetime
max_redemptions: Optional[int]
redeemed: int = 0
def validate_coupon(
coupon: Optional[Coupon],
now: datetime,
) -> Optional[str]:
if coupon is None:
return "Unknown code"
if now < coupon.starts_at:
return "Coupon is not active yet"
if now >= coupon.expires_at:
return "Coupon expired"
if (
coupon.max_redemptions is not None
and coupon.redeemed >= coupon.max_redemptions
):
return "Coupon fully redeemed"
return None
spring = Coupon(
code="SPRING30",
percent_off=Decimal("30"),
starts_at=datetime(2030, 3, 1, tzinfo=timezone.utc),
expires_at=datetime(2030, 4, 1, tzinfo=timezone.utc),
max_redemptions=100,
)
check_time = datetime(2030, 3, 15, tzinfo=timezone.utc)
print(validate_coupon(spring, check_time)) # NoneThe validator returns an error when the coupon cannot be used. In a real checkout, also validate the product, customer, minimum order, and stacking rules on the server. Do not trust a discount calculated only in browser code.
Model the decision flow
Check eligibility before recording a redemption. Record the redemption atomically with the order, so two simultaneous buyers cannot exceed a limited campaign.
Exercise
A coupon expires at 2026-06-01 00:00 UTC. Can a buyer use it at 2026-06-01 00:00:00 UTC?
Show answer
No. If the expiry rule is exclusive, the coupon is invalid when the current time is equal to or later than the expiry time.