public override Attempt <IShipmentRateQuote> QuoteShipment(IShipment shipment)
        {
            try
            {
                // TODO this should be made configurable
                var visitor = new UPSShipmentLineItemVisitor()
                {
                    UseOnSalePriceIfOnSale = false
                };

                shipment.Items.Accept(visitor);

                var province = ShipMethod.Provinces.FirstOrDefault(x => x.Code == shipment.ToRegion);

                var collection = GetCollectionFromCache(shipment);

                if (collection == null)
                {
                    try
                    {
                        var http    = new UpsHttpRequestHandler();
                        var rateXml = http.Post(RateRequest(shipment, visitor));

                        collection = UpsParseRates(rateXml);

                        _runtimeCache.InsertCacheItem(MakeCacheKey(shipment), () => collection);
                    }
                    catch (Exception ex)
                    {
                        return(Attempt <IShipmentRateQuote> .Fail(
                                   new Exception("An error occured during your request : " +
                                                 ex.Message +
                                                 " Please contact your administrator or try again.")));
                    }
                }
                var shippingPrice = 0M;

                var firstCarrierRate = collection.FirstOrDefault(option => option.Service == _shipMethod.ServiceCode);
                if (firstCarrierRate != null)
                {
                    shippingPrice = firstCarrierRate.Rate;
                }

                return(Attempt <IShipmentRateQuote> .Succeed(new ShipmentRateQuote(shipment, _shipMethod) { Rate = shippingPrice }));
            }
            catch (Exception ex)
            {
                return(Attempt <IShipmentRateQuote> .Fail(
                           new Exception("An error occured during your request : " +
                                         ex.Message +
                                         " Please contact your administrator or try again.")));
            }
        }
        public override Attempt<IShipmentRateQuote> QuoteShipment(IShipment shipment)
        {
            try
            {
                // TODO this should be made configurable
                var visitor = new UPSShipmentLineItemVisitor() { UseOnSalePriceIfOnSale = false };

                shipment.Items.Accept(visitor);

                var province = ShipMethod.Provinces.FirstOrDefault(x => x.Code == shipment.ToRegion);
                                                  
                var collection = GetCollectionFromCache(shipment);

                if (collection == null)
                {
                    try
                    {
                        var http = new UpsHttpRequestHandler();
                        var rateXml = http.Post(RateRequest(shipment, visitor));

                        collection = UpsParseRates(rateXml);

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

                }
                var shippingPrice = 0M;

                var firstCarrierRate = collection.FirstOrDefault(option => option.Service == _shipMethod.ServiceCode);
                if (firstCarrierRate != null)
                    shippingPrice = firstCarrierRate.Rate;
                
                return Attempt<IShipmentRateQuote>.Succeed(new ShipmentRateQuote(shipment, _shipMethod) { Rate = shippingPrice });


            }
            catch (Exception ex)
            {
                return Attempt<IShipmentRateQuote>.Fail(
                           new Exception("An error occured during your request : " +
                                                        ex.Message +
                                                        " Please contact your administrator or try again."));
            }
        }
        public override Attempt<IShipmentRateQuote> QuoteShipment(IShipment shipment)
        {
            try
            {
                // TODO this should be made configurable
                var visitor = new UPSShipmentLineItemVisitor() { UseOnSalePriceIfOnSale = false };

                shipment.Items.Accept(visitor);

                var province = ShipMethod.Provinces.FirstOrDefault(x => x.Code == shipment.ToRegion);
                                          
                // JASON: Removing Cache check as the strategy handles this. (However, the Provider is getting quotes to know what methods to return...)
                var collection = GetCollectionFromCache(shipment);

                //if (collection == null)
                //{
                    try
                    {
                        var http = new UpsHttpRequestHandler();
                        var rateXml = http.Post(RateRequest(shipment, visitor));

                        collection = UpsParseRates(rateXml);

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

                //}
                var shippingPrice = 0M;

                if (_processorSettings.UpsFreeGroundShipping && _shipMethod.ServiceCode == UPSShippingGatewayProvider.UPSGround)
                {
                    shippingPrice = 0M;
                }
                else
                {
                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service == _shipMethod.ServiceCode);
                    if (firstCarrierRate != null)
                    {
                        shippingPrice = firstCarrierRate.Rate;
                    }
                }
                
                return Attempt<IShipmentRateQuote>.Succeed(new ShipmentRateQuote(shipment, _shipMethod) { Rate = shippingPrice });


            }
            catch (Exception ex)
            {
                return Attempt<IShipmentRateQuote>.Fail(
                           new Exception("An error occured during your request : " +
                                                        ex.Message +
                                                        " Please contact your administrator or try again."));
            }
        }
Exemple #4
0
        public override Attempt <IShipmentRateQuote> QuoteShipment(IShipment shipment)
        {
            try
            {
                // TODO this should be made configurable
                var visitor = new UPSShipmentLineItemVisitor()
                {
                    UseOnSalePriceIfOnSale = false
                };

                shipment.Items.Accept(visitor);

                var province = ShipMethod.Provinces.FirstOrDefault(x => x.Code == shipment.ToRegion);

                // JASON: Removing Cache check as the strategy handles this. (However, the Provider is getting quotes to know what methods to return...)
                var collection = GetCollectionFromCache(shipment);

                //if (collection == null)
                //{
                try
                {
                    var http    = new UpsHttpRequestHandler();
                    var rateXml = http.Post(RateRequest(shipment, visitor));

                    collection = UpsParseRates(rateXml);

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

                //}
                var shippingPrice = 0M;

                if (_processorSettings.UpsFreeGroundShipping && _shipMethod.ServiceCode == UPSShippingGatewayProvider.UPSGround)
                {
                    shippingPrice = 0M;
                }
                else
                {
                    var firstCarrierRate = collection.FirstOrDefault(option => option.Service == _shipMethod.ServiceCode);
                    if (firstCarrierRate != null)
                    {
                        shippingPrice = firstCarrierRate.Rate;
                    }
                }

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