Create discount codes

In this guide

Keyseal creates your discount codes at Stripe, on your account, and tracks them: who used which code, for which sale and which licence. You do not need the Stripe Dashboard. This guide shows how to give licences to testers, run a dated promotion, send a link that applies the code, and what Stripe does not allow.

A discount sets what the code grants: a percentage (1 to 100) or a fixed amount in one currency, the products it covers and, for a subscription, how long it lasts. A code is the text a buyer uses; it belongs to a discount. Discounts and codes belong to one organization and one environment: a test code does not work in live.

Everything needs the admin role (or an API key with the admin right), reading included: a 100% code is worth a licence.

Before you start

  1. Stripe is connected in the environment (Stripe guide, in French) and the catalogue is sent to Stripe: a discount only covers products already at Stripe.
  2. The restricted key has two more rights: Coupons: write (coupon_write) and Promotion codes: write (promotion_code_write). They are optional: without them, connecting and selling work as before, and the first code you create answers which rights to add (stripe_permissions_missing, listed in missing). The console names them too and links to the Stripe settings. Add them to the existing key in the Dashboard; you do not need a new one.
  3. Start in test. A test code costs nothing and touches no real buyer.

Codes for testers

The simplest way: a series of 100% codes, single use, one per tester.

In the console, open Discount codes, then Create. Choose 100%, the products, the duration (see below), then a series (the default): a prefix such as TESTERS, and how many codes (50 at most per request). Keyseal makes TESTERS-XXXXXXXX with no ambiguous characters, each usable once. The note says who the codes are for: a first name or a reference, nothing more (see Personal data).

From the discount's page, copy one code, all the usable codes, or the buy link of each code. Send each tester a link: there is nothing to type.

With the CLI:

keyseal discounts create --name "Testers" --product <product-id> --percent-off 100 --duration forever
keyseal discounts codes create dsc_… --series TESTERS --count 5 --note "Autumn beta"

Or through an agent: discounts_create, then discounts_codes_create (agents.md, in French).

A code's page then lists its uses: the date, the amount taken off, the customer, the sale and the licence issued.

For testers on a subscription, choose the duration "forever". With "once" (the default), a 100% code only clears the first invoice: the next one is not paid, and the subscription ends. With "forever", every invoice is 0 and the licence renews. "N months" (repeating) discounts the first N invoices.

Warning: with no card, the subscription stops. A subscription bought with a code sends payment_method_collection=if_required: when the discount covers the whole first invoice (100% "once" or "N months", or a large enough fixed amount), Stripe collects no card. The first invoice at full price then fails for lack of a payment method, and the subscription ends. For discounts that do not last forever, warn the buyer, or prefer a percentage below 100%, which asks for the card.

