/// <summary>
 /// Adjusts the rate of the quote based on the province Associated with the ShipMethod
 /// </summary>
 /// <param name="baseRate">The base (unadjusted) rate</param>
 /// <param name="province">The <see cref="IShipProvince"/> associated with the ShipMethod</param>
 /// <returns></returns>
 protected decimal AdjustedRate(decimal baseRate, IShipProvince province)
 {
     if (province == null) return baseRate;
     return province.RateAdjustmentType == RateAdjustmentType.Numeric
                ? baseRate + province.RateAdjustment
                : baseRate*(1 + (province.RateAdjustment/100));
 }
        public Attempt<IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, IShipProvince province)
        {
            // First sum up the total weight for the shipment.
            // We're assumning that a custom order line property 
            // was set on the order line prior when the product was added to the order line.

            var shippingPrice = 0M;
            try
            {
                var http = new UpsHttpRequestHandler();
                var rateXml = http.Post(RateRequest(shipment, totalWeight));

                var collection = UpsParseRates(rateXml);

                var firstCarrierRate = collection.FirstOrDefault(option => option.Service == shipMethod.Name);
                if (firstCarrierRate != null)
                    shippingPrice = firstCarrierRate.Rate;
            }
            catch (Exception ex)
            {
                return Attempt<IShipmentRateQuote>.Fail(
                        new Exception("An error occured during your request : " +
                                                     ex.Message +
                                                     " Please contact your administrator or try again."));
            }

            return Attempt<IShipmentRateQuote>.Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice });
        }
        public Attempt<IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, int quantity, IShipProvince province)
        {
            // First sum up the total weight for the shipment.
            // We're assumning that a custom order line property 
            // was set on the order line prior when the product was added to the order line.

            var shippingPrice = 0M;
            try
            {
                var service = new RateService {Url = "https://wsbeta.fedex.com:443/web-services/rate"};
                
                var reply = service.getRates(RateRequest(shipment, totalWeight, quantity));
                                                            
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    var collection = BuildDeliveryOptions(reply, shipment);

                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service.Contains(shipMethod.ServiceCode.Split('-').First()));
                    if (firstCarrierRate != null)
                        shippingPrice = firstCarrierRate.Rate;
                }

            }
            catch (Exception ex)
            {
                return Attempt<IShipmentRateQuote>.Fail(
                        new Exception("An error occured during your request : " +
                                                     ex.Message +
                                                     " Please contact your administrator or try again."));
            }

            return Attempt<IShipmentRateQuote>.Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice });
        }
Beispiel #4
0
 /// <summary>
 /// Adjusts the rate of the quote based on the province Associated with the ShipMethod
 /// </summary>
 /// <param name="baseRate">
 /// The base (unadjusted) rate
 /// </param>
 /// <param name="province">
 /// The <see cref="IShipProvince"/> associated with the ShipMethod
 /// </param>
 /// <returns>
 /// The adjusted rate.
 /// </returns>
 protected decimal AdjustedRate(decimal baseRate, IShipProvince province)
 {
     if (province == null)
     {
         return(baseRate);
     }
     return(province.RateAdjustmentType == RateAdjustmentType.Numeric
                ? baseRate + province.RateAdjustment
                : baseRate *(1 + (province.RateAdjustment / 100)));
 }
        internal static IShipProvince ToShipProvince(this ShipProvinceDisplay shipProvinceDisplay, IShipProvince destination)
        {
            destination.AllowShipping = shipProvinceDisplay.AllowShipping;
            destination.RateAdjustment = shipProvinceDisplay.RateAdjustment;
            destination.RateAdjustmentType = shipProvinceDisplay.RateAdjustmentType;

            return destination;
        }
