Skip to main content

previewOrder

Preview an order calculation without creating it. 🔐 This method requires authorization.

Description

This method calculates and previews an order - including product totals, applied discounts, and the final sum - without actually creating the order in the system. It returns a Promise that resolves to an IPreviewOrderEntity object.

Orders.previewOrder(

body*, body.products, products.productId, products.quantity, body.couponCode, body.additionalDiscountsMarkers, body.bonusAmount, langCode

);

Parameters schema

Schema

body(required): ICreateOrderPreview
Order preview body

body.products: IPreviewOrderProduct[]
Array of products to preview.

products.productId: number
Product identifier.
example: 1

products.quantity: number
Quantity of the product.
example: 2

body.couponCode: string
Coupon code to apply.

body.additionalDiscountsMarkers: string[]
Array of additional discount markers.

body.bonusAmount: number
Bonus amount to apply.

langCode: string
Language code. Default: "en_US"
example: "en_US"

Examples

Minimal example


const body = {
"formIdentifier": "orderForm",
"paymentAccountIdentifier": "cash",
"formData": {
{
"marker": "order_name",
"type": "string",
"value": "Ivan"
}
},
"products": [
{
"productId": 2957,
"quantity": 2
}
]
};

const response = await Orders.previewOrder("my_order", body);

Example response

{
"formIdentifier": "orderForm",
"paymentAccountIdentifier": "cash",
"formData": [
{
"marker": "order_name",
"value": "Ivan",
"type": "string"
}
],
"products": [
{
"productId": 2957,
"quantity": 2
}
],
"currency": "usd",
"totalSum": 300
}

Response schema

Schema: IOrderPreviewResponse

totalSum: number
Total order amount before discounts.
example: 300

totalSumWithDiscount: number
Total order amount after discounts.
example: 250

discountConfig: IOrderDiscountConfig
Discount configuration applied to the order.

discountConfig.bonus: IOrderDiscountBonus | null
Bonus calculation result, or null when bonuses are not used.

bonus.availableBalance: number
User bonus balance available at the moment of calculation.
example: 0

bonus.bonusApplied: number
Bonus amount actually applied to this order.
example: 0

bonus.maxBonusDiscount: number
Maximum bonus amount allowed to be spent on this order.
example: 0

bonus.minBonusAmount: number | null
Minimum bonus balance required to use bonuses, or null if no threshold.
example: null

bonus.minOrderAmountForBonus: number | null
Minimum order total required to apply bonuses, or null if no threshold.
example: null

discountConfig.coupon: unknown | null
Resolved coupon, or null when no coupon is applied.

discountConfig.orderDiscounts: unknown[]
Order-level discounts that were matched and applied.

discountConfig.productDiscounts: unknown[]
Product-level discounts that were matched and applied.

discountConfig.settings: IOrderDiscountSettings
Stacking and cap settings used during calculation.

settings.allowGiftStacking: boolean
Whether multiple gift discounts can be combined.
example: false

settings.allowStacking: boolean
Whether multiple non-gift discounts can be combined.
example: false

settings.maxDiscountValue: number | null
Hard cap on total discount value, or null if uncapped.
example: null

discountConfig.additionalDiscountsMarkers: string[]
Markers of extra discounts requested by the client (omitted in preview responses).

discountConfig.bonusApplied: number
Bonus amount applied to the order (omitted in preview responses).
example: 0

discountConfig.excludedGiftProductIds: string[]
Product ids excluded from gift selection (omitted in preview responses).

discountConfig.totalDue: number
Total amount due after discounts and bonuses (omitted in preview responses).
example: 300

discountConfig.totalRaw: number
Total amount before discounts (omitted in preview responses).
example: 300

discountConfig.totalSumWithDiscount: number
Total amount after discounts but before bonuses (omitted in preview responses).
example: 300

currency: string
Currency of the order.
example: "USD"

orderPreview: IOrderPreviewItem[]
Array of order preview items.

orderPreview.id: number
Product identifier.
example: 2954

orderPreview.price: number
Product unit price before discounts.
example: 51

orderPreview.quantity: number
Quantity of the product.
example: 1

orderPreview.discountPrice: number | null
Unit price after discounts, or null when no discount applies.
example: null

orderPreview.isGift: boolean
Whether the product is delivered as a gift.
example: false

bonusApplied: number
Bonus applied to the order.

totalDue: number
Total due after bonuses.