Introduction
The Discounts module lets you manage and apply discounts to products and orders
More information about the module's user interface https://doc.oneentry.cloud/docs/category/discounts
🎯 What does this module do?
The Discounts module lets you fetch discounts and validate coupon codes — percentage or fixed-amount reductions, bonus-point accrual, and personal discounts. You define discount rules in the OneEntry admin panel; this module retrieves them, validates coupons at checkout, and reads the current user's bonus balance and history.
The SDK is read-only: discounts are created and configured in the admin panel.
🚀 Quickstart
Initialize the module from defineOneEntry:
const { Discounts } = defineOneEntry( "your-project-url", { "token": "your-app-token" });
Validate a coupon code at checkout and read the result:
// Validate a coupon code entered by the customer.
const result = await Discounts.validateDiscountsCoupon("SUMMER20");
if (result.valid) {
console.log("Coupon applied:", result.coupon);
} else {
console.log("Invalid coupon:", result.error);
}
✨ Key Concepts
What is a Discount?
A Discount (IDiscountsEntity) is a pricing rule that reduces the cost of products or orders:
type—DISCOUNT,BONUS, orPERSONAL_DISCOUNTdiscountValue— how the reduction is calculated:discountType(PERCENTorFIXED_AMOUNT), a numericvalue, anapplicability(TO_PRODUCTorTO_ORDER), and an optionalmaxAmountidentifier— unique marker for filtering and referencingstartDate/endDate— optional validity periodconditions— rules that decide when the discount applies (by product, category, cart amount, user, …)
Discount Structure
{
id: 1,
identifier: 'summer_sale',
localizeInfos: {
title: 'Summer Sale'
},
type: 'DISCOUNT',
startDate: '2025-06-01T00:00:00.000Z',
endDate: '2025-08-31T23:59:59.999Z',
discountValue: {
applicability: 'TO_ORDER',
discountType: 'PERCENT',
value: 20,
maxAmount: 100
},
conditionLogic: 'AND',
conditions: [
{ type: 'MIN_CART_AMOUNT', value: '50' }
]
}
Discount types
The type field classifies the discount:
type | Description |
|---|---|
| DISCOUNT | Standard discount applied to products/orders |
| BONUS | Bonus-points (loyalty) accrual |
| PERSONAL_DISCOUNT | Discount targeted at specific users or groups |
How the reduction is calculated lives in discountValue.discountType:
discountValue.discountType | Description | Example |
|---|---|---|
| PERCENT | Reduce price by a percentage | 20% off all summer items |
| FIXED_AMOUNT | Reduce price by a fixed amount | $10 off orders over $50 |
📋 What You Need to Know
Discounts are created in the admin panel
You cannot create discounts via the SDK — they're created in the OneEntry admin panel. When creating one you provide a Name, a Marker (identifier), a type (DISCOUNT, BONUS, or PERSONAL_DISCOUNT), a discountValue (PERCENT or FIXED_AMOUNT plus the numeric value), an optional validity period (startDate / endDate), and optional conditions.
What the module does
- ✅ Fetch all discounts —
getAllDiscounts() - ✅ Retrieve a specific discount by marker —
getDiscountByMarker() - ✅ Validate coupon codes at checkout —
validateDiscountsCoupon() - ✅ Read the current user's bonus balance and history
- ❌ Does not create or modify discounts (use the admin panel)
📊 Quick Reference Table
| Method | Description |
|---|---|
| getAllDiscounts() | Get all discounts |
| getDiscountByMarker() | Get a single discount by marker |
| validateDiscountsCoupon() | Validate a discount coupon code |
| getBonusBalance() | Get the current user's bonus balance |
| getBonusHistory() | Get the current user's bonus transaction history |
❓ Common Questions (FAQ)
How do I apply a discount at checkout?
Fetch the discount with getDiscountByMarker() or validate a coupon with validateDiscountsCoupon(), then use the returned discount value to calculate the reduced price.
Can a discount have an expiration date?
Yes. Discounts can have optional startDate and endDate fields — check them before displaying a discount to ensure it's currently active.
How do I show discount badges on products?
Fetch all discounts with getAllDiscounts(), match them to products by your business logic, and render a badge from localizeInfos.title and discountValue.value.
What happens if a coupon code is invalid?
validateDiscountsCoupon() returns an ICouponValidationResult — { valid: boolean; coupon?; error? }. When the coupon doesn't exist or has expired, valid is false and an error message is provided. Check result.valid and show an appropriate message.
🎓 Best Practices
- Cache discounts on load — they change infrequently; avoid repeated API calls.
- Validate coupons before applying — always call
validateDiscountsCoupon()before pricing an order. - Handle expired discounts — check
endDatebefore displaying a discount. - Use descriptive markers —
summer_sale_2025, notdiscount1. - Localize discount names — use
localizeInfosfor multi-language support.
🔗 Related Documentation
- Products Module - Manage products that discounts are applied to
- Orders Module - Preview and create orders with discounts applied
- Payments Module - Process payments for discounted orders
- Locales Module - Multi-language discount names