Class VoucherifyUtil
java.lang.Object
org.bhn.promotion.voucherify.utils.VoucherifyUtil
Utility class providing methods for handling voucher and promotion data related to the
Voucherify.
-
Method Summary
Modifier and TypeMethodDescriptionstatic BooleancheckCPFundedPromotion(Object metaData) Retrieves the promotion funded by content partner or not from the provided metadata.static StringgenerateItemUniqueKey(String sourceId, Integer price) Generates a unique key for an item based on its source ID and price.static StringgenerateItemUniqueKey(String sourceId, BigDecimal price) Generates a unique key for an item based on its source ID and scaled price.static org.bhn.promotion.core.enums.promotions.DiscountEffectgetDiscountEffectFromVoucherifyEffectEnum(io.voucherify.client.model.Discount.EffectEnum effect) Converts the givenDiscount.EffectEnumto its correspondingDiscountEffectenum constant by matching the enum name.getItemModelsWithAppliedDiscounts(RedeemPromotionResponseDto.RedemptionOrder redemptionOrder, Promo promo) Retrieves a list ofItemModelobjects from the provided redemption order that have applied discounts, along with the associated promotion details.static StringgetPromotionEffect(Object metaData) Retrieves the promotion effect from the provided metadata.static org.bhn.promotion.core.enums.promotions.PromotionEffectgetPromotionEffectEnumFromString(String promotionEffect) Converts the given string to its correspondingPromotionEffectenum constant.static DiscountModelgetRedemptionDiscountModel(RedeemPromotionResponseDto.RedemptionOrder orderResponse, Map<String, BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel) Constructs aDiscountModelfor the given order response, considering item-level and order-level value-add promotions.static DiscountModelgetRedemptionOrderDiscountModel(RedeemPromotionResponseDto.RedemptionOrder orderResponse, Map<String, BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel) Constructs aDiscountModelfor the given order response, considering item-level and order-level value-add promotions.static DiscountModelgetValidationDiscountModel(ValidationResponseDto.ValidateResponseBodyOrder orderResponse, Map<String, BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel) Constructs aDiscountModelfor the given order response, considering item-level and order-level value-add promotions.static DiscountModelgetValidationRedeemablesItemDiscountModel(ValidationResponseDto.ValidateResponseBodyOrder orderResponse, Map<String, BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel) Constructs aDiscountModelfor the given order response, considering item-level and order-level value-add promotions.
-
Method Details
-
getValidationDiscountModel
public static DiscountModel getValidationDiscountModel(ValidationResponseDto.ValidateResponseBodyOrder orderResponse, Map<String, BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel) Constructs aDiscountModelfor the given order response, considering item-level and order-level value-add promotions.- Parameters:
orderResponse- theValidationResponseDto.ValidateResponseBodyOrderobject representing the calculated order details, including item discounts and total amounts. Must not benull.itemValueAddPromotionMap- aMap<String, BigDecimal>mapping unique item keys to their respective value-add promotion amounts.promotionEffect- the effect of the promotion as aString, typically identifying the type of promotion (e.g., "VALUE_ADD" or "DISCOUNT").orderLevel- abooleanflag indicating whether the value-add promotions should be applied at the order level. Iffalse, value-add promotions are ignored when computing totals.- Returns:
- a
DiscountModelcontaining the computed totals, item-level discounts, and value-add promotion details.
-
getValidationRedeemablesItemDiscountModel
public static DiscountModel getValidationRedeemablesItemDiscountModel(ValidationResponseDto.ValidateResponseBodyOrder orderResponse, Map<String, BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel) Constructs aDiscountModelfor the given order response, considering item-level and order-level value-add promotions.- Parameters:
orderResponse- theValidationResponseDto.ValidateResponseBodyOrderobject representing the calculated order details, including item discounts and total amounts. Must not benull.itemValueAddPromotionMap- aMap<String, BigDecimal>mapping unique item keys to their respective value-add promotion amounts.promotionEffect- the effect of the promotion as aString, typically identifying the type of promotion (e.g., "VALUE_ADD" or "DISCOUNT").orderLevel- abooleanflag indicating whether the value-add promotions should be applied at the order level. Iffalse, value-add promotions are ignored when computing totals.- Returns:
- a
DiscountModelcontaining the computed totals, item-level discounts, and value-add promotion details.
-
getRedemptionDiscountModel
public static DiscountModel getRedemptionDiscountModel(RedeemPromotionResponseDto.RedemptionOrder orderResponse, Map<String, BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel) Constructs aDiscountModelfor the given order response, considering item-level and order-level value-add promotions.- Parameters:
orderResponse- theRedeemPromotionResponseDto.RedemptionOrderobject representing the calculated order details, including item discounts and total amounts. Must not benull.itemValueAddPromotionMap- aMap<String, BigDecimal>mapping unique item keys to their respective value-add promotion amounts.promotionEffect- the effect of the promotion as aString, typically identifying the type of promotion (e.g., "VALUE_ADD" or "DISCOUNT").orderLevel- abooleanflag indicating whether the value-add promotions should be applied at the order level. Iffalse, value-add promotions are ignored when computing totals.- Returns:
- a
DiscountModelcontaining the computed totals, item-level discounts, and value-add promotion details.
-
getRedemptionOrderDiscountModel
public static DiscountModel getRedemptionOrderDiscountModel(RedeemPromotionResponseDto.RedemptionOrder orderResponse, Map<String, BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel) Constructs aDiscountModelfor the given order response, considering item-level and order-level value-add promotions.- Parameters:
orderResponse- theRedeemPromotionResponseDto.RedemptionOrderobject representing the calculated order details, including item discounts and total amounts. Must not benull.itemValueAddPromotionMap- aMap<String, BigDecimal>mapping unique item keys to their respective value-add promotion amounts.promotionEffect- the effect of the promotion as aString, typically identifying the type of promotion (e.g., "VALUE_ADD" or "DISCOUNT").orderLevel- abooleanflag indicating whether the value-add promotions should be applied at the order level. Iffalse, value-add promotions are ignored when computing totals.- Returns:
- a
DiscountModelcontaining the computed totals, item-level discounts, and value-add promotion details.
-
getItemModelsWithAppliedDiscounts
public static List<ItemModel> getItemModelsWithAppliedDiscounts(RedeemPromotionResponseDto.RedemptionOrder redemptionOrder, Promo promo) Retrieves a list ofItemModelobjects from the provided redemption order that have applied discounts, along with the associated promotion details.- Parameters:
redemptionOrder- theOrderCalculatedobject representing the calculated order details, including item discounts and product information. Must not benull.promo- thePromoobject containing promotion details such as discount type and effect. Must not benull.- Returns:
- a list of
ItemModelobjects representing items with applied discounts, or an empty list if no such items exist.
-
generateItemUniqueKey
Generates a unique key for an item based on its source ID and price.- Parameters:
sourceId- the source identifier for the item, typically a unique string that identifies the origin or source of the item (e.g., a product ID or source code). Must not benull.price- the price of the item as anInteger. This value is appended to the source ID to form the unique key.- Returns:
- a
Stringrepresenting the unique key for the item, constructed by concatenating thesourceId, an underscore ("_"), and theprice.
-
generateItemUniqueKey
Generates a unique key for an item based on its source ID and scaled price.- Parameters:
sourceId- the source identifier for the item, typically a unique string that identifies the origin or source of the item (e.g., a product ID or source code). Must not benull.price- the price of the item as aBigDecimal. This value is scaled by multiplying it with a predefined scale factor (PRICE_CONVERTOR_SCALE) and then converted to an integer.- Returns:
- a
Stringrepresenting the unique key for the item, constructed by concatenating thesourceId, an underscore ("_"), and the scaled integer value of the price.
-
getPromotionEffect
Retrieves the promotion effect from the provided metadata.- Parameters:
metaData- the metadata object, expected to be a map containing promotion details- Returns:
- the promotion effect as a string, or a default value
DISCOUNTif not found - Throws:
ClassCastException- if the provided metadata or its nested structure is not of the expected typeMap<String, Object>
-
getPromotionEffectEnumFromString
public static org.bhn.promotion.core.enums.promotions.PromotionEffect getPromotionEffectEnumFromString(String promotionEffect) Converts the given string to its correspondingPromotionEffectenum constant.Returns null if the input is null or does not match any PromotionEffect constant.
- Parameters:
promotionEffect- the name of the PromotionEffect enum constant; may be null- Returns:
- the corresponding PromotionEffect enum constant, or null if no match is found
-
getDiscountEffectFromVoucherifyEffectEnum
public static org.bhn.promotion.core.enums.promotions.DiscountEffect getDiscountEffectFromVoucherifyEffectEnum(io.voucherify.client.model.Discount.EffectEnum effect) Converts the givenDiscount.EffectEnumto its correspondingDiscountEffectenum constant by matching the enum name.Returns null if the input is null or no matching DiscountEffect constant exists.
- Parameters:
effect- the EffectEnum value to convert; may be null- Returns:
- the corresponding DiscountEffect enum constant, or null if no match is found
-
checkCPFundedPromotion
Retrieves the promotion funded by content partner or not from the provided metadata.- Parameters:
metaData- the metadata object, expected to be a map containing promotion details- Returns:
- the promotion is CP funded or not as a Boolean, or a default value
falseif not found - Throws:
ClassCastException- if the provided metadata or its nested structure is not of the expected typeMap<String, Object>
-