private static void ShowRateReply(RateReply reply) { Console.WriteLine("RateReply details:"); for (int i = 0; i < reply.RateReplyDetails.Length; i++) { RateReplyDetail rateReplyDetail = reply.RateReplyDetails[i]; Console.WriteLine("Rate Reply Detail for Service {0} ", i + 1); if (rateReplyDetail.ServiceTypeSpecified) { Console.WriteLine("Service Type: {0}", rateReplyDetail.ServiceType); } if (rateReplyDetail.PackagingTypeSpecified) { Console.WriteLine("Packaging Type: {0}", rateReplyDetail.PackagingType); } for (int j = 0; j < rateReplyDetail.RatedShipmentDetails.Length; j++) { RatedShipmentDetail shipmentDetail = rateReplyDetail.RatedShipmentDetails[j]; Console.WriteLine("---Rated Shipment Detail for Rate Type {0}---", j + 1); ShowShipmentRateDetails(shipmentDetail); ShowPackageRateDetails(shipmentDetail.RatedPackages); } ShowDeliveryDetails(rateReplyDetail); Console.WriteLine("**********************************************************"); } }
private static void ShowDeliveryDetails(RateReplyDetail rateDetail) { if (rateDetail.DeliveryTimestampSpecified) { Console.WriteLine("Delivery timestamp: " + rateDetail.DeliveryTimestamp); } if (rateDetail.TransitTimeSpecified) { Console.WriteLine("Transit time: " + rateDetail.TransitTime); } }
private static void ShowDeliveryDetails(RateReplyDetail rateDetail) { if (rateDetail.DeliveryTimestampSpecified) { DB.LogGenera("FedEx", "", "Delivery timestamp: " + rateDetail.DeliveryTimestamp.ToString()); } if (rateDetail.TransitTimeSpecified) { DB.LogGenera("FedEx", "", "Transit Time: " + rateDetail.TransitTime); } }
public static void FedExShowDeliveryDetails(RateReplyDetail rateDetail) { if (rateDetail.DeliveryTimestampSpecified) { FedExNoelWrite("Delivery timestamp: " + rateDetail.DeliveryTimestamp.ToString()); } if (rateDetail.TransitTimeSpecified) { FedExNoelWrite("Transit time: " + rateDetail.TransitTime); } }
private Dictionary <string, ProviderShipRateQuote> ParseRates(RateReply reply) { Dictionary <string, ProviderShipRateQuote> quotes = new Dictionary <string, ProviderShipRateQuote>(); for (int i = 0; i < reply.RateReplyDetails.Length; i++) { RateReplyDetail rdetail = reply.RateReplyDetails[i]; RatedShipmentDetail rsdetail = GetRatedShipmentDetail(rdetail.RatedShipmentDetails); if (rsdetail != null) { ProviderShipRateQuote psrq = new ProviderShipRateQuote(); psrq.ServiceCode = rdetail.ServiceType.ToString(); //psrq.Name = GetServiceName(psrq.ServiceCode); psrq.ServiceName = GetServiceName(psrq.ServiceCode); psrq.Rate = rsdetail.ShipmentRateDetail.TotalNetCharge.Amount; quotes.Add(psrq.ServiceCode, psrq); } } return(quotes); }
private void FedExGetRates(Shipments AllShipments, out string RTShipRequest, out string RTShipResponse, decimal ExtraFee, Decimal MarkupPercent, decimal ShipmentValue, decimal ShippingTaxRate) // Retrieves FedEx rates { RTShipRequest = string.Empty; RTShipResponse = string.Empty; Decimal maxWeight = AppLogic.AppConfigUSDecimal("RTShipping.Fedex.MaxWeight"); if (maxWeight == 0) { maxWeight = 150; } if (ShipmentWeight > maxWeight) { SM.ErrorMsg = "FedEx " + AppLogic.AppConfig("RTShipping.CallForShippingPrompt"); return; } foreach (Packages Shipment in AllShipments) { foreach (Package p in Shipment) { if (p.IsFreeShipping) { HasFreeItems = true; break; } } RateRequest request = CreateRateRequest(Shipment); RateService service = new RateService(); // Initialize the service service.Url = this.FedexServer; try { RateReply reply = service.getRates(request); string rateRequest = SerializeObject(request); string rateReply = SerializeObject(reply); System.Diagnostics.Debug.WriteLine(rateRequest); System.Diagnostics.Debug.WriteLine(rateReply); if (reply.RateReplyDetails != null && (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING))// check if the call was successful { //create list of available services for (int i = 0; i < reply.RateReplyDetails.Length; i++) { RateReplyDetail rateReplyDetail = reply.RateReplyDetails[i]; // listRatedShipmentDetail is currently unused - could be used in the future to support list or pro-rated rates RatedShipmentDetail listRatedShipmentDetail = rateReplyDetail.RatedShipmentDetails .FirstOrDefault(rsd => rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_LIST_PACKAGE || rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_LIST_PACKAGE || rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_LIST_SHIPMENT || rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_LIST_SHIPMENT); RatedShipmentDetail ratedShipmentDetail = rateReplyDetail.RatedShipmentDetails .FirstOrDefault(rsd => rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_PACKAGE || rsd.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_SHIPMENT || rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_ACCOUNT_PACKAGE || rsd.ShipmentRateDetail.RateType == ReturnedRateType.RATED_ACCOUNT_SHIPMENT); string rateName = "FedEx " + FedExGetCodeDescription(rateReplyDetail.ServiceType.ToString()); if (ShippingMethodIsAllowed(rateName, "FEDEX")) { decimal totalCharges = ratedShipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount; //multiply the returned rate by the quantity in the package to avoid calling //more than necessary if there were multiple IsShipSeparately items //ordered. If there weren't, Shipment.PackageCount is 1 and the rate is normal totalCharges = totalCharges * Shipment.PackageCount; if (MarkupPercent != System.Decimal.Zero) { totalCharges = Decimal.Round(totalCharges * (1.00M + (MarkupPercent / 100.0M)), 2, MidpointRounding.AwayFromZero); } decimal vat = Decimal.Round(totalCharges * ShippingTaxRate, 2, MidpointRounding.AwayFromZero); if (!SM.MethodExists(rateName)) { ShipMethod s_method = new ShipMethod(); s_method.Carrier = "FEDEX"; s_method.ServiceName = rateName; s_method.ServiceRate = totalCharges; s_method.VatRate = vat; if (HasFreeItems) { s_method.FreeItemsRate = totalCharges; } SM.AddMethod(s_method); } else { int IndexOf = SM.GetIndex(rateName); ShipMethod s_method = SM[IndexOf]; s_method.ServiceRate += totalCharges; s_method.VatRate += vat; if (HasFreeItems) { s_method.FreeItemsRate += totalCharges; } SM[IndexOf] = s_method; } } } // Handling fee should only be added per shipping address not per package // let's just compute it here after we've gone through all the packages. // Also, since we can't be sure about the ordering of the method call here // and that the collection SM includes shipping methods from all possible carriers // we'll need to filter out the methods per this carrier to avoid side effects on the main collection foreach (ShipMethod shipMethod in SM.PerCarrier("FEDEX")) { shipMethod.ServiceRate += ExtraFee; } } else { RTShipResponse = "Error: Call Not Successful " + reply.Notifications[0].Message; } RTShipRequest = Serialize(request); RTShipResponse = Serialize(reply); } catch (SoapException e) { RTShipResponse = "FedEx Error: " + e.Detail.InnerXml; } catch (Exception e) { RTShipResponse = "FedEx Error: " + e.InnerException.Message; } } }
private void FedExGetRates(Packages Shipment, out string RTShipRequest, out string RTShipResponse, decimal ExtraFee, Decimal MarkupPercent, decimal ShipmentValue, decimal ShippingTaxRate) // Retrieves FedEx rates { RTShipRequest = string.Empty; RTShipResponse = string.Empty; Hashtable htRates = new Hashtable(); RateRequest request = CreateRateRequest(Shipment); RateService service = new RateService(); // Initialize the service service.Url = this.FedexServer; try { // Call the web service passing in a RateRequest and returning a RateReply RateReply reply = service.getRates(request); if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful { //create list of available services for (int i = 0; i < reply.RateReplyDetails.Length; i++) { RateReplyDetail rateReplyDetail = reply.RateReplyDetails[i]; RatedShipmentDetail ratedShipmentDetail = rateReplyDetail.RatedShipmentDetails[1]; decimal totalCharges = ratedShipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount; if (MarkupPercent != System.Decimal.Zero) { totalCharges = Decimal.Round(totalCharges * (1.00M + (MarkupPercent / 100.0M)), 2, MidpointRounding.AwayFromZero); } decimal vat = Decimal.Round(totalCharges * ShippingTaxRate, 2, MidpointRounding.AwayFromZero); string rateName = rateReplyDetail.ServiceType.ToString(); if (htRates.ContainsKey(rateName)) { // Get the sum of the rate(s) decimal myTempCharge = Localization.ParseUSDecimal(htRates[rateName].ToString().Split('|')[0]); totalCharges += myTempCharge; vat += Localization.ParseUSDecimal(htRates[rateName].ToString().Split('|')[1]); // Remove the old value & add the new htRates.Remove(rateName); } // Temporarily add rate to hash table htRates.Add(rateName, Localization.CurrencyStringForDBWithoutExchangeRate(totalCharges) + "|" + Localization.CurrencyStringForDBWithoutExchangeRate(vat)); } } else { ratesText.Add("Error: Call Not Successful"); ratesValues.Add("Error: Call Not Successful"); } RTShipRequest = Serialize(request); RTShipResponse = Serialize(reply); } catch (SoapException e) { ratesText.Add("Error: " + e.Detail.InnerText); ratesValues.Add("Error: " + e.Detail.InnerText); } catch (Exception e) { ratesText.Add("Error: " + e.Message); ratesValues.Add("Error: " + e.Message); } // Add rates from hastable into array(s) IDictionaryEnumerator myEnumerator = htRates.GetEnumerator(); while (myEnumerator.MoveNext()) { Decimal tmp_rate = Localization.ParseUSDecimal(myEnumerator.Value.ToString().Substring(0, myEnumerator.Value.ToString().IndexOf("|"))) + ExtraFee; Decimal tmp_vat = Localization.ParseUSDecimal(myEnumerator.Value.ToString().Substring(myEnumerator.Value.ToString().LastIndexOf("|") + 1)); String rateText = tmp_rate.ToString() + "|" + tmp_vat.ToString(); ratesText.Add(myEnumerator.Key.ToString() + " $" + rateText); ratesValues.Add(myEnumerator.Key.ToString() + "|" + rateText); } }