> ## Documentation Index
> Fetch the complete documentation index at: https://strapi-suite.littlebox.pt/llms.txt
> Use this file to discover all available pages before exploring further.

# Promotions and discount codes

> Apply discount codes, gifts and store credit, and verify the checkout email.

Automatic promotions apply by themselves on every quote. Discount codes need the customer to type them.

## Apply a Code

`POST /discounts/apply`

Session: checkout. Rate limit: `discount.apply`. The body is the [full cart](https://strapi-suite.littlebox.pt/frontend/guides/ecommerce/cart.md#quote-the-cart) plus `code` (required, up to 40 characters). Strapi prices the cart with the code added, and saves the cart with the code only when its status is `APPLIED` or `AWAITING_SHIPPING`.

```json Request theme={null}
{
  "code": "welcome10",
  "lines": [{ "variantId": 31, "quantity": 2 }],
  "locale": "en",
  "email": null,
  "promotionCodes": [],
  "giftChoices": {},
  "destination": { "country": "PT", "postalCode": "1000-001" },
  "shippingMethod": null
}
```

```json Response 200 theme={null}
{
  "code": "WELCOME10",
  "status": "APPLIED",
  "message": "Code applied.",
  "applied": true,
  "quote": { "lines": [], "totals": {}, "codes": [] }
}
```

`quote` is a full [quote](https://strapi-suite.littlebox.pt/frontend/guides/ecommerce/cart.md#quote-the-cart) (shortened above). With an empty cart, every code answers `CONDITIONS_NOT_MET`, so the answer never reveals whether a code exists. To remove a code, send the cart without it to `POST /cart/quote`. A cart holds up to 5 codes (`400 too_many` on `promotionCodes`).

```ts src/app/(store)/cart/actions.ts (continued) theme={null}
export async function applyCode(code: string) {
  const locale = await getLocale();
  try {
    const result = await withSession("checkout", async (auth) => {
      const cart = await storeFetch<StoredCart>("/cart", { auth });
      return storeFetch<{ code: string; status: string; message: string; applied: boolean; quote: Quote }>(
        "/discounts/apply",
        { method: "POST", auth, body: { ...cartBody(cart, locale), code } },
      );
    });
    revalidatePath("/cart");
    return { ok: true as const, data: result };
  } catch (error) {
    return toActionError(error);
  }
}
```

## Code Statuses

The same public statuses appear in `discounts/apply`, in `quote.codes[].status` and in the `detail` of a `PROMOTION_CODE_INVALID` error.

| Status | Meaning | What to show |
| - | - | - |
| `APPLIED` | The code gives a discount. | Success. |
| `NOT_FOUND` | Unknown, inactive or not started yet. | "This code does not exist." |
| `NOT_ELIGIBLE` | Not for this customer (restricted to other emails, or this email already used it up). | "This code is not available for this order." |
| `EMAIL_NOT_VERIFIED` | The promotion depends on the email (a list of emails or a per customer limit). | Ask for the email and run the [checkout email verification](#checkout-email-verification). |
| `EXPIRED` | The promotion ended. | "This code has expired." |
| `USAGE_LIMIT_REACHED` | The code has no uses left. | "This code has reached its usage limit." |
| `CONDITIONS_NOT_MET` | The cart does not meet the conditions yet (for example a minimum amount). | Keep the code, show the message. |
| `CONFLICT` | It cannot combine with the promotions already applied. Strapi kept the best combination. | Show the message. |
| `NO_BENEFIT` | It gives nothing on this cart. | Show the message. |
| `AWAITING_SHIPPING` | A shipping promotion and no delivery method yet. The code stays in the cart. | "Choose a delivery method." It applies once you quote with a method. |
| `GIFT_UNAVAILABLE` | Its gift is out of stock. Other benefits of the promotion still apply. | "The gift of this code is out of stock." |

## Checkout Email Verification

Some codes need proof that the guest owns the email: Strapi never evaluates a per customer limit or an email list without it, so the API never tells whether an email already bought. The same proof lets a guest place an order with the email of a registered account. A logged in customer never needs it: the account email is already verified.

**1. Send the code**

`POST /checkout/email-verification` with `{ "email": "jane@example.com", "locale": "en" }`. Strapi emails a
6 digit code valid for 10 minutes and answers `202 { "expiresAt": "2026-11-27T10:10:00.000Z" }`.

**2. Confirm the code**

`POST /checkout/email-verification/confirm` with `{ "email": "jane@example.com", "code": "042317" }`. Strapi
answers `200 { "verified": true }` and marks the email verified on this guest session.

**3. Quote again with the email**

Send the cart with `email: "jane@example.com"`. The code status now reflects the real eligibility. Use the same
email in `customer.email` when you place the order.

Session: guest only. With a login session both routes answer `409 ACTION_NOT_AVAILABLE`. Rate limits: `email.send` and `email.confirm`.

| Status | Code | When |
| - | - | - |
| 202 | | Code sent. A new code for the same email keeps the attempts already used. |
| 400 | `invalid_email` | Bad email. |
| 400 | `VERIFICATION_CODE_INVALID` | Wrong or expired code, or another email than the one the code was sent to. |
| 403 | `CUSTOMER_BLOCKED` | The email belongs to a blocked customer. |
| 409 | `VERIFICATION_CONFLICT` | Parallel attempts. Retry. |
| 409 | `ACTION_NOT_AVAILABLE` | Called with a login session. |
| 429 | `VERIFICATION_LOCKED` | 5 wrong codes. `Retry-After` runs until the code expires. Every request on this session waits until then. |
| 502 | `EMAIL_SEND_FAILED` | The email provider failed. Retry later. |
| 503 | `EMAIL_NOT_CONFIGURED` | Email sending is not set up on the store. |

## Gifts (Buy X Get Y)

A "buy X, get a gift" promotion adds its gift **by itself**. Never put the gift in the cart yourself: a gift variant sent as a cart line is an ordinary purchase, charged in full.

* **Gift lines.** When the promotion applies, `quote.lines` has a line with `isGift: true`, already discounted (`total: 0` for a free gift) and with the promotion in `promotionIds`. It follows the cart: buy fewer and it goes away at the next quote.
* **`giftOptions`.** One entry per applied promotion with a gift. `quantity` is the units per gift and `repetitions` is how many gifts the cart earns (buy 4 with "buy 2, get 1" gives 2). `selected` lists the variant of each gift, first to last. `available` tells whether the variant has stock for a gift (the cart's own units of that variant are already taken out).
* **Choosing.** By default each gift is the first variant with stock. To choose, send `giftChoices` in the next quote (Strapi stores it in the cart), in `discounts/apply` and in the order: `{ "9": 42 }` uses that variant for every gift of promotion 9, `{ "9": [41, 42] }` chooses gift by gift (1 to 20 ids). A missing position, a variant the promotion does not offer, or one without stock falls back to the default, so `selected` always shows what the customer gets. Show a choice only when `variants` has more than one entry, and disable the variants with `available: false`.
* **Out of stock.** When the cart meets the promotion but no gift variant has stock, there is no gift line and no `giftOptions` entry. The promotion shows in `unavailableGifts: [{ promotionId, name, code }]` so you can say "the gift is out of stock". Other benefits of that promotion still apply.

```json giftOptions entry theme={null}
{
  "promotionId": 9,
  "benefitIndex": 0,
  "quantity": 1,
  "repetitions": 2,
  "selected": [41, 42],
  "selectedVariantId": 41,
  "variants": [
    { "variantId": 41, "sku": "LSS-MUG-WHT", "name": "Littlebox Strapi Suite Mug", "option": "White", "imageUrl": "/uploads/mug_white.jpg", "available": true },
    { "variantId": 42, "sku": "LSS-MUG-BLK", "name": "Littlebox Strapi Suite Mug", "option": "Black", "imageUrl": "/uploads/mug_black.jpg", "available": true }
  ]
}
```

## Store Credit

A store credit is a 12 character code bound to an email. The customer can use it at checkout without verifying the email: the code itself is the secret.

`POST /store-credit/check`

Session: checkout. Rate limit: `storeCredit.check`.

```json Request theme={null}
{ "code": "AB12CD34EF56", "email": "jane@example.com" }
```

```json Response 200 theme={null}
{ "balance": 1500, "expiresAt": "2027-06-30T23:59:59.000Z" }
```

For a logged in customer, Strapi checks the code against the account email and ignores `email`. A credit of another email answers the same as an unknown code. Errors: `400` on `code` with `STORE_CREDIT_NOT_FOUND`, `STORE_CREDIT_VOID`, `STORE_CREDIT_EXPIRED` or `STORE_CREDIT_EMPTY`; `400 invalid_email` on `email`.

To use it, send `storeCreditCode` with the order. Strapi pays `min(balance, total)` from the credit. The order answer's `due` tells what is left to pay. When `due` is `0`, there is nothing to pay on Stripe.


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