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

# Discounts

> Create promotional codes to drive conversions, run campaigns, and reward customers with percentage discounts across one‑time and subscription purchases.

<Frame>
  <img src="https://mintcdn.com/dodopayments/mOQO5ej_lx0yH9p-/images/discount-codes/discount-code-cover.png?fit=max&auto=format&n=mOQO5ej_lx0yH9p-&q=85&s=57f1a644801ddc5efc506b50541eaaba" alt="Discount codes overview cover" style={{ maxHeight: '500px', width: 'auto' }} width="1200" height="630" data-path="images/discount-codes/discount-code-cover.png" />
</Frame>

Discount codes let you run targeted promotions and incentives. Create percentage-based discounts, set limits and expirations, restrict to products, and apply them at checkout.

<CardGroup cols={2}>
  <Card title="Checkout Sessions" icon="cart-shopping" href="/developer-resources/checkout-session">
    Apply one or more stacked codes during hosted checkout with `discount_codes` and UI controls.
  </Card>

  <Card title="Get Discount" icon="code" href="/api-reference/discounts/validate-discount">
    Retrieve a discount by its ID to inspect its status and restrictions.
  </Card>

  <Card title="Get Discount by Code" icon="tag" href="/api-reference/discounts/get-discount-by-code">
    Look up and validate a discount using its code name (e.g., "SAVE20").
  </Card>

  <Card title="Create Discount (API)" icon="code" href="/api-reference/discounts/create-discount">
    Programmatically create new discount codes.
  </Card>

  <Card title="List & Update Discounts" icon="code" href="/api-reference/discounts/list-discounts">
    Browse and manage existing discounts; update or delete as needed.
  </Card>

  <Card title="Plan Change Discounts" icon="arrows-rotate" href="/api-reference/subscriptions/change-plan">
    Apply discount codes when upgrading or downgrading subscription plans.
  </Card>
</CardGroup>

## What Are Discount Codes?

Discount codes are promotional tokens that reduce order totals at checkout. Use them for seasonal campaigns, first-purchase incentives, win-back offers, or negotiated B2B pricing.

Codes are percentage-based (e.g., 15% off) or flat-amount (e.g., \$5 off). You can stack up to 20 codes per checkout, payment, or subscription, so a customer can redeem both a welcome offer and a campaign code in the same transaction. Restrict codes to specific products, limit how many times each customer can use them, set expiration dates, and control who's eligible to redeem.

## Key Benefits

* **Flexible discounts**: Percentage-based or flat-amount discounts
* **Stackable codes**: Apply up to 20 codes per checkout, payment, or subscription
* **Targeted control**: Restrict by product, subscription cycles, and customer eligibility
* **Campaign governance**: Scheduled start dates, expiration dates, overall and per-customer usage limits
* **Per-currency pricing**: Set the flat deduction, amount cap, and minimum subtotal per currency

## Creating Discount Codes

Create discount codes in your Dodo Payments dashboard, then apply them in hosted checkout or via API.

<Frame>
  <img src="https://mintcdn.com/dodopayments/Rh05LkBeJE32G3qq/images/discount-codes/discount-details.png?fit=max&auto=format&n=Rh05LkBeJE32G3qq&q=85&s=895a9dbe429c2ae57ecc1b317dd2b10d" alt="Discounts list in the Dodo Payments dashboard showing existing discount codes" style={{ maxHeight: '500px', width: 'auto' }} width="3008" height="1626" data-path="images/discount-codes/discount-details.png" />
</Frame>

### Dashboard Setup

