Skip to main content
In this guide you’ll make a discount, give it a promo code, and put it on a checkout. By the end, a buyer can type LAUNCH20 on the hosted checkout page and pay less, and you can see which code they used.

Discounts and promo codes

There are two objects. If you have used coupons on other payment platforms, the model will feel familiar.
  • A discount says what the buyer gets: a percent off, or a fixed amount off. It always comes off the whole order. Its ID starts with discount_.
  • A promo code is the text a buyer types to get a discount, such as LAUNCH20. It also holds the rules: when the code works, how many times it can be used, and who can use it. Its ID starts with promo_.
One discount can have many promo codes. For example, one “20% off” discount can have a LAUNCH20 code that ends on Friday and a FRIENDS20 code that only works once per buyer. A discount never changes after you make it. So every code on it always gives the same discount. The buyer pays the lower price. You are paid for what the buyer pays, not for the full price.
Discounts work on one-time checkouts only. A checkout with a recurring product does not take a discount yet. See What is not supported yet.

Before you start

  • To make discounts and codes with the API, an API key with the discounts:write permission. To read them, discounts:read. See Permissions.
  • To create checkouts, an API key with payments:write. See Accept a payment with Checkout.

Make a discount in the dashboard

1

Open the Discounts tab

Go to Products and open the Discounts tab. Click Create discount.
2

Say what the buyer gets

Give the discount a Name, such as “Launch week”. Buyers see the name when you put the discount on a checkout without a code.Under Discount, pick one:
  • Percent: enter the Percent off.
  • Fixed amount: enter the Amount off and its currency. To set the amount in more currencies, click Add a price in another currency. See Other currencies.
3

Add promo codes

Type the code under Code, such as LAUNCH20. For each code you can also set:
  • Ends on a date: the last day the code works. It works until the end of that day, in your own time.
  • Limit how many times it can be used: the total number of uses, for all buyers together.
  • Once per customer: each buyer can use the code once.
  • New customers only: only buyers who have never paid you before.
You can add more codes with Add another code, or add none and add them later.
4

Create it

Click Create discount. The discount and its codes are saved together. If any code can’t be saved, nothing is saved. When the problem is a code whose text another active code already uses, the form marks that code.
The Create a discount form: Launch, 25 percent off, the code LAUNCH25 limited to 100 uses and once per customer, with a preview of the terms and the line the buyer sees at checkout
The Discounts tab lists every discount with its codes and how many times they were used. Open a discount to see each code’s status and uses. From there you can Add code, or use a code’s menu to Turn off or Turn on the code.
A discount open on the Discounts tab: Launch, 25% off, with the codes LAUNCH25 (Active, used 37 of 100), NEWSLETTER (Active, new customers only) and EARLYBIRD (Off)
Each code shows one of these statuses:
  • Active: buyers can use it now.
  • Scheduled: it has a start time that has not come yet.
  • Expired: its end date has passed.
  • Used up: it has reached its limit of uses.
  • Off: you turned it off.
The dashboard form does not set a start time, or a per-buyer limit above one. To set those, make the code with the API.

Make a discount with the API

The examples use the sandbox, so no real money moves. The Node.js and Python SDKs don’t have discounts yet, so the examples are cURL only.
1

Create the discount

Send either percent_off, or amount_off with currency. Not both.
The rules for a discount:
  • name: 1 to 255 characters.
  • percent_off: above 0 and at most 100, with up to 2 decimal places. 12.5 means 12.5% off.
  • amount_off: above 0, as a decimal string, with no more decimal places than its currency has. It needs a currency.
  • currency_options: only with amount_off. The fixed amount in other currencies, such as {"NGN": "12000.00"}. Don’t repeat the main currency here.
  • Each currency must be one you can price a checkout in. Crypto currencies are not accepted.
2

Create a promo code for it

