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 -
Constructor Summary
ConstructorsConstructorDescriptionShipEngineFulfillmentPricingProvider(ShipEngineService shipEngineService, ShipEngineProperties shipEngineProperties, ShipmentDetailsService<ShipmentDetails> shipmentDetailsService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected BigDecimaladdIfExists(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-levelFulfillmentPriceInfofrom each item in the givenFulfillmentPricingRequest.protected List<com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponse>buildRatesResponse(@NonNull RatesResponse ratesResponse, @NonNull javax.money.CurrencyUnit currency) Convert aRatesResponseto a list ofFulfillmentOptionPricedResponse.com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponsecalculateCostForFulfillmentGroup(@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.booleancanCalculateCostForOption(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.booleancanProvidePricedFulfillmentOptions(@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"booleancanProvideShippingLabel(String fulfillmentOptionName) Indicate if this fulfillment provider can provide shipping labels for the given fulfillment option.protected com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponseconvertRateToPricedResponse(@NonNull Rate rate, @NonNull javax.money.CurrencyUnit currency) Convert aRateto aFulfillmentOptionPricedResponse.com.broadleafcommerce.shipping.domain.FulfillmentOptionPricedResponseestimateCostForFulfillmentGroup(@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 StringformatFulfillmentOptionDescription(@NonNull Rate rate) Build the description that users will see for thisFulfillmentOption.protected StringformatFulfillmentOptionName(@NonNull Rate rate) Builds the name for aFulfillmentOptionPricedResponsefrom aRate.protected InstantgetEstimatedDeliveryDate(@NonNull Rate rate) Parse an Instant from the estimated delivery date of aRate.protected javax.money.MonetaryAmountgetFulfillmentRate(@NonNull Rate rate, @NonNull javax.money.CurrencyUnit currency) Sum the shipping, insurance, confirmation, and other amounts from the givenRate.protected ShipEnginePropertiesprotected ShipEngineServiceprotected ShipmentDetailsService<ShipmentDetails>protected booleanTaxable setting for newFulfillmentOptionPricedResponseprotected StringTax code for newFulfillmentOptionPricedResponse.protected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanisShipEngineFulfillmentOption(String fulfillmentOptionName) Determine if the given String represents aFulfillmentOptioncreated by this provider.protected StringparseRateIdFromFulfillmentOptionName(@NonNull String fulfillmentOptionName) Parse the ShipEngineRateid 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 ShipmentDetailssaveShipmentDetails(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment, @NonNull LabelResponse labelResponse, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Create and saveShipmentDetails.protected voidsetCurrencyIfNull(@NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest) Set theCurrencyUniton theFulfillmentPricingRequestto the system default if it is null.booleanshippingLabelIsPurchased(@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, waitMethods 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:FulfillmentPricingProviderWhether this provider can provide fulfillment options based on the "fulfillmentPricingRequest"- Specified by:
canProvidePricedFulfillmentOptionsin 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:FulfillmentPricingProviderRetrieve all possible priced fulfillment options for the provided request. Intended to be used to display options to the customer for selection.- Specified by:
providePricedFulfillmentOptionsin 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:FulfillmentPricingProviderCalculate shipping for a request that includes a specified fulfillment option.- Specified by:
calculateCostForFulfillmentGroupin 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:FulfillmentPricingProviderWhether this provider has knowledge of the provided option and thus can provide cost information for it.- Specified by:
canCalculateCostForOptionin 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:FulfillmentPricingProviderEstimate shipping for a request that includes a specified fulfillment option.- Specified by:
estimateCostForFulfillmentGroupin 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:ShippingLabelProviderIndicate if this fulfillment provider can provide shipping labels for the given fulfillment option.- Specified by:
canProvideShippingLabelin interfaceShippingLabelProvider- Parameters:
fulfillmentOptionName- The name of the fulfillment option to check.- Returns:
- true if this
ShippingLabelProvidercan 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:ShippingLabelProviderIndicate if a shipping label has already been purchased for this fulfillment.- Specified by:
shippingLabelIsPurchasedin 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:ShippingLabelProviderGet 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:
provideShippingLabelin 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-levelFulfillmentPriceInfofrom 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
FulfillmentPriceInfofor 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 aRatesResponseto 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 aRateto aFulfillmentOptionPricedResponse.- Parameters:
rate- The rate to convert to theFulfillmentOptionPricedResponse.currency- The currency for the prices.- Returns:
- A
FulfillmentOptionPricedResponsecreated from the givenRate.
-
formatFulfillmentOptionName
Builds the name for aFulfillmentOptionPricedResponsefrom 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 aFulfillmentOptioncreated by this provider.- Parameters:
fulfillmentOptionName- The name of theFulfillmentOptionto check.- Returns:
- True if the given String starts with the SHIPENGINE_FUL_OPT_PREFIX.
-
parseRateIdFromFulfillmentOptionName
protected String parseRateIdFromFulfillmentOptionName(@NonNull @NonNull String fulfillmentOptionName) Parse the ShipEngineRateid from the given Fulfillment Option name String.- Parameters:
fulfillmentOptionName- The name of theFulfillmentOption- Returns:
- A ShipEngine
Rateid. - 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
FulfillmentOptionPricedResponseshould 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 theCurrencyUniton theFulfillmentPricingRequestto the system default if it is null.- Parameters:
fulfillmentPricingRequest- The fulfillment being shipped.
-
getShipEngineService
-
getShipEngineProperties
-
getShipmentDetailsService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-