/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="fedExClientPolicy"></param> /// <returns></returns> internal static List <KeyValuePair <string, decimal> > GetShippingRates(FedexReqestInput input, FedExClientPolicy fedExClientPolicy) { FedExClientPolicy = fedExClientPolicy; var request = CreateRateRequest(input); var service = new RateService(); try { // Call the web service passing in a RateRequest and returning a RateReply var reply = service.getRates(request); if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) { return(ShowRateReply(reply)); } } catch (SoapException e) { Console.WriteLine(e.Detail.InnerText); } catch (Exception e) { Console.WriteLine(e.Message); } return(new List <KeyValuePair <string, decimal> >()); }
internal static List <KeyValuePair <string, decimal> > GetCartShippingRates(Cart cart, GetProductCommand getProductCommand, FedExClientPolicy fedExClientPolicy, CommerceContext commerceContext) { var input = new FedexReqestInput(); FedExClientPolicy = fedExClientPolicy; if (cart != null && cart.Lines.Any <CartLineComponent>() && cart.HasComponent <PhysicalFulfillmentComponent>()) { var component = cart.GetComponent <PhysicalFulfillmentComponent>(); var shippingParty = component?.ShippingParty; input.AddressLine1 = shippingParty.Address1; input.AddressLine2 = shippingParty.Address2; input.City = shippingParty.City; input.CountryCode = shippingParty.CountryCode; input.StateCode = shippingParty.StateCode; input.ZipPostalCode = shippingParty.ZipPostalCode; input.PriceValue = cart.Totals.SubTotal.Amount; decimal height = 0.0M; decimal width = 0.0M; decimal length = 0.0m; decimal weight = 0.0m; foreach (var cartLineComponent in cart.Lines) { // get specific weight value var productArgument = ProductArgument.FromItemId(cartLineComponent.ItemId); if (!productArgument.IsValid()) { continue; } var product = getProductCommand.Process(commerceContext, productArgument.CatalogName, productArgument.ProductId).Result; decimal val = 0m; if (product != null) { if (product.HasProperty(FedExClientPolicy.WeightFieldName) && product[FedExClientPolicy.WeightFieldName].ToString().Trim() != "") { val = GetFirstDecimalFromString(product[FedExClientPolicy.WeightFieldName].ToString()); } else { val = GetFirstDecimalFromString(FedExClientPolicy.Weight); } if (val > 0) { weight += val; } val = product.HasProperty(FedExClientPolicy.HeightFieldName) && product[FedExClientPolicy.HeightFieldName].ToString().Trim() != "" ? GetFirstDecimalFromString(product[FedExClientPolicy.HeightFieldName].ToString()) : GetFirstDecimalFromString(FedExClientPolicy.Height); if (val > 0) { height += val; } val = product.HasProperty(FedExClientPolicy.WidthFieldName) && product[FedExClientPolicy.WidthFieldName].ToString().Trim() != "" ? GetFirstDecimalFromString(product[FedExClientPolicy.WidthFieldName].ToString()) : GetFirstDecimalFromString(FedExClientPolicy.Width); if (val > 0 && val > width) { width = val; } val = product.HasProperty(FedExClientPolicy.LengthFieldName) && product[FedExClientPolicy.LengthFieldName].ToString().Trim() != "" ? GetFirstDecimalFromString(product[FedExClientPolicy.LengthFieldName].ToString()) : GetFirstDecimalFromString(FedExClientPolicy.Length); if (val > 0 && val > length) { length = val; } } } input.Height = Math.Ceiling(height).ToString(CultureInfo.CurrentCulture); input.Width = Math.Ceiling(width).ToString(CultureInfo.CurrentCulture); input.Length = Math.Ceiling(length).ToString(CultureInfo.CurrentCulture); input.Weight = Math.Ceiling(weight); } var rates = new List <KeyValuePair <string, decimal> >(); if (input.CountryCode.ToLower() == "us") { rates = FedxUs.GetShippingRates(input, FedExClientPolicy); } else { rates = FedExInternational.GetShippingRates(input, FedExClientPolicy); } return(rates); }