Discount codes
Create percent or fixed-amount discount codes, limit them by price, date and redemptions, and pre-fill them from your extension.
Discount codes reduce the price at checkout. Buyers type a code on the hosted checkout page, or your extension pre-fills one, for example for a launch or a “come back” offer.
// popup.js
import { bill } from './bill'
document.getElementById('launch-offer').addEventListener('click', () => {
bill.openCheckout('price_pro_yearly_id', { discountCode: 'LAUNCH20' })
})
Create the code first (below). Replace price_pro_yearly_id with a real price ID from Sell → Products or bill.getPlans(), or pass undefined to open the plan picker with the code applied to whichever plan the buyer chooses. The shared bill client is set up in the Quick start.
Show a discounted price in your own UI only as a hint. The buyer always pays the amount on the checkout page.
Create a code
-
Open Sell → Discounts and click New discount. Check that the environment toggle shows the environment you want; sandbox and live codes are separate.
-
Enter the code. Codes are stored in uppercase and must be unique within the environment, so
launch20becomesLAUNCH20. Buyers can type it in any case. -
Choose the type.
- Percent: for example 20% off.
- Fixed amount: for example 2.00 off. Pick the currency; the code only applies to prices in that currency.
-
Choose which prices it applies to: all prices, or only the prices you select.
-
Choose the duration (subscriptions only):
- Once: only the first billing period is discounted. Later renewals are charged the full price.
- Forever: every billing period is discounted for the life of the subscription.
-
Set limits (optional).
- Max redemptions: the total number of paid checkouts that can use the code.
- Expires at: the code stops working after this date and time.
-
Save. The code is active immediately. Turn Active off at any time to pause it without deleting it.
Let buyers enter codes
Checkout shows a “Discount code” field when Settings → Checkout → Allow discount codes is on (checkout.allowDiscountCodes, on by default). Turn it off if you only want codes you pre-fill; pre-filled codes still apply.
When a buyer enters a code, the summary updates with the discount, tax and new total before they pay. An unknown, inactive, expired or used-up code, or one that doesn’t apply to the selected price, is rejected with discount_invalid, and the buyer can remove it or try another.
How amounts are calculated
All amounts are recalculated on the ExtensionBill server from your catalog and the discount record. Nothing the browser sends can change the price.
- Subtotal: the amount of the selected price.
- Discount: percent of the subtotal, or the fixed amount, never more than the subtotal.
- Tax: if you enabled a tax rate in Settings → Checkout, it’s applied to the discounted amount. See Taxes.
- Total: what PayPal charges.
The order keeps the discount amount and code, so you see them in Customers → Orders and on the buyer’s receipt.
For recurring prices, ExtensionBill builds the discount into the PayPal subscription when the buyer approves it. Once charges the first billing period at the discounted price, then the regular price from the second period on. Forever charges every period at the discounted price. Changing or deactivating a code later doesn’t affect subscriptions that already used it.
Redemptions
The Redemptions counter goes up by one for each completed checkout that used the code. When it reaches Max redemptions, the code stops being accepted. Abandoned or failed checkouts don’t count.
Sandbox and live
A code belongs to one environment. A code created while the dashboard is in Sandbox only works on sandbox checkouts (pk_test_ keys); create it again in Live before you announce it. This lets you test a code end to end without touching real buyers. See Testing with PayPal sandbox.
Customize
Pre-fill the buyer’s email too
const user = await bill.getUser()
await bill.openCheckout('price_pro_monthly_id', {
email: user.customer?.email,
discountCode: 'COMEBACK30',
})
More checkout options are in Checkout & one-time payments.
The discount object
A discount as returned by the dashboard API:
{
"id": "66f1d0b2e4b0a1d2c3b4a6a1",
"env": "live",
"code": "LAUNCH20",
"type": "percent",
"percentOff": 20,
"priceIds": [],
"duration": "once",
"maxRedemptions": 500,
"redemptions": 137,
"expiresAt": "2026-12-31T23:59:59.000Z",
"active": true
}
An empty priceIds array means the code applies to all prices. Fixed-amount codes use amountOff in minor units plus currency, so "amountOff": 200, "currency": "USD" is $2.00 off.
Ideas
- A launch code with an expiry date for your first week in the store.
- A “Pro forever 30% off” code for early adopters, limited by max redemptions.
- A win-back code you pre-fill when a subscriber’s plan ends.