Discount codes
Five effect types, restriction sets, validity windows and usage limits — and what happens to a code between the cart and the ticket
A discount code is bearer evidence: presenting it is the authentication. Anyone who types it correctly gets what it grants, which is why the interesting configuration is not who may use it but what it does, what it covers and how many times it works.
What a code does to a cart arrives on a quote as an effect, in
applied_effects: a small object carrying what it did, display copy you can
render, and the id of the code it came from. Build your cart UI against that
shape rather than against codes themselves and it keeps working as more things
become able to change a price.
The shape on the wire
{
"id": "dsc_0199c4e8-5e43-7c77-bd24-6f0a3b8c1d55",
"code": "WINTER20",
"effect_type": "percent",
"percent_bps": 2000,
"amount_minor": null,
"amount_currency": null,
"stackable": false,
"valid_from": null,
"valid_until": null,
"max_uses": 100,
"max_uses_per_customer": 1,
"active": true,
"item_ids": [],
"event_ids": ["evt_0199c4e5-2b10-7f44-8a91-3c7d0e5f8a22"],
"metadata": {}
}The five effect types
effect_type | What it does | Fields it requires |
|---|---|---|
percent | Takes a percentage off each covered position. | percent_bps in (0, 10000] |
amount | Takes a fixed amount off each covered ticket. | amount_minor, amount_currency |
price_override | Sets each covered position to a fixed price. Zero is free entry. | amount_minor, amount_currency |
fee_waiver | Waives the buyer-visible booking fee. | none |
unlock | Makes a gated item purchasable. | none |
The fields are mutually exclusive and the engine enforces it: a percent code
carrying an amount is rejected, an unlock carrying either is rejected, and
price_override reuses the amount fields — the amount is the price the
position becomes.
amount is per ticket, not per cart. A 500 off code on a line of three
tickets takes 1500 off that line. If you mean "£5 off the order", a code
cannot express it today.
Two more rules worth knowing before you pick a type:
- A discount can never make a line negative. A percentage is capped at the price and a fixed amount is capped at the remainder; the floor is zero.
price_overrideonly applies when it lowers the price. An override above the current price is reported as superseded and charges nothing extra. Where several overrides cover a line, the lowest wins.
fee_waiver waives the booking fee only
It removes what the buyer pays in fees, not the platform fee itself: the fee
still exists and falls to your proceeds. It therefore does nothing at all
against an absorbed fee schedule, or on a position whose fee is already zero.
One waiver is all a position can use — see
fee schedules.
unlock opens a gated item
An unlock code names no price. An unlock code makes a gated line sellable in
quotes and checkout sessions. That is how a
members-only tier can be offered with an explicit unlock when the buyer has
no matching membership effect. A code that unlocks nothing in the cart —
because no covered line is gated — is rejected as not_applicable rather than
applied silently.
Restriction sets
item_ids and event_ids are the code's coverage, and they work as a union:
- Both empty — every position in the cart. This is the default.
- Otherwise — a position is covered if its item is in
item_ids, or its event is inevent_ids.
Naming an event covers every item that points at it, including items you create afterwards. That makes "20% off everything at the winter social" a single code that does not need revisiting when you add a tier.
Both arrays reject duplicate ids, and every id must exist under your organizer
or the write answers 400 invalid_reference. On a patch, an array you send
replaces the existing one wholesale; an array you omit is left alone.
A code that covers no line in the cart is rejected as not_applicable — it is
not an error, just a code that did nothing here.
Validity, limits and uniqueness
| Field | Behaviour |
|---|---|
valid_from | Nullable. Before it, the code is rejected not_yet_valid. Inclusive: the code works at exactly this instant. |
valid_until | Nullable. At and after it, the code is rejected expired. Must be strictly after valid_from. |
active | Default true. false rejects the code as inactive. This is the off switch; there is no delete. |
max_uses | Positive integer or null for unlimited. Counts redemptions across all buyers: one checkout that uses the code is one use, however many tickets it discounts. It does not cap ticket quantity. |
max_uses_per_customer | Positive integer or null. Counts that identified customer's redemptions, not tickets. |
stackable | Default false. See stacking. |
Send RFC3339 timestamps with an offset; responses normalize to UTC with milliseconds. Windows are compared as instants against the engine's clock, not against the venue's timezone — "midnight on the 31st" is whatever instant that is where your buyers are, so write the offset you mean.
Codes are unique per organizer, case-insensitively
SUMMER, summer and Summer are the same code. Creating a second one
answers:
{
"error": {
"type": "invalid_request_error",
"code": "code_already_exists",
"message": "A discount code with this value already exists",
"param": "code",
"request_id": "d2b7f0c4-9a51-4a2f-9c1e-6c4b0a7e12f3"
}
}Matching is case-insensitive too, and codes are trimmed of surrounding
whitespace before they are looked up — so a buyer who pastes winter20 gets
the code you created as WINTER20. Presenting the same code twice in one
request counts once.
Store the code the way you want it displayed; the engine echoes back the spelling you created, and echoes a rejection back in the spelling the buyer typed.
Stacking
By default the engine applies the single best discount per position: among
the non-stackable effects covering a line, only the one that produces the
lowest final price applies, and the rest are reported in
superseded_effect_ids. "Best" is decided by simulating each candidate and
comparing the final prices, so it always lands on the answer that favours the
buyer.
A stackable percent or amount discount opts out of that competition: it always applies, in addition to whichever exclusive discount won. Price overrides, fee waivers and unlocks are not part of this comparison — each has its own rule, described above.
Stacked percentages apply one after another, each to what is left, not
added together. Two stackable 10% codes on a 2500 ticket take 250, then 225
off the remaining 2250, leaving 2025 — 19% off in total, not 20%.
A superseded code is worth knowing about for a reason beyond display: a code that priced nothing is never spent. Its usage count does not move.
A price for one checkout is not a code
If your own backend decides a price for one buyer — an affiliate or invitation
offer — do not create a code for it. Send it as an offer when you create the
checkout: it takes the same
effect types, is priced by the same engine, and cannot be presented to or
replayed into any other cart.
Create one
POST/v1/discount_codescurl -X POST https://tickets.lissen.com/api/v1/discount_codes \
-H "Authorization: Bearer tk_test_..." \
-H "Ticketing-Organizer: org_0199c4e2-1f7a-7c31-8d44-2b9f6a1e05c7" \
-H "Idempotency-Key: 6d0f2a91-7c35-4b60-8e19-3a4c7f2b9d05" \
-H "Content-Type: application/json" \
-d '{
"code": "WINTER20",
"effect_type": "percent",
"percent_bps": 2000,
"event_ids": ["evt_0199c4e5-2b10-7f44-8a91-3c7d0e5f8a22"],
"valid_until": "2026-11-14T00:00:00Z",
"max_uses": 100,
"max_uses_per_customer": 1
}'A fixed-price members' tier, restricted to one item:
curl -X POST https://tickets.lissen.com/api/v1/discount_codes \
-H "Authorization: Bearer tk_test_..." \
-H "Ticketing-Organizer: org_0199c4e2-1f7a-7c31-8d44-2b9f6a1e05c7" \
-H "Idempotency-Key: 0b7e5c34-92a1-4f76-8d03-1a5b6c8e2f49" \
-H "Content-Type: application/json" \
-d '{
"code": "MEMBERS",
"effect_type": "price_override",
"amount_minor": 1500,
"amount_currency": "GBP",
"item_ids": ["itm_0199c4e3-77a2-7e19-b0c5-9d3f2a4e6b10"]
}'Update with PATCH/v1/discount_codes/{id}; the
merged result is validated, so a patch that leaves the code in an incoherent
state — adding percent_bps to an amount code, say — is a 400 naming the
offending field.
Presenting a code
Codes go into a cart as strings, up to ten per request:
curl -X POST https://tickets.lissen.com/api/v1/quotes \
-H "Authorization: Bearer tk_test_..." \
-H "Ticketing-Organizer: org_0199c4e2-1f7a-7c31-8d44-2b9f6a1e05c7" \
-H "Content-Type: application/json" \
-d '{
"line_items": [
{ "item_id": "itm_0199c4e3-77a2-7e19-b0c5-9d3f2a4e6b10", "quantity": 2 }
],
"codes": ["WINTER20", "NOPE"],
"customer": { "external_ref": "your-user-8817" }
}'A code that does not work is not an error. It comes back in
rejected_codes, spelled as the buyer typed it, with a reason:
{
"rejected_codes": [{ "code": "NOPE", "reason": "not_found" }]
}| Reason | What to tell the buyer |
|---|---|
not_found | No such code. |
inactive | The code has been switched off. |
not_yet_valid | It does not start until later. |
expired | Its window has closed. |
not_applicable | It does not cover anything in this cart. |
currency_mismatch | It is priced in another currency. |
max_uses_reached | It has been fully used. |
per_customer_limit_reached | This customer has already used it. |
An unknown external_ref is authenticated but has customer_id: null.
Per-customer limits cannot be evaluated until a customer row already exists
for that ref. Checkout-session creation does not create that row, so do not
assume a later cart will count; max_uses still applies.
How a use is spent
Every code effect is consumable: it spends something finite, so the engine tracks it in three stages.
Quoted. A preview checks the counts so an exhausted code shows as rejected rather than silently doing nothing — but it reserves nothing and spends nothing. Quote as often as you like.
Reserved at checkout. When a real checkout claims capacity, the code's use is reserved alongside it. That reservation is what stops a "first 100" code from going to 130 people who all had the checkout page open at once.
Committed at issuance. At issuance, commit rechecks that the redemption exists and remains reserved, the code is active and within its validity window, identity and the quoted effect still match, and usage limits still admit it. Reserved and committed uses count toward the limits, so another purchase cannot take this checkout's reserved slot.
A checkout that is abandoned or lapses releases its reservation, and the use returns to the pool.
Checkout covers the sessions this happens inside.
Errors this resource returns
| Code | Status | Type | What it means | What to do |
|---|---|---|---|---|
code_already_exists | 400 | invalid_request_error | A discount code with this name already exists for the organizer. Uniqueness is case-insensitive: `SUMMER` and `summer` are the same code. | Pick another code, or update the existing one. |
invalid_reference | 400 | invalid_request_error | The request referenced an id that does not exist under this organizer — an `event_id`, a `quota_id`, an `item_id`, a `plan_id` (when creating a membership benefit), or a customer named by `id` or `external_ref` in a transfer. | Check the id, and check the `Ticketing-Organizer` header names the tenant that owns it. |
invalid_request | 400 | invalid_request_error | The request body or query failed validation. `param` names the field. | Fix the named field and send the request again. |
not_found | 404 | invalid_request_error | No such object under this organizer. An object belonging to another tenant reads as absent, never as forbidden. | Check the id and the organizer header. |
invalid_request covers a field combination the effect type forbids, a
percent_bps outside (0, 10000], a valid_until not after valid_from, or
a duplicate id in a restriction set, with param naming it. The full list is
the error registry.
Separately, a code that priced a cart can still fail to be reserved when a
checkout session claims it — its last use having gone to someone else. That is
code_not_reservable, and it belongs to checkout rather
than to configuring the code.
Note what is not an error: a code that is unknown, expired, exhausted or
inapplicable. Those are rejected_codes on a successful quote, because a buyer
typing a bad code is not a broken request.
What emits on the activity stream
discount_code.created— on the create, with the full snapshot including both restriction arrays.discount_code.updated— on every accepted patch, withprevious_attributes. Switching a code off is an update, soactiveflips in the diff.
Redemptions have their own vocabulary in the stream, so you can watch a code being spent rather than inferring it from orders. The full type registry lists every current type and its feed scope.
Gotchas
amountis per ticket. Per-cart amounts do not exist.- A code cannot be deleted.
active: falseis the off switch, and the code string stays taken — you cannot recreate it under the same name. - Uniqueness is case-insensitive.
VIPblocksvip. - Best-of-one is the default. Two 10% codes give you 10% off, not 20%: the
better one wins and the other is superseded. Marking both
stackablegives 19%, because the second applies to what the first left. - A superseded code is not spent. Losing the comparison costs the buyer nothing and costs the code nothing.
price_overrideupward does nothing. It is an override, not a price change; the lower of the override and the current price wins.- Money codes must match the cart's currency. A
GBPamount code in aEURcart is rejected, not converted — there is no FX. - Per-customer limits need a customer row that already exists. An unknown
external_refquotes as authenticated withcustomer_id: null, and checkout-session creation does not create the row, so onlymax_usescan bite for that buyer. - Ten codes per request, 64 characters each. Beyond that the request is refused rather than truncated.