Exemplo n.º 1
0
        public ShippingResponse getShipping(HttpContext ctx) {
            Customer customer = new Customer();
            Settings settings = ViewBag.settings;
            customer.GetFromStorage(ctx);
            FedExAuthentication auth = new FedExAuthentication {
                AccountNumber = Convert.ToInt32(settings.Get("FedExAccount")),
                Key = settings.Get("FedExKey"),
                Password = settings.Get("FedExPassword"),
                CustomerTransactionId = "",
                MeterNumber = Convert.ToInt32(settings.Get("FedExMeter"))
            };

            customer.Cart.BindAddresses();

            ShippingAddress destination = new ShippingAddress();
            try {
                destination = customer.Cart.Shipping.getShipping();
            } catch (Exception) {
                Response.Redirect("/Cart/Checkout");
            }
            DistributionCenter d = new DistributionCenter().GetNearest(customer.Cart.Shipping.GeoLocate());
            ShippingAddress origin = d.getAddress().getShipping();
            List<int> parts = new List<int>();
            foreach (CartItem item in customer.Cart.CartItems) {
                for (int i = 1; i <= item.quantity; i++) {
                    parts.Add(item.partID);
                }
            }
            ShippingResponse response = CURTAPI.GetShipping(auth, origin, destination, parts);

            return response;
        }
Exemplo n.º 2
0
        internal static ShippingResponse GetShipping(FedExAuthentication auth, ShippingAddress origin, ShippingAddress dest, List<int> parts)
        {
            ShippingResponse response = new ShippingResponse();
            try {
                WebClient wc = new WebClient();
                wc.Proxy = null;

                Settings settings = new Settings();
                wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
                string URI = settings.Get("CURTAPISHIPPINGDOMAIN") + "GetShipping";
                string parameters = "dataType=JSON";
                parameters += "&auth=" + Newtonsoft.Json.JsonConvert.SerializeObject(auth);
                parameters += "&origin=" + Newtonsoft.Json.JsonConvert.SerializeObject(origin);
                parameters += "&destination=" + Newtonsoft.Json.JsonConvert.SerializeObject(dest);
                parameters += "&parts=" + Newtonsoft.Json.JsonConvert.SerializeObject(parts);
                if (settings.Get("FedExEnvironment") == "development") {
                    parameters += "&environment=development";
                } else {
                    parameters += "&environment=production";
                }
                string APIresponse = wc.UploadString(URI, parameters);
                response = JsonConvert.DeserializeObject<ShippingResponse>(APIresponse);
                if (response.Status == "ERROR") {
                    throw new Exception("FedEx is having issues at the moment. Please try again.");
                }
            } catch (Exception) { }
            return response;
        }
Exemplo n.º 3
0
        public ShippingResponse getShipping()
        {
            Settings settings = new Settings();
            FedExAuthentication auth = new FedExAuthentication {
                AccountNumber = Convert.ToInt32(settings.Get("FedExAccount")),
                Key = settings.Get("FedExKey"),
                Password = settings.Get("FedExPassword"),
                CustomerTransactionId = "",
                MeterNumber = Convert.ToInt32(settings.Get("FedExMeter"))
            };

            ShippingAddress destination = new ShippingAddress();
            destination = this.Shipping.getShipping();
            DistributionCenter d = new DistributionCenter().GetNearest(this.Shipping.GeoLocate());
            ShippingAddress origin = d.getAddress().getShipping();
            List<int> parts = new List<int>();
            foreach (CartItem item in this.CartItems) {
                for (int i = 1; i <= item.quantity; i++) {
                    parts.Add(item.partID);
                }
            }

            ShippingResponse response = CURTAPI.GetShipping(auth, origin, destination, parts);

            return response;
        }