Class VoucherifyUtil

java.lang.Object
org.bhn.promotion.voucherify.utils.VoucherifyUtil

public class VoucherifyUtil extends Object
Utility class providing methods for handling voucher and promotion data related to the Voucherify.
  • Method Details

    • getValidationDiscountModel

      public static DiscountModel getValidationDiscountModel(ValidationResponseDto.ValidateResponseBodyOrder orderResponse, Map<String,BigDecimal> itemValueAddPromotionMap, String promotionEffect, boolean orderLevel)
      Constructs a DiscountModel for the given order response, considering item-level and order-level value-add promotions.
      Parameters:
      orderResponse - the ValidationResponseDto.ValidateResponseBodyOrder object representing the calculated order details, including item discounts and total amounts. Must not be null.
      itemValueAddPromotionMap - a Map<String, BigDecimal> mapping unique item keys to their respective value-add promotion amounts.
      promotionEffect - the effect of the promotion as a String, typically identifying the type of promotion (e.g., "VALUE_ADD" or "DISCOUNT").
      orderLevel - a boolean flag indicating whether the value-add promotions should be applied at the order level. If false, value-add promotions are ignored when computing totals.
      Returns:
      a DiscountModel containing 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 a DiscountModel for the given order response, considering item-level and order-level value-add promotions.
      Parameters:
      orderResponse - the ValidationResponseDto.ValidateResponseBodyOrder object representing the calculated order details, including item discounts and total amounts. Must not be null.
      itemValueAddPromotionMap - a Map<String, BigDecimal> mapping unique item keys to their respective value-add promotion amounts.
      promotionEffect - the effect of the promotion as a String, typically identifying the type of promotion (e.g., "VALUE_ADD" or "DISCOUNT").
      orderLevel - a boolean flag indicating whether the value-add promotions should be applied at the order level. If false, value-add promotions are ignored when computing totals.
      Returns:
      a DiscountModel containing 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 a DiscountModel for the given order response, considering item-level and order-level value-add promotions.
      Parameters:
      orderResponse - the RedeemPromotionResponseDto.RedemptionOrder object representing the calculated order details, including item discounts and total amounts. Must not be null.
      itemValueAddPromotionMap - a Map<String, BigDecimal> mapping unique item keys to their respective value-add promotion amounts.
      promotionEffect - the effect of the promotion as a String, typically identifying the type of promotion (e.g., "VALUE_ADD" or "DISCOUNT").
      orderLevel - a boolean flag indicating whether the value-add promotions should be applied at the order level. If false, value-add promotions are ignored when computing totals.
      Returns:
      a DiscountModel containing 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 a DiscountModel for the given order response, considering item-level and order-level value-add promotions.
      Parameters:
      orderResponse - the RedeemPromotionResponseDto.RedemptionOrder object representing the calculated order details, including item discounts and total amounts. Must not be null.
      itemValueAddPromotionMap - a Map<String, BigDecimal> mapping unique item keys to their respective value-add promotion amounts.
      promotionEffect - the effect of the promotion as a String, typically identifying the type of promotion (e.g., "VALUE_ADD" or "DISCOUNT").
      orderLevel - a boolean flag indicating whether the value-add promotions should be applied at the order level. If false, value-add promotions are ignored when computing totals.
      Returns:
      a DiscountModel containing 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 of ItemModel objects from the provided redemption order that have applied discounts, along with the associated promotion details.
      Parameters:
      redemptionOrder - the OrderCalculated object representing the calculated order details, including item discounts and product information. Must not be null.
      promo - the Promo object containing promotion details such as discount type and effect. Must not be null.
      Returns:
      a list of ItemModel objects representing items with applied discounts, or an empty list if no such items exist.
    • generateItemUniqueKey

      public static String generateItemUniqueKey(String sourceId, Integer price)
      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 be null.
      price - the price of the item as an Integer. This value is appended to the source ID to form the unique key.
      Returns:
      a String representing the unique key for the item, constructed by concatenating the sourceId, an underscore ("_"), and the price.
    • generateItemUniqueKey

      public static String generateItemUniqueKey(String sourceId, BigDecimal price)
      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 be null.
      price - the price of the item as a BigDecimal. This value is scaled by multiplying it with a predefined scale factor (PRICE_CONVERTOR_SCALE) and then converted to an integer.
      Returns:
      a String representing the unique key for the item, constructed by concatenating the sourceId, an underscore ("_"), and the scaled integer value of the price.
    • getPromotionEffect

      public static String getPromotionEffect(Object metaData)
      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 DISCOUNT if not found
      Throws:
      ClassCastException - if the provided metadata or its nested structure is not of the expected type Map<String, Object>
    • getPromotionEffectEnumFromString

      public static org.bhn.promotion.core.enums.promotions.PromotionEffect getPromotionEffectEnumFromString(String promotionEffect)
      Converts the given string to its corresponding PromotionEffect enum 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 given Discount.EffectEnum to its corresponding DiscountEffect enum 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

      public static Boolean checkCPFundedPromotion(Object metaData)
      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 false if not found
      Throws:
      ClassCastException - if the provided metadata or its nested structure is not of the expected type Map<String, Object>