Class ShipEngineFulfillmentPricingProvider
- java.lang.Object
-
- com.broadleafcommerce.shipping.service.integrations.shipengine.service.ShipEngineFulfillmentPricingProvider
-
- All Implemented Interfaces:
FulfillmentPricingProvider
,ShippingLabelProvider
public class ShipEngineFulfillmentPricingProvider extends Object implements FulfillmentPricingProvider, ShippingLabelProvider
FulfillmentPricingProvider
for the ShipEngine integration.- Author:
- Cade Rea (cade-rea)
-
-
Field Summary
Fields Modifier and Type Field Description static String
SEPARATOR
static String
SHIPENGINE_FUL_OPT_PREFIX
-
Constructor Summary
Constructors Constructor Description ShipEngineFulfillmentPricingProvider(ShipEngineService shipEngineService, ShipEngineProperties shipEngineProperties, ShipmentDetailsService<ShipmentDetails> shipmentDetailsService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BigDecimal
addIfExists(ShipEngineCurrencyAmount addAmount, @NonNull BigDecimal total)
Add the addAmount to the total if addAmount is not nullprotected Map<String,com.broadleafcommerce.shipping.domain.FulfillmentPriceInfo>
buildItemPriceInfoMap(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Build Map of item-levelFulfillmentPriceInfo
from each item in the givenFulfillmentPricingRequest
.protected List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse>
buildRatesResponse(@NonNull RatesResponse ratesResponse, @NonNull javax.money.CurrencyUnit currency)
Convert aRatesResponse
to a list ofFulfillmentOptionPricedResponse
.com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse
calculateCostForFulfillmentGroup(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Calculate shipping for a request that includes a specified fulfillment option.boolean
canCalculateCostForOption(String fulfillmentOptionName)
Whether this provider has knowledge of the provided option and thus can provide cost information for it.boolean
canProvidePricedFulfillmentOptions(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"boolean
canProvideShippingLabel(String fulfillmentOptionName)
Indicate if this fulfillment provider can provide shipping labels for the given fulfillment option.protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse
convertRateToPricedResponse(@NonNull Rate rate, @NonNull javax.money.CurrencyUnit currency)
Convert aRate
to aFulfillmentOptionPricedResponse
.com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse
estimateCostForFulfillmentGroup(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Estimate shipping for a request that includes a specified fulfillment option.protected String
formatFulfillmentOptionDescription(@NonNull Rate rate)
Build the description that users will see for thisFulfillmentOption
.protected String
formatFulfillmentOptionName(@NonNull Rate rate)
Builds the name for aFulfillmentOptionPricedResponse
from aRate
.protected Instant
getEstimatedDeliveryDate(@NonNull Rate rate)
Parse an Instant from the estimated delivery date of aRate
.protected javax.money.MonetaryAmount
getFulfillmentRate(@NonNull Rate rate, @NonNull javax.money.CurrencyUnit currency)
Sum the shipping, insurance, confirmation, and other amounts from the givenRate
.protected ShipEngineProperties
getShipEngineProperties()
protected ShipEngineService
getShipEngineService()
protected ShipmentDetailsService<ShipmentDetails>
getShipmentDetailsService()
protected boolean
getTaxable()
Taxable setting for newFulfillmentOptionPricedResponse
protected String
getTaxCode()
Tax code for newFulfillmentOptionPricedResponse
.protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected boolean
isShipEngineFulfillmentOption(String fulfillmentOptionName)
Determine if the given String represents aFulfillmentOption
created by this provider.protected String
parseRateIdFromFulfillmentOptionName(@NonNull String fulfillmentOptionName)
Parse the ShipEngineRate
id from the given Fulfillment Option name String.List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse>
providePricedFulfillmentOptions(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Retrieve all possible priced fulfillment options for the provided request.ShippingLabelDownload
provideShippingLabel(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, boolean purchase, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Get the shipping label associated with this fulfillment.protected ShipmentDetails
saveShipmentDetails(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, @NonNull LabelResponse labelResponse, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Create and saveShipmentDetails
.protected void
setCurrencyIfNull(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Set theCurrencyUnit
on theFulfillmentPricingRequest
to the system default if it is null.boolean
shippingLabelIsPurchased(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Indicate if a shipping label has already been purchased for this fulfillment.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.broadleafcommerce.shipping.service.integrations.FulfillmentPricingProvider
getFulfillmentOptionPricingResponses
-
-
-
-
Field Detail
-
SHIPENGINE_FUL_OPT_PREFIX
public static final String SHIPENGINE_FUL_OPT_PREFIX
- See Also:
- Constant Field Values
-
SEPARATOR
public static final String SEPARATOR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ShipEngineFulfillmentPricingProvider
public ShipEngineFulfillmentPricingProvider(ShipEngineService shipEngineService, ShipEngineProperties shipEngineProperties, ShipmentDetailsService<ShipmentDetails> shipmentDetailsService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Detail
-
canProvidePricedFulfillmentOptions
public boolean canProvidePricedFulfillmentOptions(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Description copied from interface:FulfillmentPricingProvider
Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"- Specified by:
canProvidePricedFulfillmentOptions
in interfaceFulfillmentPricingProvider
- Parameters:
fulfillmentPricingRequest
- The request used to identify relevant fulfillment options- Returns:
- Whether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"
-
providePricedFulfillmentOptions
public List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse> providePricedFulfillmentOptions(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Description copied from interface:FulfillmentPricingProvider
Retrieve all possible priced fulfillment options for the provided request. Intended to be used to display options to the customer for selection.- Specified by:
providePricedFulfillmentOptions
in interfaceFulfillmentPricingProvider
- Parameters:
fulfillmentPricingRequest
- The request for which to calculate shipping and return options.- Returns:
- All possible priced fulfillment options for the provided request.
-
calculateCostForFulfillmentGroup
public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse calculateCostForFulfillmentGroup(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Description copied from interface:FulfillmentPricingProvider
Calculate shipping for a request that includes a specified fulfillment option.- Specified by:
calculateCostForFulfillmentGroup
in interfaceFulfillmentPricingProvider
- Parameters:
fulfillmentPricingRequest
- The request for which to calculate shipping.- Returns:
- Response object with calculated shipping cost for the provided request.
-
canCalculateCostForOption
public boolean canCalculateCostForOption(String fulfillmentOptionName)
Description copied from interface:FulfillmentPricingProvider
Whether this provider has knowledge of the provided option and thus can provide cost information for it.- Specified by:
canCalculateCostForOption
in interfaceFulfillmentPricingProvider
- Parameters:
fulfillmentOptionName
- The option to consider whether this provider can calculate cost information.- Returns:
- Whether this provider has knowledge of the provided option and thus can provide cost information for it.
-
estimateCostForFulfillmentGroup
public com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse estimateCostForFulfillmentGroup(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Description copied from interface:FulfillmentPricingProvider
Estimate shipping for a request that includes a specified fulfillment option.- Specified by:
estimateCostForFulfillmentGroup
in interfaceFulfillmentPricingProvider
- Parameters:
fulfillmentPricingRequest
- The request for which to estimate shipping.- Returns:
- Response object with estimated shipping cost for the provided request.
-
canProvideShippingLabel
public boolean canProvideShippingLabel(@Nullable String fulfillmentOptionName)
Description copied from interface:ShippingLabelProvider
Indicate if this fulfillment provider can provide shipping labels for the given fulfillment option.- Specified by:
canProvideShippingLabel
in interfaceShippingLabelProvider
- Parameters:
fulfillmentOptionName
- The name of the fulfillment option to check.- Returns:
- true if this
ShippingLabelProvider
can provide a shipping label for the given fulfillmentOptionName.
-
shippingLabelIsPurchased
public boolean shippingLabelIsPurchased(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:ShippingLabelProvider
Indicate if a shipping label has already been purchased for this fulfillment.- Specified by:
shippingLabelIsPurchased
in interfaceShippingLabelProvider
- Returns:
- true if there is an existing label for this fulfillment
-
provideShippingLabel
public ShippingLabelDownload provideShippingLabel(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, boolean purchase, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) throws LabelException
Description copied from interface:ShippingLabelProvider
Get the shipping label associated with this fulfillment. If a label does not already exist, the purchase parameter will be checked to determine if a new label should be purchased.- Specified by:
provideShippingLabel
in interfaceShippingLabelProvider
- Parameters:
orderFulfillment
- The fulfillment for which to get a shipping label.purchase
- True if shipping should be purchased, false if an existing label should be read.- Returns:
- a Map with the label response for the shipping label
- Throws:
LabelException
-
saveShipmentDetails
protected ShipmentDetails saveShipmentDetails(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, @NonNull @NonNull LabelResponse labelResponse, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Create and saveShipmentDetails
.- Parameters:
orderFulfillment
- Provides addresses and items for a shipment.labelResponse
- Contains the shipping label download URL.contextInfo
- The context of the request.- Returns:
- A persisted
ShipmentDetails
.
-
buildItemPriceInfoMap
protected Map<String,com.broadleafcommerce.shipping.domain.FulfillmentPriceInfo> buildItemPriceInfoMap(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Build Map of item-levelFulfillmentPriceInfo
from each item in the givenFulfillmentPricingRequest
. This method sets all item-level fulfillment charges to 0.- Parameters:
fulfillmentPricingRequest
- Provides addresses and items for a shipment.- Returns:
- Map of
FulfillmentPriceInfo
for each item in the givenFulfillmentPricingRequest
-
buildRatesResponse
protected List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse> buildRatesResponse(@NonNull @NonNull RatesResponse ratesResponse, @NonNull @NonNull javax.money.CurrencyUnit currency)
Convert aRatesResponse
to a list ofFulfillmentOptionPricedResponse
.- Parameters:
ratesResponse
- The response from ShipEngine.currency
- The currency for the prices.- Returns:
-
convertRateToPricedResponse
protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse convertRateToPricedResponse(@NonNull @NonNull Rate rate, @NonNull @NonNull javax.money.CurrencyUnit currency)
Convert aRate
to aFulfillmentOptionPricedResponse
.- Parameters:
rate
- The rate to convert to theFulfillmentOptionPricedResponse
.currency
- The currency for the prices.- Returns:
- A
FulfillmentOptionPricedResponse
created from the givenRate
.
-
formatFulfillmentOptionName
protected String formatFulfillmentOptionName(@NonNull @NonNull Rate rate)
Builds the name for aFulfillmentOptionPricedResponse
from aRate
. For example, with a rate id of "se-1234", this would return "SHIPENGINE_se-1234".- Parameters:
rate
- The rate used for building theFulfillmentOptionPricedResponse
.- Returns:
- A name for the
FulfillmentOptionPricedResponse
.
-
isShipEngineFulfillmentOption
protected boolean isShipEngineFulfillmentOption(@Nullable String fulfillmentOptionName)
Determine if the given String represents aFulfillmentOption
created by this provider.- Parameters:
fulfillmentOptionName
- The name of theFulfillmentOption
to check.- Returns:
- True if the given String starts with the SHIPENGINE_FUL_OPT_PREFIX.
-
parseRateIdFromFulfillmentOptionName
protected String parseRateIdFromFulfillmentOptionName(@NonNull @NonNull String fulfillmentOptionName)
Parse the ShipEngineRate
id from the given Fulfillment Option name String.- Parameters:
fulfillmentOptionName
- The name of theFulfillmentOption
- Returns:
- A ShipEngine
Rate
id. - See Also:
formatFulfillmentOptionName(com.broadleafcommerce.shipping.service.integrations.shipengine.domain.rates.rate.response.Rate)
-
formatFulfillmentOptionDescription
protected String formatFulfillmentOptionDescription(@NonNull @NonNull Rate rate)
Build the description that users will see for thisFulfillmentOption
.- Parameters:
rate
- The rate used for building theFulfillmentOptionPricedResponse
.- Returns:
- A user-friendly description of the
FulfillmentOption
.
-
getFulfillmentRate
protected javax.money.MonetaryAmount getFulfillmentRate(@NonNull @NonNull Rate rate, @NonNull @NonNull javax.money.CurrencyUnit currency)
Sum the shipping, insurance, confirmation, and other amounts from the givenRate
.- Parameters:
rate
- The rate used for building theFulfillmentOptionPricedResponse
.currency
- The currency of the prices.- Returns:
- The total of all shipping charges from the given
Rate
.
-
getEstimatedDeliveryDate
@Nullable protected Instant getEstimatedDeliveryDate(@NonNull @NonNull Rate rate)
Parse an Instant from the estimated delivery date of aRate
.- Parameters:
rate
- The rate used for building theFulfillmentOptionPricedResponse
.- Returns:
- The Instant representation of the estimated delivery date or null if not available.
-
getTaxable
protected boolean getTaxable()
Taxable setting for newFulfillmentOptionPricedResponse
- Returns:
- True if new
FulfillmentOptionPricedResponse
should be marked as taxable. - See Also:
ShipEngineProperties.isTaxable()
-
getTaxCode
protected String getTaxCode()
Tax code for newFulfillmentOptionPricedResponse
.- Returns:
- Tax code from properties.
- See Also:
ShipEngineProperties.getTaxCode()
-
addIfExists
protected BigDecimal addIfExists(@Nullable ShipEngineCurrencyAmount addAmount, @NonNull @NonNull BigDecimal total)
Add the addAmount to the total if addAmount is not null- Parameters:
addAmount
- The amount to add to the total.total
- The running total.- Returns:
- The same total object that is passed in.
-
setCurrencyIfNull
protected void setCurrencyIfNull(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
Set theCurrencyUnit
on theFulfillmentPricingRequest
to the system default if it is null.- Parameters:
fulfillmentPricingRequest
- The fulfillment being shipped.
-
getShipEngineService
protected ShipEngineService getShipEngineService()
-
getShipEngineProperties
protected ShipEngineProperties getShipEngineProperties()
-
getShipmentDetailsService
protected ShipmentDetailsService<ShipmentDetails> getShipmentDetailsService()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
-