Pass the discount’s ID and the code buyers will type. Every other field is optional.
The fields of a promo code:
  • code: what the buyer types. 3 to 64 characters: letters, digits, - or _. Buyers can type it in any case. It is saved in capital letters, so launch20 becomes LAUNCH20.
  • starts_at: the code does not work before this time.
  • expires_at: the code stops working at this time. It must be in the future, and after starts_at.
  • max_redemptions: the total number of uses, for all buyers together.
  • max_redemptions_per_customer: how many times one buyer can use the code.
  • first_time_transaction: when true, only buyers who have never paid you before can use the code.
Only one of your active codes can use a given text, in any case. A second active LAUNCH20 is refused with PROMO_CODE_TAKEN. A code you turned off does not block the text.
3

Turn a code off or on

PATCH /v1/promo-codes/{id} takes only active. Turning a code off stops new buyers from using it. It does not change past uses.
Turning a code back on fails with PROMO_CODE_TAKEN if another active code now uses its text.
To read them back:
  • GET /v1/discounts/{id} and GET /v1/promo-codes/{id} return one object.
  • GET /v1/discounts and GET /v1/promo-codes list them, newest first. They use limit and cursor like other lists. See Pagination.
The lists have no filters. To find the codes of one discount, list the codes and match on discount_id. You can’t delete a discount or a promo code. Turn the code off instead.

Put a discount on a checkout

POST /v1/checkout-sessions takes three new fields. Send at most one of them. Sending two is refused with a 422 VALIDATION_ERROR.
  • allow_promo_codes: true shows the buyer a box on the hosted page to type a code.
  • promo_code_id: you apply a code yourself. Its rules and limits still apply.
  • discount_id: you apply a discount yourself, with no code. It has no limits and counts no uses.
There is no discount yet. The buyer adds one on the hosted page.
In the response:
  • amount is what the buyer pays, after the discount.
  • subtotal is the price before the discount. It is the same as amount when there is no discount.
  • discount is null when there is none. subtotal minus discount.amount_off is amount.
When you apply a discount or code yourself, the buyer does not get a code box and can’t take the discount off.
A code you apply with promo_code_id is checked again when the buyer pays. If it has expired or been used up by then, or this buyer has already used it, or it is for new customers and this buyer has paid you before, the buyer sees why and can remove the code to pay the full price. To give a discount with no such checks, use discount_id.

What the buyer sees

When you set allow_promo_codes, the order summary on the hosted page shows Add promo code under the items. The buyer clicks it, types the code and applies it.
The hosted checkout with the promo code box open in the order summary, under the items
  • If the code works, the discount line shows the code, the amount it takes off, and a button to remove it. The total and the pay button drop to the new price.
  • If it doesn’t, the buyer sees why under the box, for example “This code has expired.” The messages are in the errors table.
  • The buyer can remove the code, or type another one. A new code replaces the old one. A checkout holds one code at most.
  • When you applied a discount without a code, the line shows the discount’s name instead, and the buyer can’t remove it.
The hosted checkout with SAVE25 applied: the discount line shows the code and minus 5.00, and the total is 15.00
The hosted page does this through its own calls. You don’t call them. A few more things can happen while the checkout is open:
  • The buyer changes the cart. The discount is worked out again on the new cart. If the code no longer fits, it is taken off and the buyer sees the full price.
  • A payment is under way. The code can’t change until that payment finishes or is cancelled.
  • The discount takes the whole price. A 100% discount, or a fixed amount equal to or above the price, makes the checkout free. It completes with no payment step. The checkout.completed webhook has payment_status: "no_payment_required" and no charge.

Limits and how uses are counted

Only promo codes count uses. A discount you apply with discount_id has no limits. A code’s times_redeemed counts its uses. Here is when it changes:
  • The buyer starts to pay. A use is taken, before any money moves. times_redeemed goes up by one now.
  • The payment succeeds. The use stays.
  • A payment fails and the buyer tries again. The same checkout keeps the same use. It is not counted twice.
  • The buyer takes the code off or changes it. The use is given back.
  • The checkout expires or is cancelled without a payment. The use is given back.
  • You refund the payment. The use is not given back.
