// Entry Point.
        public void GetTrackingResult(string trackingNo)
        {
            shippingResult = new ShippingResult();

            if (!string.IsNullOrEmpty(trackingNo))
            {
                CarrierName carrier = GetCarrierName(trackingNo);

                CredentialValidation(carrier);

                switch (carrier)
                {
                case CarrierName.UPS:
                    trackingFacility = new UPSTracking(trackingNo);
                    break;

                case CarrierName.USPS:
                    trackingFacility = new USPSTracking(trackingNo);
                    break;

                case CarrierName.FedEx:
                    trackingFacility = new FedExTracking(trackingNo);
                    break;

                default:
                    trackingFacility = new USPSTracking(trackingNo);
                    break;
                }

                shippingResult = trackingFacility.GetTrackingResult();
            }
        }
Exemple #2
0
        public void TestShippingResult()
        {
            ShippingResult sr = new ShippingResult();

            sr.Shippable    = true;
            sr.ShippingRate = 12.975m;
            Assert.IsTrue(sr.Shippable);
            Assert.AreEqual(12.98, sr.ShippingRate);
        }
Exemple #3
0
        public ShippingStatus(DateTime dateTime, ShippingResult result)
        {
            if (!Enum.IsDefined(typeof(ShippingResult), result))
            {
                throw new ArgumentException($"Unexpected {nameof(ShippingResult)} value: {result}.");
            }

            this.DateTime = dateTime;
            this.Result   = result;
        }
Exemple #4
0
        public static string GetContractValue(ShippingResult shippingResult)
        {
            if (!Enum.IsDefined(typeof(ShippingResult), shippingResult))
            {
                throw new ArgumentOutOfRangeException(nameof(shippingResult));
            }

            var contractValue = (ShippingResultContract)shippingResult;

            if (!Enum.IsDefined(typeof(ShippingResultContract), contractValue))
            {
                throw new NotImplementedException("Missing adapter value.");
            }

            return(contractValue.ToString());
        }
        public override ShippingResult GetShippingResult(string ShipMethodName, Order ThisOrder, AnonymousAddress Address)
        {
            TraceContext   trace  = WebTrace.GetTraceContext();
            ShippingResult RetVal = new ShippingResult();

            RetVal.Shippable = false;

            CommerceBuilder.Orders.Basket basket = ThisOrder.AcBasket;
            if (basket == null)
            {
                basket = AcHelper.GetAcBasket(ThisOrder.ShoppingCart, true);
                if (basket != null)
                {
                    basket.Package(false);
                }
                ThisOrder.AcBasket = basket;
            }

            if (basket == null || basket.Shipments.Count == 0)
            {
                return(RetVal);
            }

            ShipMethodCollection shipMethods = ThisOrder.AcShipMethods;

            if (shipMethods == null)
            {
                shipMethods             = ShipMethodDataSource.LoadForStore();
                ThisOrder.AcShipMethods = shipMethods;
            }

            if (shipMethods == null || shipMethods.Count == 0)
            {
                return(RetVal);
            }

            ShipMethod shipMethod;
            string     methodName   = "";
            int        shipMethodId = AcHelper.ExtractShipMethodId(ShipMethodName, out methodName);

            if (shipMethodId != 0)
            {
                shipMethod = AcHelper.FindShipMethod(shipMethods, shipMethodId);
            }
            else
            {
                shipMethod = AcHelper.FindShipMethod(shipMethods, methodName);
            }
            if (shipMethod == null)
            {
                return(RetVal);
            }

            CommerceBuilder.Users.Address acAddress = AcHelper.GetAnonAcAddress(basket.User, Address);
            if (!shipMethod.IsApplicableTo(acAddress))
            {
                return(RetVal);
            }

            ShipRateQuote rateQuote;

            //TODO : should assign a default ship rate
            RetVal.ShippingRate = 0;
            bool isValid = true;

            foreach (Orders.BasketShipment bshipment in basket.Shipments)
            {
                bshipment.SetAddress(acAddress);
                if (!bshipment.IsShipMethodApplicable(shipMethod))
                {
                    isValid = false;
                    break;
                }
                rateQuote = shipMethod.GetShipRateQuote(bshipment);
                if (rateQuote != null && rateQuote.TotalRate > 0)
                {
                    RetVal.ShippingRate += rateQuote.TotalRate;
                }
                else if (rateQuote == null)
                {
                    //this ship method is not applicable
                    isValid = false;
                    break;
                }
            }

            if (isValid)
            {
                RetVal.Shippable = true;
            }

            return(RetVal);
        }