Sub topic 7
Coupon types and the rules that define them
This chapter assumes you can already work with percentages, you know your list price and cost floor from earlier chapters, and you can read short Python. It covers the model every coupon system shares. The next chapters apply it to Udemy and to your own site.
A coupon is a price rule with conditions
A coupon is a code, or a link carrying a code, that changes the price a buyer pays. Every coupon system, whether a marketplace or your own checkout, has two parts:
- An effect: how the price changes.
- Conditions: who can use the coupon, on what, when, and how often.
Many pricing mistakes come from setting the effect and forgetting the conditions. A 50% coupon with no expiry and no cap is a permanent price cut that anyone can find.
The three effects
Almost every coupon reduces to one of three effects.
| Effect | What the buyer gets | Example on a 99.00 course | Typical use |
|---|---|---|---|
| Percentage off | A share of the price removed | 30% off gives 69.30 | Seasonal sales, broad campaigns |
| Amount off | A fixed sum removed | 20.00 off gives 79.00 | Referral rewards, win-back offers |
| Fixed price | The price is set to a value | Price becomes 49.00 | Marketplaces with price tiers, launch pricing |
| Free access | Price becomes zero | 0.00 | Reviewers, partners, giveaways |
Free access is a special case of the first three, such as 100% off or a fixed price of 0. Treat it separately in your rules anyway. Free redemptions earn nothing, so you should cap them tightly and track who receives them.
Each effect behaves differently as the price changes:
- A percentage scales with the price. It gives the same proportional discount on a cheap course and an expensive one.
- An amount off is a larger share of a cheap item. On a 25.00 course, 20.00 off is 80%.
- A fixed price ignores the list price. If you later raise the list price, a fixed-price coupon gives a deeper discount without you changing it.
Which effect a platform lets you use is a platform decision. Some marketplaces only let you pick from preset price points. Your own site can offer any of the three.
Guardrails on the effect
Whatever the effect, apply two limits:
- The final price never goes below zero.
- A coupon never raises the price above the list price. This matters for fixed-price coupons when the buyer is already paying less.
Round only at the end, to the currency's smallest unit, and use decimal arithmetic rather than floats. The code below applies those rules.
from decimal import Decimal, ROUND_HALF_UP
from dataclasses import dataclass
from enum import Enum
CENT = Decimal("0.01")
def money(x: Decimal) -> Decimal:
return x.quantize(CENT, rounding=ROUND_HALF_UP)
class Kind(Enum):
PERCENT = "percent"
AMOUNT_OFF = "amount_off"
FIXED_PRICE = "fixed_price"
@dataclass(frozen=True)
class Rule:
kind: Kind
value: Decimal
def apply_rule(price: Decimal, rule: Rule) -> Decimal:
if rule.kind is Kind.PERCENT:
result = price * (Decimal(100) - rule.value) / Decimal(100)
elif rule.kind is Kind.AMOUNT_OFF:
result = price - rule.value
else:
result = rule.value
# Never below zero, never above the current price.
return money(min(max(result, Decimal(0)), price))
list_price = Decimal("99.00")
print(apply_rule(list_price, Rule(Kind.PERCENT, Decimal("30")))) # 69.30
print(apply_rule(list_price, Rule(Kind.AMOUNT_OFF, Decimal("20")))) # 79.00
print(apply_rule(list_price, Rule(Kind.FIXED_PRICE, Decimal("49")))) # 49.00
print(apply_rule(list_price, Rule(Kind.AMOUNT_OFF, Decimal("120")))) # 0.00
print(apply_rule(list_price, Rule(Kind.FIXED_PRICE, Decimal("120")))) # 99.00The last two lines show the guardrails. An amount larger than the price stops at zero, and a fixed price above the list price leaves the list price unchanged.
The conditions that define a coupon
Conditions are where coupons differ most from one system to another. Check each of these when you set up a code.
Time window
A start and an end. Store times with a time zone, because "ends at midnight" means different moments for buyers in different places. Decide whether the end is inclusive. The validation code later in this tutorial treats the expiry as the first moment the code stops working.
Redemption limits
There are two separate limits, and they solve different problems:
- A total cap limits how many times a code can be used across all buyers. It protects your margin if the code leaks.
- A per-buyer limit stops one person using the same code repeatedly. It usually needs a buyer identity, such as an account or email, to enforce.
A total cap alone does not stop one buyer from using it many times. A per-buyer limit alone does not stop a code spreading to thousands of buyers.
Eligibility
Eligibility decides which buyers and which products qualify:
- Product scope: one course, a set of courses, or everything.
- Buyer scope: new customers only, existing customers only, a named list, or anyone.
- Order scope: a minimum order value, or a required bundle.
Narrow scope is your main protection against discounting buyers who would have paid full price.
Distribution
How the code reaches people matters as much as the rules. A public code printed on a website is available to everyone, including coupon-aggregator sites. A single-use code emailed to one person is private. Unique codes in bulk give the control of single-use codes without managing them by hand.
Stacking
Stacking is what happens when a buyer has more than one discount, such as a coupon plus a sale price or two coupons. Three policies exist:
- No stacking: one discount per order.
- Best of: the system applies whichever discount gives the lowest price.
- Sequential: discounts apply one after another.
Sequential stacking is the risky one because order changes the outcome:
def stack_sequential(price: Decimal, rules: list[Rule]) -> Decimal:
for rule in rules:
price = apply_rule(price, rule)
return price
pct = Rule(Kind.PERCENT, Decimal("30"))
off = Rule(Kind.AMOUNT_OFF, Decimal("20"))
print(stack_sequential(Decimal("99.00"), [off, pct])) # 55.30
print(stack_sequential(Decimal("99.00"), [pct, off])) # 49.30The same two discounts leave you 6.00 apart per sale depending on order. If you allow stacking on your own site, define the order in writing and test it. If you do not need stacking, forbid it.
How a checkout evaluates a code
A well-built system checks conditions in a fixed order and returns a specific reason when one fails. The order is not arbitrary. Cheap checks that need no buyer data go first, and checks that depend on the order go last.
The Udemy and own-site chapters that follow use this same sequence.
Choosing rules for a goal
Match rules to the job the coupon does rather than reusing one template.
| Goal | Effect | Conditions |
|---|---|---|
| Launch to a small first audience | Fixed price or percentage | Short window, total cap, product scope |
| Seasonal sale | Percentage | Fixed end date, one per buyer, no stacking |
| Reward a referral | Amount off | Single-use unique codes, new customers only |
| Win back lapsed buyers | Percentage or amount off | Named list, one use per buyer |
| Give review copies | Free access | Very low cap, unique codes, track recipients |
Whatever the goal, ask what the price is after the discount and whether it stays above your cost floor once fees and any revenue share are taken out. A coupon that looks fine as a percentage can push the net per sale below your minimum, especially when a fixed payment fee is a large part of a low price.
Common errors
- Percent and amount confusion. "20 off" entered in a percentage field gives 20%, not 20.00. Label fields clearly and validate their ranges.
- Open-ended codes. A code with no expiry and no cap is a standing discount.
- Time zone drift. Naive timestamps make a coupon end hours early or late for some buyers.
- Stacking by accident. A site-wide sale price plus a coupon can compound unless you decide otherwise.
- Float arithmetic. Binary floats give prices like 69.30000000000001. Use decimals and round once.
- Silent failures. A generic "invalid code" message pushes buyers to support or away. Return the specific reason.
Exercise
A course lists at 80.00. You run two discounts: 25% off, and 10.00 off. A buyer can use both in sequence. Calculate the final price in each order and say which order gives the buyer the lower price. Then state one condition you would add to stop a leaked code being used by many buyers.
Show answer
Percent first: 80.00 × 0.75 = 60.00, then 60.00 − 10.00 = 50.00. Amount first: 80.00 − 10.00 = 70.00, then 70.00 × 0.75 = 52.50. Percent first gives the lower price, 50.00. To limit leakage, add a total redemption cap (and an expiry). For one buyer reusing a code, also add a per-buyer limit; unique single-use codes avoid both problems.
Exercise
A fixed-price coupon sets the price to 40.00. A buyer already has a sale price of 35.00 on the same course. What should a correctly guarded system charge, and which guardrail applies?
Show answer
It should charge 35.00. The guardrail is that a coupon never raises the price above the current price, so the result is the lower of the coupon price and the existing price.