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 CurrencyUtils()
-
Method Summary
All Methods Instance Methods Concrete Methods 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 thePriceContext
.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 thePriceContext
but validation with and falling-back to theContextInfo
.javax.money.CurrencyUnit
getFallbackCurrency(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Gets theCurrencyUnit
to use as a final fallback if requested currency is null or invalid, first checking theApplication
then theSystemCurrencyContextHolder
.boolean
isCurrencyAllowed(@NonNull javax.money.CurrencyUnit requestedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determines whether therequestedCurrency
is allowed given theContextInfo
.
-
-
-
Method Detail
-
getCurrencyFromPriceContext
public javax.money.CurrencyUnit getCurrencyFromPriceContext(@NonNull @NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext)
Gets the currency for the request using only thePriceContext
. Ifcurrency
is not explicitly set, then this will try to get the currency forrequested locale
, and, that failing, it will use theSystemCurrencyContextHolder
.- 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 thePriceContext
but validation with and falling-back to theContextInfo
. Ifcurrency
is not explicitly set, then this will try to get the currency forrequested locale
, then theApplication.computeDefaultCurrency()
, and, those failing, it will use theSystemCurrencyContextHolder
.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 theCurrencyUnit
to use as a final fallback if requested currency is null or invalid, first checking theApplication
then theSystemCurrencyContextHolder
.- 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:
getCurrencyFromPriceContext(PriceContext)
,getCurrencyFromPriceContextWithContextInfo(PriceContext, ContextInfo)
-
isCurrencyAllowed
public boolean isCurrencyAllowed(@NonNull @NonNull javax.money.CurrencyUnit requestedCurrency, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determines whether therequestedCurrency
is allowed given theContextInfo
. This will check theApplication.computeAllowedCurrencies()
for this determination.- Parameters:
requestedCurrency
-CurrencyUnit
requested for use during a pricing requestcontextInfo
- Optional, additional multitenant and sandbox data including the allowed currencies.- Returns:
- whether the
requestedCurrency
is allowed given theContextInfo
.
-
-