Beispiel #6
0
        /// <summary>
        /// Calculates the rate based on the total shipment item price
        /// </summary>
        /// <param name="shipment">The associated <see cref="IShipment"/></param>
        /// <param name="totalPrice">The total price of the items in the shipment</param>
        /// <param name="province">The <see cref="IShipProvince"/> associated with the shipment destination.  Used for rate adjustments</param>
        /// <returns>Returns an <see cref="Attempt"/> to quote a rate using 'this' ship method</returns>
        private Attempt <IShipmentRateQuote> CalculateVaryByPrice(IShipment shipment, decimal totalPrice, IShipProvince province = null)
        {
            var tier = RateTable.Rows.FirstOrDefault(x => x.RangeLow <= totalPrice && totalPrice < x.RangeHigh);

            if (tier == null)
            {
                return
                    (Attempt <IShipmentRateQuote> .Fail(
                         new IndexOutOfRangeException("The shipments total weight was calculated to be : " +
                                                      totalPrice.ToString(CultureInfo.InvariantCulture) +
                                                      " which is outside any rate tier defined by the current rate table.")));
            }


            return(Attempt <IShipmentRateQuote> .Succeed(new ShipmentRateQuote(shipment, ShipMethod) { Rate = AdjustedRate(tier.Rate, province) }));
        }
        internal static IShipProvince ToShipProvince(this ShipProvinceDisplay shipProvinceDisplay, IShipProvince destination)
        {
            destination.AllowShipping      = shipProvinceDisplay.AllowShipping;
            destination.RateAdjustment     = shipProvinceDisplay.RateAdjustment;
            destination.RateAdjustmentType = shipProvinceDisplay.RateAdjustmentType;

            return(destination);
        }
 internal static ShipProvinceDisplay ToShipProvinceDisplay(this IShipProvince shipProvince)
 {
     return(AutoMapper.Mapper.Map <ShipProvinceDisplay>(shipProvince));
 }
        /// <summary>
        /// Calculates the rate based on the total weight of the items in the shipment
        /// </summary>
        /// <param name="shipment">The associated <see cref="IShipment"/></param>
        /// <param name="totalWeight">The total weight of the items in the shipment</param>
        /// <param name="province">The <see cref="IShipProvince"/> associated with the shipment destination.  Used for rate adjustments</param>
        /// <returns>Returns an <see cref="Attempt"/> to quote a rate using 'this' ship method</returns>
        private Attempt<IShipmentRateQuote> CalculateVaryByWeight(IShipment shipment, decimal totalWeight, IShipProvince province = null)
        {
            var tier = RateTable.Rows.FirstOrDefault(x => x.RangeLow <= totalWeight && totalWeight < x.RangeHigh);
            if (tier == null)
                return
                    Attempt<IShipmentRateQuote>.Fail(
                        new IndexOutOfRangeException("The shipments total weight was calculated to be : " +
                                                     totalWeight.ToString(CultureInfo.InvariantCulture) +
                                                     " which is outside any rate tier defined by the current rate table."));

                return Attempt<IShipmentRateQuote>.Succeed(new ShipmentRateQuote(shipment, ShipMethod) { Rate = AdjustedRate(tier.Rate, province) });
        }
Beispiel #10
0
        public Attempt <IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, IShipProvince province)
        {
            // First sum up the total weight for the shipment.
            // We're assumning that a custom order line property
            // was set on the order line prior when the product was added to the order line.

            var shippingPrice = 0M;

            try
            {
                var http    = new UpsHttpRequestHandler();
                var rateXml = http.Post(RateRequest(shipment, totalWeight));

                var collection = UpsParseRates(rateXml);

                var firstCarrierRate = collection.FirstOrDefault(option => option.Service == shipMethod.Name);
                if (firstCarrierRate != null)
                {
                    shippingPrice = firstCarrierRate.Rate;
                }
            }
            catch (Exception ex)
            {
                return(Attempt <IShipmentRateQuote> .Fail(
                           new Exception("An error occured during your request : " +
                                         ex.Message +
                                         " Please contact your administrator or try again.")));
            }

            return(Attempt <IShipmentRateQuote> .Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice }));
        }
        public Attempt <IShipmentRateQuote> CalculatePrice(IShipment shipment, IShipMethod shipMethod, decimal totalWeight, int quantity, IShipProvince province)
        {
            // First sum up the total weight for the shipment.
            // We're assumning that a custom order line property
            // was set on the order line prior when the product was added to the order line.

            var shippingPrice = 0M;

            try
            {
                var service = new RateService {
                    Url = "https://wsbeta.fedex.com:443/web-services/rate"
                };

                var reply = service.getRates(RateRequest(shipment, totalWeight, quantity));

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    var collection = BuildDeliveryOptions(reply, shipment);

                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service.Contains(shipMethod.ServiceCode.Split('-').First()));
                    if (firstCarrierRate != null)
                    {
                        shippingPrice = firstCarrierRate.Rate;
                    }
                }
            }
            catch (Exception ex)
            {
                return(Attempt <IShipmentRateQuote> .Fail(
                           new Exception("An error occured during your request : " +
                                         ex.Message +
                                         " Please contact your administrator or try again.")));
            }

            return(Attempt <IShipmentRateQuote> .Succeed(new ShipmentRateQuote(shipment, shipMethod) { Rate = shippingPrice }));
        }