A series that stops half way (Stripe unreachable) returns the codes already made and says why the rest is missing: ask for them again with a new request, with no clash. A code left "pending" (Stripe's answer was lost) is resumed by activating it (PATCH with active: true, or the console button). Merely reading a code never creates it at Stripe.

A dated promotion

Example: 30% off for Black Friday.

  1. Create the discount "Black Friday" at 30%, on the products you want. For a subscription, the duration says how many invoices are discounted.
  2. Create the chosen code BF30: 3 to 40 characters (letters, digits, hyphens), kept in capitals. Give it an end date (with a time zone) and, if you like, a number of uses.
keyseal discounts create --name "Black Friday" --product <product-id> --percent-off 30
keyseal discounts codes create dsc_… --code BF30 --expires-at 2026-12-01T00:00:00Z

Stripe has no start date. For a promotion that starts on a given day, create the code inactive (--inactive, or the console checkbox), then activate it on the day: keyseal discounts codes update dco_… --active. After its end date a code is "expired" and cannot be activated again.

The code works typed by the buyer on the payment page (Stripe's input field) and applied by a link.

https://<url>/b/{organization}/{plan}?code=BF30
https://<url>/b/{organization}/{plan}?code=BF30&environment=test

A code's page offers this link for each plan, ready to copy. The code is applied in advance: the payment page shows the discounted price and has no input field. The keyseal.js button passes the link on as it is (checkout guide).

Only codes created in Keyseal, in this organization and environment, work by link. Without ?code=, nothing changes: the payment page has its input field, and codes created in the Stripe Dashboard keep working.

What the buyer sees

  • A good code: the Stripe payment page, with the discount. It carries the discount's name: choose one the buyer will understand ("Black Friday").
  • A 100% code: no card for a one-time purchase. Stripe still asks for the email, name and address. The sale is recorded at 0, with its invoice, and the licence is issued as for a paid purchase. A subscription whose first amount is 0 asks for no card either.
  • A code that cannot be used (unknown, inactive, expired, used up, for another product, refused by Stripe): a "This code is no longer valid" page (status 410), the same whatever the reason, without showing the code. It offers a "Buy at the regular price" button. Keyseal never opens a session at full price without that click.
  • A free plan ignores the code.
  • A code typed on the payment page that is not valid is refused by Stripe itself.

The use is recorded when Stripe notifies the purchase. If recording it fails, the licence is issued anyway: the buyer is never penalised. The sale (GET /orders/{id}) shows the discount applied: id, name and amount taken off, never the code's text (webhooks guide).

What Stripe imposes

  • A code applies to every product of its discount, so to every plan of those products, renewals included. It cannot target one plan. A product added later is not covered: create another discount.
  • Nothing changes after creation except a discount's name, a code's note and its activation. The text, end date, number of uses, amount, duration and products are fixed. To change one, deactivate the code and create another. Nothing is deleted: the history stays.
  • No start date (see above).
  • A code's text is unique across the whole Stripe account, case-insensitively. If Rayonne, AudiGEO or another tool shares your account, a text already taken is refused (discount_code_taken).
  • A single-use code becomes inactive once used. An expired or used-up code cannot be activated again.
  • A fixed amount only applies in its currency: a plan in another currency refuses the code.
  • The code and the link work with Managed Payments (measured in test mode, version 2026-10-28.endive).

Disconnecting Stripe

Discounts stay fixed on the old products. Disconnecting Stripe therefore first deactivates at Stripe the active codes made in Keyseal, then discounts and codes become "unavailable" for good (their history stays). After you connect again, create new ones: the same code text is free again.

  • If a code cannot be deactivated (Stripe unreachable, dead key, right removed), the disconnection is refused: 409 stripe_discount_codes_active, with the codes listed in codes.
  • A forced disconnection (?force=true) goes ahead and answers 200 with {"disconnected": true, "codes_still_active": […]}: those codes may still work at Stripe. Deactivate them by hand in the Stripe Dashboard. The console shows this list; note it down before leaving the page.
  • Nothing is recreated automatically.

Personal data

A code's note ("for whom") may hold personal data. Write only a first name or a reference. The note of a code used by a person follows their rights: it is exported with their record, cleared with their contact details, hidden while their processing is restricted. The note of a shared or never-used code is handled by hand: edit it or clear it (discounts_codes_update). See docs/en/data-subject-rights.md.

A code's text is never written to a log or an outgoing webhook, and it is not exported: like a licence key, it may be worth something. Your proxy's access log must mask code= (see docs/en/deploy.md).

Common errors

Code HTTP Meaning
stripe_permissions_missing 422 the key lacks coupon_write or promotion_code_write (missing)
discount_product_not_on_stripe 409 a product is not at Stripe yet: sync the catalogue
discount_code_taken 409 this text already exists in Keyseal or on the Stripe account
discount_unavailable 409 the code is expired, used up, or Stripe is disconnected or changed
publisher_suspended 403 a suspended publisher cannot create or activate codes
stripe_discount_codes_active 409 on disconnection: some codes cannot be deactivated

Each route is described in the management API guide, in French.

All guides