> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bachs.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Money is always a decimal string at the currency's precision (for example "29.00"), paired with an ISO 4217 currency field. Never use minor units.
> Build against the sandbox first: base URL https://sandbox-api.bachs.io with sk_sandbox_ keys. Production is https://api.bachs.io with sk_live_ keys; going live is a key swap.
> Treat webhooks (for example collection.succeeded) as the source of truth for fulfilment, never client-side events or redirects.
> Subscriptions are created by completing a checkout for a recurring product. There is no direct create-subscription endpoint.
> IDs carry resource prefixes (cust_, prod_, sub_, chk_, inv_, ref_) and timestamps are ISO 8601 UTC.

# Discounts and promo codes

> Take a percent or a fixed amount off a checkout, and give buyers codes like LAUNCH20 to type on the checkout page.

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.

> [!WARNING]
>
> 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](#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](https://docs.bachs.io/api-reference/permissions.md).
* To create checkouts, an API key with `payments:write`. See [Accept a payment with Checkout](https://docs.bachs.io/guides/checkout/checkout-sessions.md).

## 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](#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](https://mintcdn.com/bachs/Ps43lrWL7dIY7C8Y/images/product/discounts-create.webp?fit=max\&auto=format\&n=Ps43lrWL7dIY7C8Y\&q=85\&s=1a19120ebb2f511dc9724f360c46bf6c)

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)](https://mintcdn.com/bachs/Ps43lrWL7dIY7C8Y/images/product/discounts-panel.webp?fit=max\&auto=format\&n=Ps43lrWL7dIY7C8Y\&q=85\&s=362c2fd4d19fb5c5c96a7703a0569f68)

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](https://docs.bachs.io/sdks/node.md#not-in-the-sdk-yet) and [Python](https://docs.bachs.io/sdks/python.md#not-in-the-sdk-yet) 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.

```bash Request theme={"dark"}
curl https://sandbox-api.bachs.io/v1/discounts \
  -H "Authorization: Bearer $BACHS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Launch week",
    "percent_off": "20"
  }'
```

```json Response theme={"dark"}
{
  "id": "disc_4fG7hK2mPq9RtW3x",
  "organization_id": "acct_7KpQ2mNv4XbR9dLc",
  "name": "Launch week",
  "percent_off": "20.00",
  "amount_off": null,
  "currency": null,
  "currency_options": {},
  "created_at": "2026-11-26T09:00:00Z",
  "updated_at": "2026-11-26T09:00:00Z"
}
```

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.

```bash Request theme={"dark"}
curl https://sandbox-api.bachs.io/v1/promo-codes \
  -H "Authorization: Bearer $BACHS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "discount_id": "disc_4fG7hK2mPq9RtW3x",
    "code": "launch20",
    "expires_at": "2026-12-05T23:59:59Z",
    "max_redemptions": 100,
    "max_redemptions_per_customer": 1
  }'
```

```json Response theme={"dark"}
{
  "id": "promo_8Tx2Lm5Nq7WzKc4D",
  "organization_id": "acct_7KpQ2mNv4XbR9dLc",
  "discount_id": "disc_4fG7hK2mPq9RtW3x",
  "code": "LAUNCH20",
  "active": true,
  "first_time_transaction": false,
  "max_redemptions_per_customer": 1,
  "starts_at": null,
  "expires_at": "2026-12-05T23:59:59Z",
  "max_redemptions": 100,
  "times_redeemed": 0,
  "created_at": "2026-11-26T09:05:00Z",
  "updated_at": "2026-11-26T09:05:00Z"
}
```

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.

```bash Request theme={"dark"}
curl -X PATCH https://sandbox-api.bachs.io/v1/promo-codes/promo_8Tx2Lm5Nq7WzKc4D \
  -H "Authorization: Bearer $BACHS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "active": false }'
```

```json Response theme={"dark"}
{
  "id": "promo_8Tx2Lm5Nq7WzKc4D",
  "organization_id": "acct_7KpQ2mNv4XbR9dLc",
  "discount_id": "disc_4fG7hK2mPq9RtW3x",
  "code": "LAUNCH20",
  "active": false,
  "first_time_transaction": false,
  "max_redemptions_per_customer": 1,
  "starts_at": null,
  "expires_at": "2026-12-05T23:59:59Z",
  "max_redemptions": 100,
  "times_redeemed": 12,
  "created_at": "2026-11-26T09:05:00Z",
  "updated_at": "2026-11-28T14:20:00Z"
}
```

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](https://docs.bachs.io/guides/pagination.md).

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.

> [tab] Let the buyer type a code
>
> ```bash Request theme={"dark"}
> curl https://sandbox-api.bachs.io/v1/checkout-sessions \
>   -H "Authorization: Bearer $BACHS_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "product_cart": [
>       { "product_id": "prod_abc123", "quantity": 1 }
>     ],
>     "allow_promo_codes": true,
>     "success_url": "https://shop.example.com/thanks"
>   }'
> ```
>
> ```json Response theme={"dark"}
> {
>   "checkout_id": "chk_2N3o4P5q6R7s8T9u",
>   "status": "open",
>   "amount": "40.00",
>   "subtotal": "40.00",
>   "discount": null,
>   "currency": "USD",
>   "checkout_url": "https://checkout.bachs.io/c/V8xQ2mZpLj9RfTa"
> }
> ```
>
> There is no discount yet. The buyer adds one on the hosted page.

> [tab] Apply a discount yourself
>
> ```bash Request theme={"dark"}
> curl https://sandbox-api.bachs.io/v1/checkout-sessions \
>   -H "Authorization: Bearer $BACHS_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "product_cart": [
>       { "product_id": "prod_abc123", "quantity": 1 }
>     ],
>     "discount_id": "disc_4fG7hK2mPq9RtW3x",
>     "success_url": "https://shop.example.com/thanks"
>   }'
> ```
>
> ```json Response theme={"dark"}
> {
>   "checkout_id": "chk_2N3o4P5q6R7s8T9u",
>   "status": "open",
>   "amount": "32.00",
>   "subtotal": "40.00",
>   "discount": {
>     "discount_id": "disc_4fG7hK2mPq9RtW3x",
>     "promo_code_id": null,
>     "code": null,
>     "name": "Launch week",
>     "amount_off": "8.00"
>   },
>   "currency": "USD",
>   "checkout_url": "https://checkout.bachs.io/c/V8xQ2mZpLj9RfTa"
> }
> ```
>
> The discount is on the checkout from the start. To apply a code instead, send `promo_code_id`. Then `discount.code` and `discount.promo_code_id` are filled in.

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.

> [!NOTE]
>
> 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](https://mintcdn.com/bachs/Ps43lrWL7dIY7C8Y/images/product/discounts-checkout-box.webp?fit=max\&auto=format\&n=Ps43lrWL7dIY7C8Y\&q=85\&s=da908334f6b9b382df9de84d6aeca4d4)

* 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](#errors).
* 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](https://mintcdn.com/bachs/Ps43lrWL7dIY7C8Y/images/product/discounts-checkout-applied.webp?fit=max\&auto=format\&n=Ps43lrWL7dIY7C8Y\&q=85\&s=91f2436f3b627e099fd5d4e64b4f1817)

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`.

> [!NOTE]
>
> 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](https://docs.bachs.io/guides/products/local-pricing.md)), 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.

## Payment links

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](https://mintcdn.com/bachs/Ps43lrWL7dIY7C8Y/images/product/discounts-payment-link-switch.webp?fit=max\&auto=format\&n=Ps43lrWL7dIY7C8Y\&q=85\&s=183618fdd443e8fc2ef92460eca5f14f)

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`](https://docs.bachs.io/guides/webhooks/events/checkout-completed) webhook tells you which code, and how much it took off:

```json checkout.completed theme={"dark"}
{
  "id": "evt_3c9d1e7a5b2f4806",
  "type": "checkout.completed",
  "created_at": "2026-11-26T10:15:00.000000+00:00",
  "organization_id": "acct_7KpQ2mNv4XbR9dLc",
  "data": {
    "checkout_id": "chk_9fK2mQ7vXa4BnT6R",
    "status": "completed",
    "mode": "payment",
    "payment_status": "paid",
    "amount": "15.00",
    "subtotal": "20.00",
    "currency": "USD",
    "discount": {
      "discount_id": "disc_4Hq8Zr2Vn6Lp",
      "promo_code_id": "promo_8Tx2Lm5Nq7WzKc4D",
      "code": "SAVE25",
      "name": "Launch",
      "amount_off": "5.00"
    }
  }
}
```

You can also find out here:

* **Webhooks.** The [`checkout.completed`](https://docs.bachs.io/guides/webhooks/events/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`](https://docs.bachs.io/guides/webhooks/events/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](https://docs.bachs.io/errors.md).

These come from the discount and promo code endpoints:

| `error_code` | Status | When |
| - | - | - |
| `DISCOUNT_NOT_FOUND` | 404 | No discount with that ID on your account. Also returned by checkout creation for an unknown `discount_id`. |
| `INVALID_DISCOUNT` | 400 | The discount's settings break a rule. `detail` says which, such as "Set exactly one of percent\_off and amount\_off" or "amount\_off needs a currency". |
| `PROMO_CODE_NOT_FOUND` | 404 | No promo code with that ID on your account. Also returned by checkout creation for an unknown `promo_code_id`. |
| `INVALID_PROMO_CODE` | 400 | The code's settings break a rule. `detail` says which, such as "expires\_at must be in the future". |
| `PROMO_CODE_TAKEN` | 409 | Another active code already uses this text. |
| `VALIDATION_ERROR` | 400 | A checkout request set more than one of `discount_id`, `promo_code_id` and `allow_promo_codes`, or a field has the wrong type. |

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.

| `error_code` | Status | Message | When |
| - | - | - | - |
| `PROMO_CODE_NOT_VALID` | 400 | This code isn't valid. | The code does not exist, is turned off, or has not started yet. One message for all three, so the box can't be used to find out which codes exist. |
| `PROMO_CODE_EXPIRED` | 400 | This code has expired. | Past its `expires_at`. |
| `PROMO_CODE_USED_UP` | 400 | This code has been used up. | It reached `max_redemptions`. |
| `PROMO_CODE_NOT_APPLICABLE` | 400 | This code can't be used on this order. | A fixed amount with no amount in the checkout's currency, a price of zero, or a discount that rounds to nothing. |
| `PROMO_CODE_ALREADY_USED` | 400 | You've already used this code. | This buyer reached `max_redemptions_per_customer`. Checked when the buyer pays. |
| `PROMO_CODE_FIRST_TIME_ONLY` | 400 | This code is only for first-time customers. | The code has `first_time_transaction` and this buyer has paid you before. Checked when the buyer pays. |
| `SUBSCRIPTION_DISCOUNTS_NOT_SUPPORTED` | 400 | Subscription checkouts don't take discount codes yet. | The checkout has a recurring product. |
| `PROMO_CODES_NOT_ALLOWED` | 400 | This checkout doesn't take codes. | A code was typed on a checkout created without `allow_promo_codes`. |
| `DISCOUNT_LOCKED_WHILE_PAYING` | 400 | Finish or cancel the payment in progress before changing the code. | The buyer tried to change the code or the cart while a payment was under way. |
| `PAYMENT_LINK_PROMO_CODES_ON_SUBSCRIPTION` | 400 | Promo codes don't work on subscription products yet. Turn promo codes off for this link, or use a one-time product. | You turned on promo codes for a payment link that sells a subscription product. |

## Next steps

* [Accept a payment with Checkout](https://docs.bachs.io/guides/checkout/checkout-sessions.md): create the checkout a discount goes on.
* [The checkout session object](https://docs.bachs.io/api-reference/checkout-sessions/object.md): every field a checkout returns.
* [checkout.completed](https://docs.bachs.io/guides/webhooks/events/checkout-completed.md): the webhook that tells you a code was used.
* [Local pricing](https://docs.bachs.io/guides/products/local-pricing.md): set prices in other currencies.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.