Promotion Integration: Calculating Custom Discounts
Published by Miranda Danielson on December 19, 2024
Learn more about a new configuration within promotions that is used in conjunction with an integration event to support scenarios that fall outside the capabilities of the Rules Engine.
Sample Use Case
As powerful as the Rules Engine is, you may sometimes have a use case that is too complex to solve using the properties and functions accessible within an expression.
For example, let's say you have this promotion: Buy 2 from Category A, Get 2 from Category B for 50% off, with the following stipulations:
Must scale with quantity
Quantities may be split across items
Discount should be applied to the least expensive lines first
While it's not possible to accomplish with a ValueExpression
evaluated by the Rules Engine, you can write custom code to calculate the discount yourself and return those discounts to OrderCloud to be applied as determined by your middleware.
General Workflow
A promotion is created in OrderCloud with a null
ValueExpression
Any time that promotion is added to an order, or needs to be recalculated, OrderCloud will call out to your predefined middleware endpoint with information about the order and promotion
Middleware responds with information to tell OrderCloud what the value of the discount should be
OrderCloud applies the discount to the order or applicable lineitems.
Key Highlights
OrderCloud will still evaluate the promotion's
EligibleExpression
and only call your middleware when an order is eligible to have a promotion appliedWorks with Auto Applied promotions
ValueExpressions
and those using the Promotion Integration in the same marketplace and the same order. You should always use the standard promotion flow whenever possible for the best performance and user experience. Using the Promotion integration should be a rare the exception.New Property
Promotion.UseIntegration
boolean, defaults to false
when true, OrderCloud will call out to your Marketplace's PromotionIntegration to get the discount amount
New Resource: PromotionIntegration
1{2 "Url": "",3 "HashKey": ""4}
PromotionIntegrationPayload
1{2 "Environment": "",3 "Order": {},4 "LineItems": [],5 "PromosApplied": [],6 "PromosRequested": [],7}
Environment can be useful if you host a single middleware for multiple environments so that you know if the call is coming from Production, Staging, or Sandbox
The full Order object and list of LineItems are returned
A list of Promotions already applied to the order, as well as a list of Promotions requesting to be applied to the order are also included
PromosRequested will only have multiple entries in the event AutoApply promotions is being called and more than 1 promotion is eligible
PromotionIntegrationResponse
1{2 "HttpStatusCode": 200,3 "PromosAccepted": [],4 "PromosRejected": [],5 "UnhandledErrorBody": ""6}
AcceptedPromo
1{2 "ID": "",3 "LineItemID": "", // null if order level promotion4 "Amount": 05}
RejectedPromo
1{2 "ID": "",3 "LineItemID": "", // null if order level promotion4 "Reason": ""5}
New Endpoints
GET v1/integrations/promotion
PUT v1/integrations/promotion
DELETE v1/integrations/promotion
PATCH v1/integrations/promotion
Still have questions?
Ask in our Community Channel