Class CurrencyUtils
java.lang.Object
com.broadleafcommerce.pricing.service.util.CurrencyUtils
Set of utility methods to help handle pricing requests in regards to currency.
- Author:
- Nathan Moore (nathandmoore)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjavax.money.CurrencyUnitgetCurrencyFromPriceContext(@NonNull com.broadleafcommerce.pricing.client.domain.context.PriceContext priceContext) Gets the currency for the request using only thePriceContext.javax.money.CurrencyUnitgetCurrencyFromPriceContextWithContextInfo(@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 thePriceContextbut validation with and falling-back to theContextInfo.javax.money.CurrencyUnitgetFallbackCurrency(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theCurrencyUnitto use as a final fallback if requested currency is null or invalid, first checking theApplicationthen theSystemCurrencyContextHolder.booleanisCurrencyAllowed(@NonNull javax.money.CurrencyUnit requestedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines whether therequestedCurrencyis allowed given theContextInfo.
-
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 thePriceContext. Ifcurrencyis 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
CurrencyUnitto 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 thePriceContextbut validation with and falling-back to theContextInfo. Ifcurrencyis 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
CurrencyUnitto use for the pricing request
-
getFallbackCurrency
public javax.money.CurrencyUnit getFallbackCurrency(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets theCurrencyUnitto use as a final fallback if requested currency is null or invalid, first checking theApplicationthen theSystemCurrencyContextHolder.- Parameters:
contextInfo- Additional context for multitenancy and sandbox- Returns:
- the
CurrencyUnitto 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 therequestedCurrencyis allowed given theContextInfo. This will check theApplication.computeAllowedCurrencies()for this determination.- Parameters:
requestedCurrency-CurrencyUnitrequested for use during a pricing requestcontextInfo- Optional, additional multitenant and sandbox data including the allowed currencies.- Returns:
- whether the
requestedCurrencyis allowed given theContextInfo.
-