Class CurrencyUtils

java.lang.Object
com.broadleafcommerce.pricing.service.util.CurrencyUtils

public class CurrencyUtils extends Object
Set of utility methods to help handle pricing requests in regards to currency.
Author:
Nathan Moore (nathandmoore)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    javax.money.CurrencyUnit
    getCurrencyFromPriceContext(@NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)
    Gets the currency for the request using only the PriceContext.
    javax.money.CurrencyUnit
    getCurrencyFromPriceContextWithContextInfo(@NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Gets the currency for the request using the PriceContext but validation with and falling-back to the ContextInfo.
    javax.money.CurrencyUnit
    getFallbackCurrency(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Gets the CurrencyUnit to use as a final fallback if requested currency is null or invalid, first checking the Application then the SystemCurrencyContextHolder.
    boolean
    isCurrencyAllowed(@NonNull javax.money.CurrencyUnit requestedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Determines whether the requestedCurrency is allowed given the ContextInfo.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CurrencyUtils

      public CurrencyUtils()
  • Method Details

    • getCurrencyFromPriceContext

      public javax.money.CurrencyUnit getCurrencyFromPriceContext(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)
      Gets the currency for the request using only the PriceContext. If currency is not explicitly set, then this will try to get the currency for requested locale, and, that failing, it will use the SystemCurrencyContextHolder.
      Parameters:
      priceContext - data relevant for determining which pricing entities apply to an API request.
      Returns:
      The CurrencyUnit to use for the pricing request
    • getCurrencyFromPriceContextWithContextInfo

      public javax.money.CurrencyUnit getCurrencyFromPriceContextWithContextInfo(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Gets the currency for the request using the PriceContext but validation with and falling-back to the ContextInfo. If currency is not explicitly set, then this will try to get the currency for requested locale, then the Application.computeDefaultCurrency(), and, those failing, it will use the SystemCurrencyContextHolder.

      This will also validate that the requested currency is valid for the Application. If not, then the Application's currency will be used instead.

      Parameters:
      priceContext - data relevant for determining which pricing entities apply to an API request.
      contextInfo - Additional context for multitenancy and sandbox
      Returns:
      The CurrencyUnit to use for the pricing request
    • getFallbackCurrency

      public javax.money.CurrencyUnit getFallbackCurrency(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Gets the CurrencyUnit to use as a final fallback if requested currency is null or invalid, first checking the Application then the SystemCurrencyContextHolder.
      Parameters:
      contextInfo - Additional context for multitenancy and sandbox
      Returns:
      the CurrencyUnit to use as a final fallback if requested currency is null or invalid
      See Also:
    • isCurrencyAllowed

      public boolean isCurrencyAllowed(@NonNull @NonNull javax.money.CurrencyUnit requestedCurrency, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Determines whether the requestedCurrency is allowed given the ContextInfo. This will check the Application.computeAllowedCurrencies() for this determination.
      Parameters:
      requestedCurrency - CurrencyUnit requested for use during a pricing request
      contextInfo - Optional, additional multitenant and sandbox data including the allowed currencies.
      Returns:
      whether the requestedCurrency is allowed given the ContextInfo.