Class DefaultShipEngineService

    • Constructor Detail

      • DefaultShipEngineService

        public DefaultShipEngineService​(org.springframework.web.reactive.function.client.WebClient webClient,
                                        ShipEngineProperties shipEngineProperties,
                                        WeightCalculationService weightCalculationService)
    • Method Detail

      • getEstimate

        public EstimateResponse getEstimate​(@NonNull
                                            @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Description copied from interface: ShipEngineService
        Get rate estimates from all carriers for the given FulfillmentPricingRequest. Estimates can be retrieved with less information than is required for a rate quote.
        Specified by:
        getEstimate in interface ShipEngineService
        Parameters:
        fulfillmentPricingRequest - Provides addresses and items for a shipment.
        Returns:
        An EstimateResponse with estimated Rates
      • getRates

        public RatesResponse getRates​(@NonNull
                                      @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Description copied from interface: ShipEngineService
        Get all available rates for the given FulfillmentPricingRequest.
        Specified by:
        getRates in interface ShipEngineService
        Parameters:
        fulfillmentPricingRequest - Provides addresses and items for a shipment.
        Returns:
        A RatesResponse with a list of Rates.
      • purchaseLabel

        public LabelResponse purchaseLabel​(@NonNull
                                           @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment,
                                           @Nullable
                                           com.broadleafcommerce.order.common.domain.Address fromAddress)
        Description copied from interface: ShipEngineService
        Purchase a label with an OrderFulfillment. The FulfillmentOption should be set on the OrderFulfillment.
        Specified by:
        purchaseLabel in interface ShipEngineService
        Parameters:
        orderFulfillment - Provides addresses and items for a shipment.
        fromAddress - The address that the package will be sent from. If not provided, will use the default address configured with properties. See ShipEngineProperties.DefaultFromAddress.
        Returns:
        A LabelResponse with a URL to download the shipping label.
      • retrieveLabel

        public LabelResponse retrieveLabel​(@NonNull
                                           @NonNull String labelId)
        Description copied from interface: ShipEngineService
        Retrieve an existing shipping label. This method does not purchase labels.
        Specified by:
        retrieveLabel in interface ShipEngineService
        Parameters:
        labelId - The ShipEngine label id.
        Returns:
        A LabelResponse with a URL to download the shipping label.
      • buildEstimateRequest

        protected EstimateRequest buildEstimateRequest​(@NonNull
                                                       @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Build a ShipEngine EstimateRequest from a FulfillmentPricingRequest.
        Parameters:
        fulfillmentPricingRequest - Provides addresses and items for a shipment.
        Returns:
        An EstimateRequest to send to ShipEngine.
      • buildRatesRequest

        protected RatesRequest buildRatesRequest​(@NonNull
                                                 @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Build a ShipEngine RatesRequest from a FulfillmentPricingRequest.
        Parameters:
        fulfillmentPricingRequest - Provides addresses and items for a shipment.
        Returns:
        A RatesRequest to send to ShipEngine.
      • buildBulkRateRequest

        protected BulkRateRequest buildBulkRateRequest​(@NonNull
                                                       @NonNull List<com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest> fulfillmentPricingRequests)
        Build a ShipEngine BulkRateRequest from a List of FulfillmentPricingRequest.
        Parameters:
        fulfillmentPricingRequests - Provides addresses and items for shipments.
        Returns:
        A BulkRateRequest to send to ShipEngine.
      • buildLabelRequest

        protected LabelRequest buildLabelRequest​(@NonNull
                                                 @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment orderFulfillment,
                                                 @Nullable
                                                 com.broadleafcommerce.order.common.domain.Address fromAddress)
        Build a ShipEngine LabelRequest from an OrderFulfillment.
        Parameters:
        orderFulfillment - Provides addresses and items for a shipment.
        fromAddress - The address that the package will be sent from. If not provided, will use the default address configured with properties. See ShipEngineProperties.DefaultFromAddress.
        Returns:
        A LabelRequest to send to ShipEngine.
      • callShipEngineAPI

        protected <I,​O> O callShipEngineAPI​(ShipEngineRequest<I,​O> shipEngineRequest)
        Calls the ShipEngine API. The given ShipEngineRequest should have all data needed for the API call.
        Type Parameters:
        I - The type of Input, ie the type of the body of the request.
        O - The type of Output, ie the response type
        Parameters:
        shipEngineRequest - Holds request header and body data needed by WebClient to exchange with the ShipEngine API.
        Returns:
        An object of type O
      • buildShipment

        protected ShipEngineShipment buildShipment​(@NonNull
                                                   @NonNull com.broadleafcommerce.shipping.domain.FulfillmentPricingRequest fulfillmentPricingRequest)
        Build a ShipEngineShipment from the given FulfillmentPricingRequest.
        Parameters:
        fulfillmentPricingRequest - Provides addresses and items for a shipment.
        Returns:
        A ShipEngineShipment to be included in a ShipEngine request.
      • buildPackageList

        protected List<ShipEnginePackage> buildPackageList​(@NonNull
                                                           @NonNull com.broadleafcommerce.shipping.domain.Weight packageWeight)
        Build a ShipEnginePackage with the given weight.
        Parameters:
        packageWeight - The Weight of the package.
        Returns:
        A singleton list of ShipEnginePackage to include in other requests.
      • getAddressValidationMode

        protected String getAddressValidationMode()
        Get the configured address validation mode
        Returns:
        The address validation mode
      • buildShipToAddress

        protected ShipEngineAddress buildShipToAddress​(@NonNull
                                                       @NonNull com.broadleafcommerce.shipping.domain.ShippingAddress toAddress,
                                                       String customerName)
        Build a ShipEngineAddress from a ShippingAddress and customer name.
        Parameters:
        toAddress - The destination address for the package.
        customerName - The name of the recipient.
        Returns:
        A ShipEngineAddress to include in a ShipEngine request.
      • buildShipToAddress

        protected ShipEngineAddress buildShipToAddress​(@NonNull
                                                       @NonNull com.broadleafcommerce.order.common.domain.Address toAddress)
        Build a ShipEngineAddress from an Address
        Parameters:
        toAddress - The destination address for the package.
        Returns:
        A ShipEngineAddress to include in a ShipEngine request.
      • buildShipFromAddress

        protected ShipEngineAddress buildShipFromAddress​(@Nullable
                                                         com.broadleafcommerce.shipping.domain.ShippingAddress fromAddress)
        Build a ShipEngineAddress from a ShippingAddress. If the provided address is null, this will use the default FROM address configured with ShipEngineProperties.DefaultFromAddress.
        Parameters:
        fromAddress - The address that the package is being shipped from.
        Returns:
        A ShipEngineAddress to include in a ShipEngine request.
      • buildShipFromAddress

        protected ShipEngineAddress buildShipFromAddress​(@Nullable
                                                         com.broadleafcommerce.order.common.domain.Address fromAddress)
        Build a ShipEngineAddress from an Address. If the provided address is null, this will use the default FROM address configured with ShipEngineProperties.DefaultFromAddress.
        Parameters:
        fromAddress - The address that the package is being shipped from.
        Returns:
        A ShipEngineAddress to include in a ShipEngine request.
      • getWebClient

        protected org.springframework.web.reactive.function.client.WebClient getWebClient()