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
-
Constructor Summary
ConstructorDescriptionShipEngineFulfillmentPricingProvider
(ShipEngineService shipEngineService, ShipEngineProperties shipEngineProperties, ShipmentDetailsService<ShipmentDetails> shipmentDetailsService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected BigDecimal
addIfExists
(ShipEngineCurrencyAmount addAmount, @NonNull BigDecimal total) Add the addAmount to the total if addAmount is not nullbuildItemPriceInfoMap
(@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, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Calculate shipping for a request that includes a specified fulfillment option.boolean
canCalculateCostForOption
(String fulfillmentOptionName, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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
protected ShipEngineService
protected ShipmentDetailsService<ShipmentDetails>
protected boolean
Taxable setting for newFulfillmentOptionPricedResponse
protected String
Tax code for newFulfillmentOptionPricedResponse
.protected com.broadleafcommerce.common.extension.TypeFactory
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, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Retrieve all possible priced fulfillment options for the provided request.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
calculateCostForFulfillmentGroup, canCalculateCostForOption, canProvidePricedFulfillmentOptions, estimateCostForFulfillmentGroup, getFulfillmentOptionPricingResponses, providePricedFulfillmentOptions
-
Field Details
-
SHIPENGINE_FUL_OPT_PREFIX
- See Also:
-
SEPARATOR
- See Also:
-
-
Constructor Details
-
ShipEngineFulfillmentPricingProvider
public ShipEngineFulfillmentPricingProvider(ShipEngineService shipEngineService, ShipEngineProperties shipEngineProperties, ShipmentDetailsService<ShipmentDetails> shipmentDetailsService, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
canProvidePricedFulfillmentOptions
public boolean canProvidePricedFulfillmentOptions(@NonNull @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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 optionscontextInfo
- context information around sandbox and multitenant state- 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, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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.contextInfo
- context information around sandbox and multitenant state- 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, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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.contextInfo
- context information around sandbox and multitenant state- Returns:
- Response object with calculated shipping cost for the provided request.
-
canCalculateCostForOption
public boolean canCalculateCostForOption(String fulfillmentOptionName, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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.contextInfo
- context information around sandbox and multitenant state- 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, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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.contextInfo
- context information around sandbox and multitenant state- Returns:
- Response object with estimated shipping cost for the provided request.
-
canProvideShippingLabel
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
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
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:
-
formatFulfillmentOptionDescription
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
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:
-
getTaxCode
Tax code for newFulfillmentOptionPricedResponse
.- Returns:
- Tax code from properties.
- See Also:
-
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
-
getShipEngineProperties
-
getShipmentDetailsService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-