private static void ShowEdtDetail(RatedShipmentDetail ratedShipmentDetail) { // var rsd = rateReplyDetail.RatedShipmentDetails; // if (rsd == null) throw new ArgumentNullException("rateReplyDetail"); // foreach (var ratedShipmentDetail in rsd) // { if (ratedShipmentDetail != null) { var srd = ratedShipmentDetail.ShipmentRateDetail; var dat = srd.DutiesAndTaxes; if (dat != null) { foreach (var commodityTax in dat) { Console.WriteLine("HTC Code: {0}", commodityTax.HarmonizedCode); foreach (var tax in commodityTax.Taxes) { if (tax != null) { Console.WriteLine("{0} {1} : {2} {3} \nFormula: {4} \nTax Type: {5}", tax.Name, tax.Description.Replace("&", "").Replace("nbsp;", ""), tax.Amount.Amount, tax.Amount.Currency, tax.Formula, tax.TaxType ); } } } } } // } }
private ShippingOptionCollection ParseResponse(RateReply reply) { ShippingOptionCollection result = new ShippingOptionCollection(); Debug.WriteLine("RateReply details:"); Debug.WriteLine("**********************************************************"); foreach (RateReplyDetail rateDetail in reply.RateReplyDetails) { Debug.WriteLine("ServiceType: " + rateDetail.ServiceType); for (int i = 0; i < rateDetail.RatedShipmentDetails.Length; i++) { RatedShipmentDetail shipmentDetail = rateDetail.RatedShipmentDetails[i]; Debug.WriteLine("RateType : " + shipmentDetail.ShipmentRateDetail.RateType); Debug.WriteLine("Total Billing Weight : " + shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Value); Debug.WriteLine("Total Base Charge : " + shipmentDetail.ShipmentRateDetail.TotalBaseCharge.Amount); Debug.WriteLine("Total Discount : " + shipmentDetail.ShipmentRateDetail.TotalFreightDiscounts.Amount); Debug.WriteLine("Total Surcharges : " + shipmentDetail.ShipmentRateDetail.TotalSurcharges.Amount); Debug.WriteLine("Net Charge : " + shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount); Debug.WriteLine("*********"); //take first one if (i == 0) { ShippingOption shippingOption = new ShippingOption(); string userFriendlyServiceType = GetUserFriendlyEnum(rateDetail.ServiceType.ToString()); shippingOption.Name = userFriendlyServiceType; shippingOption.Rate = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount; result.Add(shippingOption); } } Debug.WriteLine("**********************************************************"); } return(result); }
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("**********************************************************"); } }
//public static void FedExShowShipmentRateDetails(RatedShipmentDetail shipmentDetail, Person shipto, ProductCollection cart) public static double FedExRate(RatedShipmentDetail shipmentDetail, Person shipto, ProductCollection cart) { double temp = 0; if (shipmentDetail == null) { return(-1); //***EAC something wrong? } if (shipmentDetail.ShipmentRateDetail == null) { return(-1); //***EAC something wrong? } ShipmentRateDetail rateDetail = shipmentDetail.ShipmentRateDetail; FedExNoelWrite("--- Shipment Rate Detail ---"); // FedExNoelWrite("RateType: " + rateDetail.RateType); if (rateDetail.TotalBillingWeight != null) { FedExNoelWrite("Total Billing Weight: " + rateDetail.TotalBillingWeight.Value + " " + shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Units); } if (rateDetail.TotalBaseCharge != null) { FedExNoelWrite("Total Base Charge: " + rateDetail.TotalBaseCharge.Amount + " " + rateDetail.TotalBaseCharge.Currency); } if (rateDetail.TotalFreightDiscounts != null) { FedExNoelWrite("Total Freight Discounts: " + rateDetail.TotalFreightDiscounts.Amount + " " + rateDetail.TotalFreightDiscounts.Currency); } if (rateDetail.TotalSurcharges != null) { FedExNoelWrite("Total Surcharges: " + rateDetail.TotalSurcharges.Amount + " " + rateDetail.TotalSurcharges.Currency); } if (rateDetail.Surcharges != null) { // Individual surcharge for each package foreach (Surcharge surcharge in rateDetail.Surcharges) { FedExNoelWrite(" surcharge " + surcharge.SurchargeType + " " + surcharge.Amount.Amount + " " + surcharge.Amount.Currency); } } if (rateDetail.TotalNetCharge != null) { FedExNoelWrite("Total Net Charge: " + rateDetail.TotalNetCharge.Amount + " " + rateDetail.TotalNetCharge.Currency); temp = (double)rateDetail.TotalNetCharge.Amount; } return(temp); }
private static void ShowShipmentRateDetails(RatedShipmentDetail shipmentDetail) { if (shipmentDetail == null) { return; } if (shipmentDetail.ShipmentRateDetail == null) { return; } ShipmentRateDetail rateDetail = shipmentDetail.ShipmentRateDetail; Console.WriteLine("--- Shipment Rate Detail ---"); // Console.WriteLine("RateType: {0} ", rateDetail.RateType); if (rateDetail.TotalBillingWeight != null) { Console.WriteLine("Total Billing Weight: {0} {1}", rateDetail.TotalBillingWeight.Value, shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Units); } if (rateDetail.TotalBaseCharge != null) { Console.WriteLine("Total Base Charge: {0} {1}", rateDetail.TotalBaseCharge.Amount, rateDetail.TotalBaseCharge.Currency); } if (rateDetail.TotalFreightDiscounts != null) { Console.WriteLine("Total Freight Discounts: {0} {1}", rateDetail.TotalFreightDiscounts.Amount, rateDetail.TotalFreightDiscounts.Currency); } if (rateDetail.TotalSurcharges != null) { Console.WriteLine("Total Surcharges: {0} {1}", rateDetail.TotalSurcharges.Amount, rateDetail.TotalSurcharges.Currency); } if (rateDetail.Surcharges != null) { // Individual surcharge for each package foreach (Surcharge surcharge in rateDetail.Surcharges) { Console.WriteLine(" {0} surcharge {1} {2}", surcharge.SurchargeType, surcharge.Amount.Amount, surcharge.Amount.Currency); } } if (rateDetail.TotalNetCharge != null) { Console.WriteLine("Total Net Charge: {0} {1}", rateDetail.TotalNetCharge.Amount, rateDetail.TotalNetCharge.Currency); } }
public void ShowShipmentRateDetails(RatedShipmentDetail shipmentDetail) { if (shipmentDetail == null) { return; } if (shipmentDetail.ShipmentRateDetail == null) { return; } ShipmentRateDetail rateDetail = shipmentDetail.ShipmentRateDetail; // DB.LogGenera("FedEx", "", "RateType: {0}" + rateDetail.RateType); if (rateDetail.TotalBillingWeight != null) { DB.LogGenera("FedEx", "", string.Concat("Total Billing Weight: {0} {1}", rateDetail.TotalBillingWeight.Value, shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Units)); } if (rateDetail.TotalBaseCharge != null) { DB.LogGenera("FedEx", "", string.Concat("Total Base Charge: {0} {1}", rateDetail.TotalBaseCharge.Amount, rateDetail.TotalBaseCharge.Currency)); } if (rateDetail.TotalFreightDiscounts != null) { DB.LogGenera("FedEx", "", string.Concat("Total Freight Discounts: {0} {1}", rateDetail.TotalFreightDiscounts.Amount, rateDetail.TotalFreightDiscounts.Currency)); } if (rateDetail.TotalSurcharges != null) { DB.LogGenera("FedEx", "", string.Concat("Total Surcharges: {0} {1}", rateDetail.TotalSurcharges.Amount, rateDetail.TotalSurcharges.Currency)); } if (rateDetail.Surcharges != null) { // Individual surcharge for each package foreach (Surcharge surcharge in rateDetail.Surcharges) { DB.LogGenera("FedEx", "", string.Concat(" {0} surcharge {1} {2}", surcharge.SurchargeType, surcharge.Amount.Amount, surcharge.Amount.Currency)); } } if (rateDetail.TotalNetCharge != null) { DB.LogGenera("FedEx", "", string.Concat("Total Net Charge: {0} {1}", rateDetail.TotalNetCharge.Amount, rateDetail.TotalNetCharge.Currency)); } ShowFreightRateDetail(rateDetail.FreightRateDetail); }
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); } }