Class PromotionUtil

java.lang.Object
org.bhn.promotion.core.utils.PromotionUtil

public final class PromotionUtil extends Object
PromotionUtil utility methods
  • Field Details

  • Method Details

    • getPromoMap

      public static Map<String,Promo> getPromoMap(List<Promo> promos)
      Parameters:
      promos - request containing cart for which we want to extract promotions Promo
      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 - PromotionQuoteRequest object
      Returns:
      Map of String and Object
    • getCustomerMetaData

      public static Map<String,Object> getCustomerMetaData(PromotionQuoteRequest promotionQuoteRequest, boolean isNewUserFlag)
      Set MetaData for Customer
      Parameters:
      promotionQuoteRequest - PromotionQuoteRequest object
      Returns:
      Map of String and Object
    • getRedemptionMetaData

      public static Map<String,Object> getRedemptionMetaData(PromotionQuoteRequest promotionQuoteRequest, String tenantName)
      Set Redemption MetaData
      Parameters:
      promotionQuoteRequest - PromotionQuoteRequest object
      Returns:
      Map of String and Object
    • convertToDecimal

      public static BigDecimal convertToDecimal(Long value)
      Parameters:
      value - long value to be converted
      Returns:
      value to converted to BigDecimal
    • convertToDecimal

      public static BigDecimal convertToDecimal(Integer value)
      Parameters:
      value - integer value to be converted
      Returns:
      value to converted to BigDecimal
    • scaleDecimal

      public static BigDecimal scaleDecimal(BigDecimal value)
      Parameters:
      value - to be scaled up
      Returns:
      value which has been scaled up
    • objectToJsonString

      public static String objectToJsonString(Object object)
      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

      public static String setCurrency(String discountType, String currency)
    • setBaseSummary

      public static BaseSummary setBaseSummary(BigDecimal value, String currency)
      Creates and initializes a BaseSummary instance with the provided value and currency.
      Parameters:
      value - the monetary value to be set in the BaseSummary instance. It should represent the amount in the specified currency.
      currency - the currency code (e.g., "USD", "EUR") to be set in the BaseSummary instance. It must follow the ISO 4217 standard.
      Returns:
      a BaseSummary instance 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 items
      andorCommerceProductResponse - the response containing product details from AndorCommerce
    • isEmailPresent

      public static boolean isEmailPresent(Sender sender)
      Validate whether Sender and Email is present
      Parameters:
      sender - an object of Sender
      Returns:
      TRUE|FALSE
    • removeShippingPromoDetails

      public static void removeShippingPromoDetails(PromotionQuoteRequest promotionQuoteRequest)
      Remove promo details with code SHIPPING
      Parameters:
      promotionQuoteRequest - a PromotionQuoteRequest object with promo details
    • removeAutoApplyPromoDetails

      public static void removeAutoApplyPromoDetails(PromotionQuoteRequest promotionQuoteRequest)
      Remove promo details with code AUTO
      Parameters:
      promotionQuoteRequest - a PromotionQuoteRequest object with promo details
    • removePromotionsWithTypePromotion

      public static void removePromotionsWithTypePromotion(PromoSummary discountSummaryOrder)
      Remove promo details with Promotion type PROMOTION
      Parameters:
      discountSummaryOrder - a PromoSummary object with promo details
    • setPromosBetaToPromotionQuoteRequest

      public static void setPromosBetaToPromotionQuoteRequest(PromotionQuoteRequest promotionQuoteRequest)
      If Beta Promos are available then override PromotionQuoteRequest original promos
      Parameters:
      promotionQuoteRequest - a PromotionQuoteRequest object 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 - original PromoSummary object
      promoSummaryBeta - new PromoSummary object
    • setDescriptionAsDiscountType

      public static void setDescriptionAsDiscountType(PromoSummary promoSummary)
      Set Discount Type as Description in each Promo object
      Parameters:
      promoSummary - an object of PromoSummary
    • checkPromoSummaryParity

      public static boolean checkPromoSummaryParity(BigDecimal discountSummaryLineItemValue, PromoSummary discountSummaryOrder, PromoSummary promoSummaryBeta)
      Compare Promotion amounts for Parity check
      Parameters:
      discountSummaryOrder - an object of PromoSummary with Discount details
      promoSummaryBeta - an object of PromoSummary with Voucherify promotion details
      discountSummaryLineItemValue - Order Line discount amount
      Returns:
      TRUE|FALSE
    • generateItemUniqueKey

      public static String generateItemUniqueKey(String upc, BigDecimal faceValue)
      Generate a Unique key using Item upc and Face value
      Parameters:
      upc - Product UPC
      faceValue - 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 of PromotionQuoteRequest containing order items
      upcWithCodeNotEnabledForPromoCalculationMap - 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 of OrderItem objects
      Returns:
      a map containing UPCs and their corresponding promo codes
    • isOrderLevelPromo

      public static Boolean isOrderLevelPromo(Promo promo)
      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

      public static String getPromoCodesAsString(PromotionQuoteRequest promotionQuoteRequest)
    • getOrderLevelPromoFundingSources

      public static List<FundingSource> getOrderLevelPromoFundingSources(PromoSummary promoSummary)
      Retrieves the funding sources related to order-level promotions.
      Parameters:
      promoSummary - a PromoSummary object with list of FundingSource which 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 - a PromotionQuoteRequest object with all fundingSources details
      itemUpc - a String to represent itemUPC
      fundingSources - list of FundingSource which contains all fundingSources details
      appliedPromos - list of ApplicablePromoModel which 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 given RedemptionResponseModel. The method prioritizes the itemDiscountMap over the itemValueAddPromotionMap. 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 - the RedemptionResponseModel containing the discount model
      Returns:
      a list of extracted UPCs; empty if none are available
    • safeConvertJsonStringToMap

      public static Map<String,Object> safeConvertJsonStringToMap(String jsonString)
      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

      public static CommonPromoMetadata safeConvertJsonStringToCommonPromoMetadata(String jsonString)
      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

      public static Map<String,Object> safeConvertObjectToMap(Object data)
      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)