Skip to main content

Discounts

The Discounts module lets you read discounts, validate coupons and check the user's bonus balance.

More information about the module's user interface: https://doc.oneentry.cloud/docs/category/discounts (opens in a new tab)


Use this module to 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. The module retrieves them, validates coupons at checkout, and reads the current user's bonus balance and history.

The SDK is read-only. You can't create or modify discounts through it; that's done in the admin panel. When you create a discount there, you set 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.

Quickstart​

Initialize the module from defineOneEntry:


const { } = defineOneEntry(
, {
}
);

Validate a coupon code at checkout and read the result:

// Validate a coupon code entered by the customer.
const result = await Discounts.validateDiscountsCoupon("SUMMER-KBWZ-2428");

if ('statusCode' in result) {
console.error(result.message); // IError: the request failed
} else if (result.valid) {
console.log("Coupon applied:", result.coupon);
} else {
console.log("Invalid coupon:", result.error); // e.g. "Coupon not found"
}

Discount object​

A discount (IDiscountsEntity) is a pricing rule that reduces the cost of products or orders:

  • type: DISCOUNT, BONUS or PERSONAL_DISCOUNT.
  • discountValue: how the reduction is calculated. It holds a discountType (PERCENT or FIXED_AMOUNT), a numeric value, an applicability (TO_PRODUCT or TO_ORDER) and an optional maxAmount.
  • identifier: the unique marker used for filtering and referencing.
  • startDate / endDate: the optional validity period.
  • conditions: rules that decide when the discount applies (by product, category, cart amount, user, …).
{
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: [
{ id: 1, conditionType: 'MIN_CART_AMOUNT', entityIds: null, value: { amount: 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

The way the reduction is calculated is set 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

Methods​

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
getDiscountsByVectorSearch()Search discounts by meaning (vector search)

Applying a discount at checkout​

Validate the code the customer enters with validateDiscountsCoupon(), then pass it as couponCode to Orders.previewOrder() to get the discounted totals, and to Orders.createOrder() when you place the order. To apply a discount without a coupon, pass its marker in additionalDiscountsMarkers. The platform applies discounts and coupons when it calculates the order, so don't recalculate prices on the client. Use getDiscountByMarker() only to display a discount (for example, its discountValue). createOrder() requires user authorization.

validateDiscountsCoupon() returns an ICouponValidationResult: { valid: boolean; coupon?; error? }. If the coupon doesn't exist or a single-use coupon has already been used, valid is false and error contains the reason (for example, "Coupon not found"). Coupon validation doesn't check the discount's startDate/endDate, so check them yourself (see Validity period).

Validity period​

startDate and endDate are optional. Check them before displaying a discount, so you only show discounts that are currently active.

Discount badges on products​

Fetch all discounts with getAllDiscounts(), match them to products using your own business logic, and render a badge from localizeInfos.title and discountValue.value. Discounts change infrequently, so cache them on load instead of calling the API repeatedly. For multi-language names, use localizeInfos.


  • Products: products that discounts apply to
  • Orders: preview and create orders with discounts applied
  • Payments: payments for discounted orders
  • Locales: multi-language discount names