Package org.bhn.promotion.core.utils
Class PromotionUtil
java.lang.Object
org.bhn.promotion.core.utils.PromotionUtil
PromotionUtil utility methods
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckPromoSummaryParity(BigDecimal discountSummaryLineItemValue, PromoSummary discountSummaryOrder, PromoSummary promoSummaryBeta) Compare Promotion amounts for Parity checkstatic BigDecimalconvertToDecimal(Integer value) static BigDecimalconvertToDecimal(Long value) static voidenrichOrderItemMetaDataWithCardType(Map<String, Object> orderMetaData, AndorCommerceProductResponse andorCommerceProductResponse) Enriches order item metadata with card type information.Extract promo codes from order items where useBhnPromoService is false/null/random/not present.Extracts and returns a list of UPCs from either the item discount map or the item value-add promotion map present in the givenRedemptionResponseModel.static StringgenerateItemUniqueKey(String upc, BigDecimal faceValue) Generate a Unique key using Item upc and Face valuegetCustomerMetaData(PromotionQuoteRequest promotionQuoteRequest, boolean isNewUserFlag) Set MetaData for Customerstatic List<FundingSource>getOrderLevelPromoFundingSources(PromoSummary promoSummary) Retrieves the funding sources related to order-level promotions.getOrderMetaData(PromotionQuoteRequest promotionQuoteRequest, String tenantName) Set MetaData for Orderstatic org.bhn.promotion.core.enums.promotions.DiscountEffectget promo absolute target discountEffectstatic StringgetPromoCodesAsString(PromotionQuoteRequest promotionQuoteRequest) getPromoMap(List<Promo> promos) getRedemptionMetaData(PromotionQuoteRequest promotionQuoteRequest, String tenantName) Set Redemption MetaDatastatic booleanisEmailPresent(Sender sender) Validate whether Sender and Email is presentstatic BooleanisOrderLevelPromo(Promo promo) identify promo is Order levelstatic StringobjectToJsonString(Object object) Converts an object to its JSON string representation.static voidremoveAutoApplyPromoDetails(PromotionQuoteRequest promotionQuoteRequest) Remove promo details with code AUTOstatic voidremovePromotionsWithTypePromotion(PromoSummary discountSummaryOrder) Remove promo details with Promotion type PROMOTIONstatic voidremoveShippingPromoDetails(PromotionQuoteRequest promotionQuoteRequest) Remove promo details with code SHIPPINGstatic CommonPromoMetadatasafeConvertJsonStringToCommonPromoMetadata(String jsonString) Safely converts a JSON string to a CommonPromoMetadata object without throwing exceptions.safeConvertJsonStringToMap(String jsonString) Safely converts a JSON string to a Map<String, Object> without throwing exceptions.safeConvertObjectToMap(Object data) Safely converts a object to a Map<String, Object> without throwing exceptions.static voidsanitizeItemLevelRequestBasedOnUseBhnPromoService(PromotionQuoteRequest promotionQuoteRequest, Map<String, String> upcWithCodeNotEnabledForPromoCalculationMap) Sanitize the item level request based on the useBhnPromoService metadata.static BigDecimalscaleDecimal(BigDecimal value) static BaseSummarysetBaseSummary(BigDecimal value, String currency) Creates and initializes aBaseSummaryinstance with the provided value and currency.static voidsetCategory(PimcorePromotionModel pimcorePromotionModel, List<io.voucherify.client.model.Category> categories) static StringsetCurrency(String discountType, String currency) static voidsetDescriptionAsDiscountType(PromoSummary promoSummary) Set Discount Type as Description in each Promo objectstatic org.bhn.promotion.core.enums.promotions.DiscountTypesetDiscountType(String discountType) static voidsetPromosBetaToPromotionQuoteRequest(PromotionQuoteRequest promotionQuoteRequest) If Beta Promos are available then override PromotionQuoteRequest original promosstatic voidupdateDiscountSummaryOrder(PromoSummary discountSummaryOrder, PromoSummary promoSummaryBeta) Map Order level Discount summary fields with details fetched from Promotion servicestatic List<FundingSource>validateAndGetItemPromoFundingSources(PromotionQuoteRequest promotionQuoteRequest, String itemUpc, List<FundingSource> fundingSources, List<ApplicablePromoModel> appliedPromos) Retrieves the funding sources related to specific item-level promotions.
-
Field Details
-
PROMOTION_CODE_SHIPPING
- See Also:
-
PROMOTION_CODE_AUTO_APPLY
- See Also:
-
UNDERSCORE
- See Also:
-
-
Method Details
-
getPromoMap
- Parameters:
promos- request containing cart for which we want to extract promotionsPromo- Returns:
- Map returns a map of promo code and promo object
-
getOrderMetaData
public static Map<String,Object> getOrderMetaData(PromotionQuoteRequest promotionQuoteRequest, String tenantName) Set MetaData for Order- Parameters:
promotionQuoteRequest-PromotionQuoteRequestobject- Returns:
MapofStringandObject
-
getCustomerMetaData
public static Map<String,Object> getCustomerMetaData(PromotionQuoteRequest promotionQuoteRequest, boolean isNewUserFlag) Set MetaData for Customer- Parameters:
promotionQuoteRequest-PromotionQuoteRequestobject- Returns:
MapofStringandObject
-
getRedemptionMetaData
public static Map<String,Object> getRedemptionMetaData(PromotionQuoteRequest promotionQuoteRequest, String tenantName) Set Redemption MetaData- Parameters:
promotionQuoteRequest-PromotionQuoteRequestobject- Returns:
MapofStringandObject
-
convertToDecimal
- Parameters:
value- long value to be converted- Returns:
- value to converted to BigDecimal
-
convertToDecimal
- Parameters:
value- integer value to be converted- Returns:
- value to converted to BigDecimal
-
scaleDecimal
- Parameters:
value- to be scaled up- Returns:
- value which has been scaled up
-
objectToJsonString
Converts an object to its JSON string representation.- Parameters:
object- the object to be converted to a JSON string. May be null.- Returns:
- a JSON string representation of the object, or null if the object is null or an error occurs during serialization.
-
setDiscountType
public static org.bhn.promotion.core.enums.promotions.DiscountType setDiscountType(String discountType) -
setCurrency
-
setBaseSummary
Creates and initializes aBaseSummaryinstance with the provided value and currency.- Parameters:
value- the monetary value to be set in theBaseSummaryinstance. It should represent the amount in the specified currency.currency- the currency code (e.g., "USD", "EUR") to be set in theBaseSummaryinstance. It must follow the ISO 4217 standard.- Returns:
- a
BaseSummaryinstance with the specified value and currency set.
-
enrichOrderItemMetaDataWithCardType
public static void enrichOrderItemMetaDataWithCardType(Map<String, Object> orderMetaData, AndorCommerceProductResponse andorCommerceProductResponse) Enriches order item metadata with card type information.This method updates the metadata of order items with information about whether the product is a business card or a consumer card. It retrieves the product details from the provided AndorCommerceProductResponse and matches them with the UPCs in the order items.
- Parameters:
orderMetaData- the metadata of the order containing order itemsandorCommerceProductResponse- the response containing product details from AndorCommerce
-
isEmailPresent
Validate whether Sender and Email is present- Parameters:
sender- an object ofSender- Returns:
- TRUE|FALSE
-
removeShippingPromoDetails
Remove promo details with code SHIPPING- Parameters:
promotionQuoteRequest- aPromotionQuoteRequestobject with promo details
-
removeAutoApplyPromoDetails
Remove promo details with code AUTO- Parameters:
promotionQuoteRequest- aPromotionQuoteRequestobject with promo details
-
removePromotionsWithTypePromotion
Remove promo details with Promotion type PROMOTION- Parameters:
discountSummaryOrder- aPromoSummaryobject with promo details
-
setPromosBetaToPromotionQuoteRequest
public static void setPromosBetaToPromotionQuoteRequest(PromotionQuoteRequest promotionQuoteRequest) If Beta Promos are available then override PromotionQuoteRequest original promos- Parameters:
promotionQuoteRequest- aPromotionQuoteRequestobject with promo details
-
updateDiscountSummaryOrder
public static void updateDiscountSummaryOrder(PromoSummary discountSummaryOrder, PromoSummary promoSummaryBeta) Map Order level Discount summary fields with details fetched from Promotion service- Parameters:
discountSummaryOrder- originalPromoSummaryobjectpromoSummaryBeta- newPromoSummaryobject
-
setDescriptionAsDiscountType
Set Discount Type as Description in each Promo object- Parameters:
promoSummary- an object ofPromoSummary
-
checkPromoSummaryParity
public static boolean checkPromoSummaryParity(BigDecimal discountSummaryLineItemValue, PromoSummary discountSummaryOrder, PromoSummary promoSummaryBeta) Compare Promotion amounts for Parity check- Parameters:
discountSummaryOrder- an object ofPromoSummarywith Discount detailspromoSummaryBeta- an object ofPromoSummarywith Voucherify promotion detailsdiscountSummaryLineItemValue- Order Line discount amount- Returns:
- TRUE|FALSE
-
generateItemUniqueKey
Generate a Unique key using Item upc and Face value- Parameters:
upc- Product UPCfaceValue- Product Face value- Returns:
- String
-
sanitizeItemLevelRequestBasedOnUseBhnPromoService
public static void sanitizeItemLevelRequestBasedOnUseBhnPromoService(PromotionQuoteRequest promotionQuoteRequest, Map<String, String> upcWithCodeNotEnabledForPromoCalculationMap) Sanitize the item level request based on the useBhnPromoService metadata.- Parameters:
promotionQuoteRequest- an object ofPromotionQuoteRequestcontaining order itemsupcWithCodeNotEnabledForPromoCalculationMap- a map containing UPCs with promo codes
-
extractPromoCodesWhereUseBhnPromoServiceIsFalse
public static Map<String,String> extractPromoCodesWhereUseBhnPromoServiceIsFalse(List<OrderItem> items) Extract promo codes from order items where useBhnPromoService is false/null/random/not present.- Parameters:
items- a list ofOrderItemobjects- Returns:
- a map containing UPCs and their corresponding promo codes
-
isOrderLevelPromo
identify promo is Order level- Parameters:
promo- Promo- Returns:
- Boolean
-
getPromoAbsoluteDiscountEffect
public static org.bhn.promotion.core.enums.promotions.DiscountEffect getPromoAbsoluteDiscountEffect(Promo promo) get promo absolute target discountEffect- Parameters:
promo- Promo- Returns:
- DiscountEffect
-
getPromoCodesAsString
-
getOrderLevelPromoFundingSources
Retrieves the funding sources related to order-level promotions.- Parameters:
promoSummary- aPromoSummaryobject with list ofFundingSourcewhich contains all fundingSources details- Returns:
- a
List<FundingSource>containing funding sources that apply at the order level
-
validateAndGetItemPromoFundingSources
public static List<FundingSource> validateAndGetItemPromoFundingSources(PromotionQuoteRequest promotionQuoteRequest, String itemUpc, List<FundingSource> fundingSources, List<ApplicablePromoModel> appliedPromos) Retrieves the funding sources related to specific item-level promotions.- Parameters:
promotionQuoteRequest- aPromotionQuoteRequestobject with all fundingSources detailsitemUpc- a String to represent itemUPCfundingSources- list ofFundingSourcewhich contains all fundingSources detailsappliedPromos- list ofApplicablePromoModelwhich has applied promotions to an item- Returns:
- a
List<{@link FundingSource}>containing funding sources that applies to the item
-
filterUpcsFromItemDiscountOrValueAddMap
public static List<String> filterUpcsFromItemDiscountOrValueAddMap(RedemptionResponseModel response) Extracts and returns a list of UPCs from either the item discount map or the item value-add promotion map present in the givenRedemptionResponseModel. The method prioritizes theitemDiscountMapover theitemValueAddPromotionMap. If the discount model is null or both maps are empty, an empty list is returned. The keys in these maps are expected to follow a format where the UPC is the first segment before an underscore ("_"). For example, for a key like "123456_item1", the UPC "123456" will be extracted.- Parameters:
response- theRedemptionResponseModelcontaining the discount model- Returns:
- a list of extracted UPCs; empty if none are available
-
safeConvertJsonStringToMap
Safely converts a JSON string to a Map<String, Object> without throwing exceptions.This method returns an empty Map instead of throwing exceptions when JSON parsing fails.
- Parameters:
jsonString- the JSON string to convert, can be null or empty- Returns:
- a Map representation of the JSON, or an empty Map if conversion fails or JSON is invalid
-
safeConvertJsonStringToCommonPromoMetadata
Safely converts a JSON string to a CommonPromoMetadata object without throwing exceptions.This returns null instead of throwing exceptions when JSON parsing fails.
- Parameters:
jsonString- the JSON string to convert, can be null or empty- Returns:
- a CommonPromoMetadata object, or null if conversion fails or JSON is invalid
-
safeConvertObjectToMap
Safely converts a object to a Map<String, Object> without throwing exceptions.This method is returns an empty Map instead of throwing exceptions when conversion fails.
- Parameters:
data- the object to convert, can be null- Returns:
- a Map representation of the Object, or an empty Map if conversion fails
-
setCategory
public static void setCategory(PimcorePromotionModel pimcorePromotionModel, List<io.voucherify.client.model.Category> categories)
-