/// <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> >()); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="request"></param> private static void SetPackageLineItems(FedexReqestInput input, RateRequest request) { request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1]; request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem { SequenceNumber = "1", GroupPackageCount = "1", Weight = new Weight { Units = WeightUnits.LB, UnitsSpecified = true, Value = input.Weight, ValueSpecified = true } }; // package weight // package dimensions request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions { Length = input.Length, Width = input.Width, Height = input.Height, Units = LinearUnits.IN, UnitsSpecified = true }; }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="request"></param> private static void SetShipmentDetails(FedexReqestInput input, RateRequest request) { request.RequestedShipment = new RequestedShipment { ShipTimestamp = DateTime.Now, ShipTimestampSpecified = true, DropoffType = DropoffType.REGULAR_PICKUP, DropoffTypeSpecified = true, PackagingType = PackagingType.YOUR_PACKAGING, PackagingTypeSpecified = true }; // Shipping date and time //Drop off types are BUSINESS_SERVICE_CENTER, DROP_BOX, REGULAR_PICKUP, REQUEST_COURIER, STATION // SetOrigin(request); // SetDestination(input, request); // SetPackageLineItems(input, request); // request.RequestedShipment.PackageCount = "1"; //set to true to request COD shipment var isCodShipment = false; if (isCodShipment) { SetCod(request); } }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="request"></param> private static void SetPackageLineItems(FedexReqestInput input, RateRequest request) { request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1]; request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem { SequenceNumber = "1", GroupPackageCount = "1", Weight = new Weight { Units = WeightUnits.LB, UnitsSpecified = true, Value = input.Weight, ValueSpecified = true } }; // package weight // package dimensions request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions { Length = input.Length, Width = input.Width, Height = input.Height, Units = LinearUnits.IN, UnitsSpecified = true }; // Insurance request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money { Amount = input.PriceValue * FedExClientPolicy.CompensationMultipier, Currency = "USD" }; }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="request"></param> private static void SetDestination(FedexReqestInput input, RateRequest request) { request.RequestedShipment.Recipient = new RateAvailableServiceWebServiceClient.RateServiceWebReference.Party { Address = new Address { StreetLines = new string[2] { input.AddressLine1, input.AddressLine2 }, City = input.City, StateOrProvinceCode = input.StateCode, PostalCode = input.ZipPostalCode, CountryCode = input.CountryCode } }; }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> private static RateRequest CreateRateRequest(FedexReqestInput input) { // Build the RateRequest RateRequest request = new RateRequest { WebAuthenticationDetail = new WebAuthenticationDetail { UserCredential = new WebAuthenticationCredential { Key = FedExClientPolicy.Key, Password = FedExClientPolicy.Password } } }; request.WebAuthenticationDetail.ParentCredential = new WebAuthenticationCredential { Key = FedExClientPolicy.Key, Password = FedExClientPolicy.Password }; request.ClientDetail = new ClientDetail { AccountNumber = FedExClientPolicy.AccountNumber, MeterNumber = FedExClientPolicy.MeterNumber }; request.TransactionDetail = new TransactionDetail { CustomerTransactionId = "***Rate Available Services Request using VC#***" }; // This is a reference field for the customer. Any value can be used and will be provided in the response. request.Version = new VersionId(); request.ReturnTransitAndCommit = true; request.ReturnTransitAndCommitSpecified = true; SetShipmentDetails(input, request); // return(request); }
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); }