Skip to main content

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:

  • typeDISCOUNT, BONUS, or PERSONAL_DISCOUNT
  • discountValue — how the reduction is calculated: discountType (PERCENT or FIXED_AMOUNT), a numeric value, an applicability (TO_PRODUCT or TO_ORDER), and an optional maxAmount
  • identifier — unique marker for filtering and referencing
  • startDate / endDate — optional validity period
  • conditions — 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:

typeDescription
DISCOUNTStandard discount applied to products/orders
BONUSBonus-points (loyalty) accrual
PERSONAL_DISCOUNTDiscount targeted at specific users or groups

How the reduction is calculated lives in discountValue.discountType:

discountValue.discountTypeDescriptionExample
PERCENTReduce price by a percentage20% off all summer items
FIXED_AMOUNTReduce 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


📊 Quick Reference Table

MethodDescription
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 endDate before displaying a discount.
  • Use descriptive markerssummer_sale_2025, not discount1.
  • Localize discount names — use localizeInfos for multi-language support.