So a code can show as used up while a buyer is still paying. If that buyer doesn’t finish, the use comes back after their checkout expires. Checkouts expire after 60 minutes unless you set expires_in_minutes.
Some payments are slow, such as bank transfers. If one arrives after its checkout expired and gave its use back, the use is taken again, because the buyer got the discount. In that case times_redeemed can go past max_redemptions.

When each rule is checked

When the buyer applies a code, we check that it is turned on, has started, has not expired and is not used up. When the buyer pays, we check all of that again. We also check the rules that depend on who the buyer is:
  • max_redemptions_per_customer: how many times this buyer has used the code. This counts paid uses, and uses held by the buyer’s other open checkouts.
  • first_time_transaction: whether this buyer has paid you before.
So a code can be accepted when it is typed and refused when the buyer pays. If the buyer typed the code, they can take it off and pay the full price.

Who counts as the same buyer

Two uses belong to the same buyer if any one of these matches:
  • the same customer
  • the same email, ignoring capital letters and anything after a +. So ada+shop@example.com and Ada@example.com are the same buyer.
  • for some card payments, the same card
Only paid payments count as “paid you before”. A declined payment does not.

Other currencies

A percent discount takes the same percent off every price, in every currency. A fixed amount discount works on a checkout priced in its currency, or in a currency in its currency_options. On a checkout priced in any other currency, the code is refused with “This code can’t be used on this order.” If your product also has prices in other currencies (see Local pricing), each of those prices comes down too:
  • If the discount has an amount in that currency, that amount comes off.
  • If not, the price comes down by the same share as the main price.
For example, a product costs 40.00 USD and has a local price of 60000.00 NGN. A discount takes 10.00 USD off, which is a quarter of the price.
  • With no NGN amount, the NGN price drops by a quarter, to 45000.00 NGN.
  • With "currency_options": {"NGN": "12000.00"}, the NGN price drops to 48000.00 NGN.
If the buyer pays in a currency you did not set a price for, the discounted price is converted. Amounts are always rounded down to the currency’s smallest unit, so the buyer never gets more off than the discount says. A fixed amount never takes the price below zero. A discount that would take nothing off, after rounding, is refused. A payment link can offer the code box too. In the dashboard, tick Let customers use promo codes when you create or edit the link. It is off by default.
The Create a payment link page with Let customers use promo codes ticked
Every checkout the link opens then shows Add promo code, the same as a checkout created with allow_promo_codes: true. You can’t turn it on for a link that sells a subscription product. If a link’s product becomes a subscription later, its checkouts open without the code box. GET /v1/payment_links/{id} returns the setting as allow_promo_codes.

Know when a code was used

When a buyer pays with a code, the checkout.completed webhook tells you which code, and how much it took off:
checkout.completed
You can also find out here:
  • Webhooks. The checkout.completed event has data.subtotal and data.discount, with the code the buyer used, its promo_code_id, and the amount_off. checkout.expired has them too.
  • The checkout. GET /v1/checkout-sessions/{checkout_id} returns subtotal and discount.
  • Receipts. The buyer’s receipt has a “Discount (LAUNCH20)” line between the items and the amount paid, so the lines add up. With no code, it shows the discount’s name.
  • Use counts. times_redeemed on GET /v1/promo-codes/{id}, and the Uses column on the Discounts tab.

What is not supported yet

  • Subscriptions. A checkout with any recurring product is refused with SUBSCRIPTION_DISCOUNTS_NOT_SUPPORTED, whichever of the three fields you send.
  • Discounts for some products only. A discount always comes off the whole order.
  • A minimum order amount.
  • Editing a discount. To change what buyers get, make a new discount with new codes, and turn the old codes off.
  • Deleting. Turn a code off instead.
  • More than one discount on a checkout.
  • Filters on the lists. You can’t list the codes of one discount, or look a code up by its text.

Errors

Every error has the usual shape, with a stable error_code and a detail message. See Errors. These come from the discount and promo code endpoints: These are refusals. The buyer sees the message on the hosted page. Your API call gets the same error when you create a checkout with a discount that is refused.

Next steps