* **Discount Name** (required): Internal label for the dashboard.
* **Code** (required): The string customers enter at checkout. Generate a random code or enter your own (minimum 3 characters, uppercased automatically).
* **Type** (required): **Percentage** (a percent off) or **Amount** (a flat deduction).
* **Amount** (required): For percentage, the percent off in the dashboard (e.g., `15` for 15%). Over the API, the same value is in basis points (`1500`). For amount, the flat deduction in the code's default currency.
* **Start Date** (optional): Schedule the code to activate on a future date. Leave empty to activate immediately.
* **Expiration Date** (optional): Date after which the code is no longer redeemable.
* **Usage Limit** (optional, under **Advanced**): Maximum total redemptions across all customers. A [multi-subscription cart](/developer-resources/checkout-session#multi-subscription-cart) counts as one redemption.
* **Per-Customer Usage Limit** (optional, under **Advanced**): Maximum redemptions by any single customer. Must be less than or equal to the overall usage limit when both are set.
* **Customer Eligibility** (optional): Restrict who may redeem — all customers, first-time customers, existing customers, or a hand-picked list.
* **Currency Options** (optional): The discount amount for each currency you sell in. See [Per-Currency Options](#per-currency-options).
* **Product Restriction** (optional): Limit the code to specific products.
* **Subscription Cycle Limit** (optional, under **Advanced**): Number of billing cycles the discount applies to. Leave empty for indefinite.
* **Preserve on Plan Change** (optional): Keep the discount active when a subscription changes plans (`preserve_on_plan_change`).
* **Metadata** (optional): Attach custom key–value pairs for internal tracking.
* **Require a minimum order value** (optional, under **Advanced**): Minimum cart subtotal (per currency) for the code to apply.

The form shows a running **Summary** of the code you're building in a side panel. Switch to **Preview** to see how the discount appears at checkout:

<Frame>
  <img src="https://mintcdn.com/dodopayments/28D42lhMYyiRjtpN/images/discount-codes/discount-form-summary.png?fit=max&auto=format&n=28D42lhMYyiRjtpN&q=85&s=1f2c1d04fbbbac53f67d789d81e0a382" alt="New Discount Code form with the Summary and Preview side panel beside the discount details" style={{ maxHeight: '500px', width: 'auto' }} width="1920" height="963" data-path="images/discount-codes/discount-form-summary.png" />
</Frame>

Further down the form — eligibility, restrictions, and advanced options:

<Frame>
  <img src="https://mintcdn.com/dodopayments/Rh05LkBeJE32G3qq/images/discount-codes/discount-create-eligibility.png?fit=max&auto=format&n=Rh05LkBeJE32G3qq&q=85&s=26e5e6971ac541336c16cec478672a0d" alt="Eligibility, restrictions, and advanced options for a discount code" style={{ maxHeight: '500px', width: 'auto' }} width="3006" height="1342" data-path="images/discount-codes/discount-create-eligibility.png" />
</Frame>

<Tip>
  Use cycle limits for introductory pricing on subscriptions (e.g., "50% off for 3 months").
</Tip>

<Info>
  A percentage `amount` is expressed in **basis points** over the API — `1500` means 15%. A flat `amount` is a money value and is denominated by the code's currency options.
</Info>

## Discount Types

| Type | API value | Behavior |
| - | - | - |
| Percentage | `percentage` | Reduces the price by a percent. Optionally capped per currency with a maximum discount. |
| Amount | `flat` | Deducts a fixed amount. The deduction is pooled across the whole cart rather than applied per line item. |

Both types can be stacked in the same `discount_codes` array and are applied in array order.

<Frame>
  <img src="https://mintcdn.com/dodopayments/Rh05LkBeJE32G3qq/images/discount-codes/discount-flat-discount-option.png?fit=max&auto=format&n=Rh05LkBeJE32G3qq&q=85&s=38ce7f39a1ccbd26c61718f685fc4e71" alt="Discount code editor with the Amount type selected, showing a flat 500 INR deduction" style={{ maxHeight: '500px', width: 'auto' }} width="3474" height="1968" data-path="images/discount-codes/discount-flat-discount-option.png" />
</Frame>

## Customer Eligibility

Set `customer_eligibility` to control who may redeem a code:

| Value | Who can redeem |
| - | - |
| `any` | Any customer. This is the default. |
| `first_time` | Customers who have not purchased from you before. |
| `existing` | Customers who have purchased from you before. |
| `specific` | Only customers you attach to the code's allow list. |

<Frame>
  <img src="https://mintcdn.com/dodopayments/Rh05LkBeJE32G3qq/images/discount-codes/discount-restriction.png?fit=max&auto=format&n=Rh05LkBeJE32G3qq&q=85&s=3c01240807a7ca2f13b33a9f4cf4ce43" alt="Customer eligibility dropdown showing Any, First-time, Existing, and Specific customer options" style={{ maxHeight: '500px', width: 'auto' }} width="2832" height="830" data-path="images/discount-codes/discount-restriction.png" />
</Frame>

<Warning>
  A `specific` code starts with **zero** eligible customers and rejects every redemption until you attach customers to it. Attach them in the dashboard, or with the discount customers API.
</Warning>

Pair eligibility with **Per-Customer Usage Limit** to cap how often each individual customer can redeem the code, independently of the overall usage limit.

## Per-Currency Options

When you sell in multiple currencies, set per-currency behavior for each code. Under **Currency options**, each entry specifies:

* **Amount** — for an Amount discount, the flat deduction in that currency; for a Percentage discount, the maximum discount cap. Maps to `max_amount_possible` in the API.
* **Default** — mark one currency as the default. Unconfigured currencies convert from this default.

Set the per-currency minimum separately under **Require a minimum order value** in **Advanced**:

* **Minimum subtotal** — the code applies only when the cart reaches this subtotal in that currency. `0` means no minimum.

<Frame>
  <img src="https://mintcdn.com/dodopayments/Rh05LkBeJE32G3qq/images/discount-codes/discount-currency-options.png?fit=max&auto=format&n=Rh05LkBeJE32G3qq&q=85&s=8e4d0db1a3cfdd256d285a576c9eed34" alt="Currency options panel with per-currency amount and minimum subtotal for INR and USD" style={{ maxHeight: '500px', width: 'auto' }} width="2832" height="614" data-path="images/discount-codes/discount-currency-options.png" />
</Frame>

Amount discounts require at least one currency option with a resolvable default, since a flat deduction has no meaning without a currency. Percentage discounts don't require currency options.

<Info>
  The minimum subtotal is always measured against the cart's original prices, not the running total after earlier discounts in the stack. Stacking order never changes whether a minimum is met.

  For a subscription, the minimum is checked once against the product and its add-ons together. For example, a \$0 product with a \$5 add-on meets a \$4 minimum. An Amount (`flat`) code still applies only to the subscription product, not to its add-ons.
</Info>

## Checkout Experience

Customers enter discount codes in the checkout field. Eligible codes are applied immediately and totals update.

<Frame>
  <img src="https://mintcdn.com/dodopayments/Rh05LkBeJE32G3qq/images/discount-codes/discount-on-checkout.png?fit=max&auto=format&n=Rh05LkBeJE32G3qq&q=85&s=ac92cb27be2e2e7dd5364f941e709966" alt="Checkout page showing a discount applied to the order total" style={{ maxHeight: '500px', width: 'auto' }} width="2458" height="1448" data-path="images/discount-codes/discount-on-checkout.png" />
</Frame>

<Info>
  In Checkout Sessions, pass `discount_codes` (an array) to pre-apply one or more codes. The discount input field is shown by default. Set `feature_flags.allow_discount_code` to `false` to hide it. Codes are applied in array order, up to a maximum of 20.
</Info>

## Stacking Discount Codes

Checkout sessions, payments, and subscriptions accept up to 20 stacked codes via the `discount_codes` array. Codes are applied in array order: the first eligible code reduces the starting price, the next reduces the already-discounted price, and so on. When [Purchasing Power Parity](/features/purchasing-power-parity) is enabled, the starting price is the PPP-adjusted amount. The response includes `discount_ids` (on payments/subscriptions) and `discounts` (richer per-discount detail, including position and remaining subscription cycles).

```typescript theme={null}
const session = await client.checkoutSessions.create({
  product_cart: [{ product_id: 'pdt_abc', quantity: 1 }],
  discount_codes: ['WELCOME10', 'BLACKFRIDAY20'], // applied in this order
  customer: { email: 'user@example.com' },
  return_url: 'https://yoursite.com/return'
});
```

<Info>
  The singular `discount_code` field is deprecated but fully supported for backward compatibility. It cannot be combined with `discount_codes` in the same request. Migrate to `discount_codes` (the array form) to take advantage of stacking and the richer response.
</Info>

<Info>
  On a subscription price with [Card-Optional at Zero Price](/features/subscription#card-optional-at-zero-price) enabled, a stack of codes that reduces the amount due today all the way to `0` skips the card requirement too — the customer checks out with no payment method on file, the same as a native `0` price.
</Info>

## API Management

<AccordionGroup>
  <Accordion title="Create discounts">
    Create discount codes programmatically with type and amount.

    <Card title="API Reference" icon="code" href="/api-reference/discounts/create-discount">
      View the create discount API.
    </Card>
  </Accordion>

  <Accordion title="List and retrieve">
    List all discounts or retrieve details for management and auditing.

    <Card title="API Reference" icon="code" href="/api-reference/discounts/list-discounts">
      Browse listing and retrieval APIs.
    </Card>
  </Accordion>

  <Accordion title="Get discount by code">
    Look up a discount using its human-readable code (e.g., "SAVE20") instead of the internal ID.

    <Card title="API Reference" icon="code" href="/api-reference/discounts/get-discount-by-code">
      Retrieve discount by code name.
    </Card>
  </Accordion>

  <Accordion title="Update discounts">
    Modify discount configuration such as amount, expiration, or restrictions.

    <Card title="API Reference" icon="code" href="/api-reference/discounts/update-discount">
      Learn how to update discount details.
    </Card>
  </Accordion>

  <Accordion title="Retrieve a discount">
    Fetch a discount by its ID to inspect its status, usage count, and restrictions before applying it.

    <Card title="API Reference" icon="code" href="/api-reference/discounts/validate-discount">
      Get a discount by ID.
    </Card>
  </Accordion>

  <Accordion title="Delete discounts">
    Deactivate or remove discounts that are no longer needed.

    <Card title="API Reference" icon="code" href="/api-reference/discounts/delete-discount">
      Delete a discount.
    </Card>
  </Accordion>

  <Accordion title="Manage the customer allow list">
    For a discount with `customer_eligibility` set to `specific`, manage the customers that may redeem it:

    * `GET /discounts/{discount_id}/customers` — list the attached customers (paginated, up to 100 per page).
    * `POST /discounts/{discount_id}/customers` — attach customers by ID. The call is idempotent and accepts up to 1000 IDs, all of which must already exist in your business. The response echoes only the IDs submitted in that request, so list the endpoint to read the full allow list.
    * `DELETE /discounts/{discount_id}/customers/{customer_id}` — detach a single customer.
  </Accordion>
</AccordionGroup>

## Common Use Cases

* **Intro offers**: Limited‑time launch promotions for new products
* **Bulk or B2B**: Contracted discounts for select product sets
* **Retention plays**: Win‑back codes in churn‑prevention workflows
* **Seasonal campaigns**: Holiday or event‑based promotions

## Integration Examples

### Create a Discount with Metadata

Attach custom key–value pairs for internal tracking.

```typescript theme={null}
const discount = await client.discounts.create({
  type: 'percentage',
  amount: 1500, // 15%
  code: 'SUMMER2025',
  metadata: {
    campaign: 'summer_promo',
    source: 'email_blast'
  }
});
```

<Tip>
  Use metadata to tag discounts by campaign, source, or internal reference ID so you can reconcile usage and measure ROI later.
</Tip>

### Apply Discounts in Checkout Sessions

Pre‑apply one or more stacked discounts and show the code input UI.

```typescript theme={null}
const session = await client.checkoutSessions.create({
  product_cart: [
    { product_id: 'pdt_abc', quantity: 1 }
  ],
  discount_codes: ['BLACKFRIDAY2024', 'NEWUSER5'], // stacked in array order
  customer: { email: 'user@example.com', name: 'Jane Doe' },
  return_url: 'https://yoursite.com/return'
});
```

### Apply Discounts During Plan Changes

Offer promotional pricing when customers upgrade or downgrade their subscription.

```typescript theme={null}
await client.subscriptions.changePlan('sub_123', {
  product_id: 'pdt_pro',
  quantity: 1,
  proration_billing_mode: 'prorated_immediately',
  discount_codes: ['UPGRADE20']
});
```

The `discount_codes` parameter controls how discounts are handled:

| Value | Behavior |
| - | - |
| Not provided (`undefined` / `null`) | Existing discounts with `preserve_on_plan_change=true` are preserved if applicable to the new product. |
| `[]` (empty array) | All existing discounts are removed. |
| `['CODE_A', 'CODE_B', ...]` | Replaces existing discounts with this stacked set, applied in array order. |

<Info>
  Read all applied discounts from the subscription's `discounts` array in the response. Each entry includes `discount_id`, `position`, `cycles_remaining`, and the original code.
</Info>

### Hide the Discount Code Field

The discount input is shown by default. Set `allow_discount_code` to `false` to hide it.

```typescript theme={null}
const session = await client.checkoutSessions.create({
  product_cart: [{ product_id: 'pdt_abc', quantity: 1 }],
  feature_flags: {
    allow_discount_code: false
  },
  return_url: 'https://yoursite.com/return'
});
```

## Best Practices

* **Name clearly**: Use recognizable codes that match campaign names.
* **Time-box**: Add expirations to drive urgency and prevent misuse.
* **Scope wisely**: Limit to specific products to avoid margin leakage.
* **Validate early**: Check code applicability before confirming checkout.
* **Monitor impact**: Track usage and conversion by campaign.


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