public override void GetRates() { RateRequest request = CreateRateRequest(); var service = new RateService(); 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) { ProcessReply(reply); } ShowNotifications(reply); } catch (SoapException e) { Debug.WriteLine(e.Detail.InnerText); } catch (Exception e) { Debug.WriteLine(e.Message); } }
static void Main(string[] args) { RateRequest request = CreateRateRequest(); // RateService service = new RateService(); if (usePropertyFile()) { service.Url = getProperty("endpoint"); } 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) { ShowRateReply(reply); } ShowNotifications(reply); } catch (SoapException e) { Console.WriteLine(e.Detail.InnerText); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Press any key to quit!"); Console.ReadKey(); }
private void ProcessErrors(RateReply reply) { var errorTypes = new NotificationSeverityType[] { NotificationSeverityType.ERROR, NotificationSeverityType.FAILURE }; var noReplyDetails = reply.RateReplyDetails == null; if (reply.Notifications != null && reply.Notifications.Any()) { var errors = reply.Notifications .Where(e => !e.SeveritySpecified || errorTypes.Contains(e.Severity) || noReplyDetails) .Select(error => new Error { Description = error.Message, Source = error.Source, Number = error.Code }); foreach (var err in errors) { AddError(err); } } }
/// <summary> /// Processes the reply /// </summary> /// <param name="reply"></param> protected void ProcessReply(RateReply reply) { if (reply?.RateReplyDetails == null) { return; } foreach (var rateReplyDetail in reply.RateReplyDetails) { var key = rateReplyDetail.ServiceType.ToString(); if (!_serviceCodes.Keys.Contains(key)) { AddInternalError($"Unknown FedEx rate code: {key}"); } else { var netCharge = rateReplyDetail.RatedShipmentDetails.Max(r => GetCurrencyConvertedRate(r.ShipmentRateDetail)); var deliveryDate = rateReplyDetail.DeliveryTimestampSpecified ? rateReplyDetail.DeliveryTimestamp : DateTime.Now.AddDays(30); AddRate(key, _serviceCodes[key], netCharge, deliveryDate, new RateOptions() { SaturdayDelivery = rateReplyDetail.AppliedOptions?.Contains(ServiceOptionType.SATURDAY_DELIVERY) ?? false }); } } }
/// <summary> /// Processes the reply /// </summary> /// <param name="reply"></param> protected void ProcessReply(RateReply reply) { if (reply?.RateReplyDetails == null) { return; } foreach (var rateReplyDetail in reply.RateReplyDetails) { var key = rateReplyDetail.ServiceType.ToString(); if (!ServiceCodes.Keys.Contains(key)) { AddInternalError($"Unknown FedEx rate code: {key}"); } else { var rates = rateReplyDetail.RatedShipmentDetails.Select(r => GetCurrencyConvertedRate(r.ShipmentRateDetail)); rates = rates.Any(r => r.currencyCode == Shipment.Options.GetCurrencyCode()) ? rates.Where(r => r.currencyCode == Shipment.Options.GetCurrencyCode()) : rates; var netCharge = rates.OrderByDescending(r => r.amount).FirstOrDefault(); var deliveryDate = rateReplyDetail.DeliveryTimestampSpecified ? rateReplyDetail.DeliveryTimestamp : DateTime.Now.AddDays(30); AddRate(key, ServiceCodes[key], netCharge.amount, deliveryDate, new RateOptions() { SaturdayDelivery = rateReplyDetail.AppliedOptions?.Contains(ServiceOptionType.SATURDAY_DELIVERY) ?? false }, netCharge.currencyCode); } } }
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 double FedExEstimatedRate(Person shipto, ProductCollection cart) { double temp = 0.0; //return 0.0 if something is wrong RateRequest request = FedEx.FedExCreateRateRequest(shipto, cart); //TODO: better to use shoppingcartV2 if it was available RateService service = new RateService(); // Initialize the service 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 { //ShowRateReply(reply); for (int i = 0; i < reply.RateReplyDetails[0].RatedShipmentDetails.Count(); i++) { ShipmentRateDetail rateDetail = reply.RateReplyDetails[0].RatedShipmentDetails[i].ShipmentRateDetail; if ((double)rateDetail.TotalNetCharge.Amount > temp) { temp = (double)rateDetail.TotalNetCharge.Amount; } } } FedEx.FedExShowNotifications(reply); } catch (Exception ex) { temp = 0.0; } return(temp); }
private List <ShippingOption> ParseResponse(RateReply reply) { var additionalFee = IoC.Resolve <ISettingManager>().GetSettingValueDecimalNative("ShippingRateComputationMethod.FedEx.AdditionalFee", 0); string carrierServicesOffered = IoC.Resolve <ISettingManager>().GetSettingValue("ShippingRateComputationMethod.FedEx.CarrierServicesOffered"); bool applyDiscount = IoC.Resolve <ISettingManager>().GetSettingValueBoolean("ShippingRateComputationMethod.FedEx.ApplyDiscounts", false); var result = new List <ShippingOption>(); Debug.WriteLine("RateReply details:"); Debug.WriteLine("**********************************************************"); foreach (var rateDetail in reply.RateReplyDetails) { var shippingOption = new ShippingOption(); string serviceName = FedExServices.GetServiceName(rateDetail.ServiceType.ToString()); // Skip the current service if services are selected and this service hasn't been selected if (!String.IsNullOrEmpty(carrierServicesOffered) && !carrierServicesOffered.Contains(rateDetail.ServiceType.ToString())) { continue; } Debug.WriteLine("ServiceType: " + rateDetail.ServiceType); if (!serviceName.Equals("UNKNOWN")) { shippingOption.Name = serviceName; Debug.WriteLine("ServiceType: " + rateDetail.ServiceType); foreach (RatedShipmentDetail shipmentDetail in rateDetail.RatedShipmentDetails) { 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("*********"); // Get discounted rates if option is selected if (applyDiscount == true & shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT) { shippingOption.Rate = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + additionalFee; break; } else if (shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_LIST) // Get List Rates (not discount rates) { shippingOption.Rate = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + additionalFee; break; } else // Skip the rate (RATED_ACCOUNT, PAYOR_MULTIWEIGHT, or RATED_LIST) { continue; } } result.Add(shippingOption); } Debug.WriteLine("**********************************************************"); } return(result); }
public List <ShippingOption> GetShippingOptions() { var shippingOptions = new List <ShippingOption>(); RateRequest request = CreateRateRequest(); // var service = new RateService(); // Initialize the service 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 { shippingOptions = ParseAnswer(reply); } else { Debug.LogError(new Exception(reply.Notifications[0].Message), false); } } catch (SoapException e) { Debug.LogError(e); } catch (Exception e) { Debug.LogError(e); } return(shippingOptions); }
private ShippingOptionCollection ParseResponse(RateReply reply) { var result = new ShippingOptionCollection(); Debug.WriteLine("RateReply details:"); Debug.WriteLine("**********************************************************"); foreach (var rateDetail in reply.RateReplyDetails) { Debug.WriteLine("ServiceType: " + rateDetail.ServiceType); for (int i = 0; i < rateDetail.RatedShipmentDetails.Length; i++) { var 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) { var 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:"); foreach (RateReplyDetail rateReplyDetail in reply.RateReplyDetails) { if (rateReplyDetail.ServiceTypeSpecified) { Console.WriteLine("Service Type: {0}", rateReplyDetail.ServiceType); } if (rateReplyDetail.PackagingTypeSpecified) { Console.WriteLine("Packaging Type: {0}", rateReplyDetail.PackagingType); } Console.WriteLine(); foreach (RatedShipmentDetail shipmentDetail in rateReplyDetail.RatedShipmentDetails) { ShowShipmentRateDetails(shipmentDetail); Console.WriteLine(); ShowEdtDetail(shipmentDetail); Console.WriteLine(); } ShowDeliveryDetails(rateReplyDetail); Console.WriteLine("**********************************************************"); } }
private string Serialize(RateReply reply) { XmlSerializer serRateReply = new XmlSerializer(typeof(AspDotNetStorefrontCore.RateServiceWebReference.RateReply)); StringWriter swRateReply = new StringWriter(); serRateReply.Serialize(swRateReply, reply); return(swRateReply.ToString()); }
private List <ShippingOption> ParseResponse(RateReply reply, Currency requestedShipmentCurrency) { var result = new List <ShippingOption>(); Debug.WriteLine("RateReply details:"); Debug.WriteLine("**********************************************************"); foreach (var rateDetail in reply.RateReplyDetails) { var shippingOption = new ShippingOption(); string serviceName = FedexServices.GetServiceName(rateDetail.ServiceType.ToString()); // Skip the current service if services are selected and this service hasn't been selected if (!String.IsNullOrEmpty(_fedexSettings.CarrierServicesOffered) && !_fedexSettings.CarrierServicesOffered.Contains(rateDetail.ServiceType.ToString())) { continue; } Debug.WriteLine("ServiceType: " + rateDetail.ServiceType); if (!serviceName.Equals("UNKNOWN")) { shippingOption.Name = serviceName; foreach (RatedShipmentDetail shipmentDetail in rateDetail.RatedShipmentDetails) { 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 + "(" + shipmentDetail.ShipmentRateDetail.TotalNetCharge.Currency + ")"); Debug.WriteLine("*********"); // Get discounted rates if option is selected if (_fedexSettings.ApplyDiscounts & shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT) { decimal amount = ConvertChargeToPrimaryCurrency(shipmentDetail.ShipmentRateDetail.TotalNetCharge, requestedShipmentCurrency); shippingOption.Rate = amount + _fedexSettings.AdditionalHandlingCharge; break; } else if (shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_LIST) // Get List Rates (not discount rates) { decimal amount = ConvertChargeToPrimaryCurrency(shipmentDetail.ShipmentRateDetail.TotalNetCharge, requestedShipmentCurrency); shippingOption.Rate = amount + _fedexSettings.AdditionalHandlingCharge; break; } else // Skip the rate (RATED_ACCOUNT, PAYOR_MULTIWEIGHT, or RATED_LIST) { continue; } } result.Add(shippingOption); } Debug.WriteLine("**********************************************************"); } return(result); }
private List <ShippingOption> GetAvailableRates(FedExApi api, WA.Shipping.AddressInfo fedExOrigin, WA.Shipping.AddressInfo fedExDestination, List <PackageInfo> fedExPackages) { List <ShippingOption> options = new List <ShippingOption>(); RateReply reply = api.GetAvailableRates(fedExOrigin, fedExDestination, fedExPackages); if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE) // || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful { if (reply.RateReplyDetails.Length > 0) { foreach (RateReplyDetail rateDetail in reply.RateReplyDetails) { //Console.WriteLine("ServiceType: " + rateDetail.ServiceType); foreach (RatedShipmentDetail shipmentDetail in rateDetail.RatedShipmentDetails) { //Console.WriteLine("RateType : " + shipmentDetail.ShipmentRateDetail.RateType); //Console.WriteLine("Total Billing Weight : " + shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Value); //Console.WriteLine("Total Base Charge : " + shipmentDetail.ShipmentRateDetail.TotalBaseCharge.Amount); //Console.WriteLine("Total Discount : " + shipmentDetail.ShipmentRateDetail.TotalFreightDiscounts.Amount); //Console.WriteLine("Total Surcharges : " + shipmentDetail.ShipmentRateDetail.TotalSurcharges.Amount); //Console.WriteLine("Net Charge : " + shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount); //Console.WriteLine("*********"); if (shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_PACKAGE) { options.Add(new ShippingOption() { ProviderType = providerType, Name = rateDetail.ServiceType.ToString(), DisplayName = ServiceTypeToDisplayName(rateDetail.ServiceType), Cost = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount }); } } //if (rateDetail.DeliveryTimestampSpecified) //{ // Console.WriteLine("Delivery timestamp " + rateDetail.DeliveryTimestamp.ToString()); //} //Console.WriteLine("Transit Time: " + rateDetail.TransitTime); } } } else { foreach (var error in reply.Notifications) { if (error.Severity == NotificationSeverityType.ERROR || error.Severity == NotificationSeverityType.FAILURE || error.Severity == NotificationSeverityType.WARNING) { ErrorMessages.Add(string.Format(@"Code: {0}, Error: {1}", error.Code, error.Message)); } } } return(options); }
private void ProcessReply(RateReply reply) { foreach (RateReplyDetail rateReplyDetail in reply.RateReplyDetails) { decimal netCharge = rateReplyDetail.RatedShipmentDetails.Max(x => x.ShipmentRateDetail.TotalNetCharge.Amount); string key = rateReplyDetail.ServiceType.ToString(); DateTime deliveryDate = rateReplyDetail.DeliveryTimestampSpecified ? rateReplyDetail.DeliveryTimestamp : DateTime.Now.AddDays(30); AddRate(key, _serviceCodes[key], netCharge, deliveryDate); } }
public static void FedExShowNotifications(RateReply reply) { FedExNoelWrite("Notifications"); for (int i = 0; i < reply.Notifications.Length; i++) { Notification notification = reply.Notifications[i]; FedExNoelWrite("Notification no. " + i); FedExNoelWrite(" Severity:" + notification.Severity); FedExNoelWrite(" Code: " + notification.Code); FedExNoelWrite(" Message: " + notification.Message); FedExNoelWrite(" Source: " + notification.Source); } }
private static void ShowNotifications(RateReply reply) { Debug.WriteLine("Notifications"); for (int i = 0; i < reply.Notifications.Length; i++) { Notification notification = reply.Notifications[i]; Debug.WriteLine("Notification no. {0}", i); Debug.WriteLine(" Severity: {0}", notification.Severity); Debug.WriteLine(" Code: {0}", notification.Code); Debug.WriteLine(" Message: {0}", notification.Message); Debug.WriteLine(" Source: {0}", notification.Source); } }
/// <summary> /// Processes the reply /// </summary> /// <param name="reply"></param> protected void ProcessReply(RateReply reply) { foreach (var rateReplyDetail in reply.RateReplyDetails) { var netCharge = rateReplyDetail.RatedShipmentDetails.Max(x => x.ShipmentRateDetail.TotalNetCharge.Amount); var key = rateReplyDetail.ServiceType.ToString(); var deliveryDate = rateReplyDetail.DeliveryTimestampSpecified ? rateReplyDetail.DeliveryTimestamp : DateTime.Now.AddDays(30); if (_serviceCodes.ContainsKey(key)) { AddRate(key, _serviceCodes[key], netCharge, deliveryDate); } } }
public decimal GetRate(string weight, string shipperZipCode, string shipperCountryCode, string destinationZipCode, string destinationCountryCode, string serviceCode) { decimal rate = 0; // Build the RateRequest RateRequest request = new RateRequest(); // request.WebAuthenticationDetail = new WebAuthenticationDetail(); request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential(); request.WebAuthenticationDetail.UserCredential.Key = m_serviceKey; // Replace "XXX" with the Key request.WebAuthenticationDetail.UserCredential.Password = m_servicePassword; // Replace "XXX" with the Password // request.ClientDetail = new ClientDetail(); request.ClientDetail.AccountNumber = m_accountNumber; // Replace "XXX" with client's account number request.ClientDetail.MeterNumber = m_meterNumber; // Replace "XXX" with client's meter number // request.TransactionDetail = new TransactionDetail(); request.TransactionDetail.CustomerTransactionId = "***Rate v7 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(); // WSDL version information, value is automatically set from wsdl // request.ReturnTransitAndCommit = true; request.ReturnTransitAndCommitSpecified = true; request.CarrierCodes = new CarrierCodeType[1]; request.CarrierCodes[0] = CarrierCodeType.FDXE; //set the shipment details SetShipmentDetails(request, serviceCode); //Set the Origin SetOrigin(request, shipperZipCode, shipperCountryCode); //Set the Destination SetDestination(request, destinationZipCode, destinationCountryCode); //Set the Payment SetPayment(request); //Set the Summary SetSummaryPackageLineItems(request, weight); RateService service = new RateService(); // Initialize the service RateReply reply = service.getRates(request); if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) // check if the call was successful { rate = reply.RateReplyDetails[0].RatedShipmentDetails[0].ShipmentRateDetail.TotalNetCharge.Amount; } return(rate); }
private static IEnumerable <DeliveryOption> BuildDeliveryOptions(RateReply rateReply, IShipment shipment) { var optionCollection = new DeliveryOptionCollection(); foreach (var rateReplyDetail in rateReply.RateReplyDetails) { var service = rateReplyDetail.ServiceType.ToString(); optionCollection.AddRange(rateReplyDetail.RatedShipmentDetails.Select(shipmentDetail => shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount).Select(rate => new DeliveryOption { Rate = rate, Service = service })); } return(optionCollection); }
private List <ShippingOption> ParseAnswer(RateReply reply) { var res = new List <ShippingOption>(); var enabledServices = EnabledService; foreach (var rateDetail in reply.RateReplyDetails) { var shippingOption = new ShippingOption(); if (!String.IsNullOrEmpty(enabledServices) && !enabledServices.Contains(rateDetail.ServiceType.ToString())) { continue; } string serviceName = GetServiceName(rateDetail.ServiceType.ToString()); shippingOption.Name = serviceName; foreach (RatedShipmentDetail shipmentDetail in rateDetail.RatedShipmentDetails) { shippingOption.Rate = Rate > 0 ? (float)shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount * Rate + Extracharge : (float)shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + Extracharge; // Vladimir: Старый код вытаскивал только некоторые Rate. Не знаю зачем. Пусть будут все. //if (shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_SHIPMENT) //{ // shippingOption.Rate = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + Extracharge; // if (Rate > 0) // { // shippingOption.Rate *= Rate; // } // break; //} //if (shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_LIST_SHIPMENT) // Get List Rates (not discount rates) //{ // shippingOption.Rate = Rate > 0 ? shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount * Rate + Extracharge // : shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + Extracharge; // break; //} //var shippingRate = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + Extracharge; //if (Rate > 0) //{ // shippingRate *= Rate; //} //shippingOption.Rate = shippingRate; } res.Add(shippingOption); } return(res); }
public void ShowNotifications(RateReply reply) { DB.LogGenera("FedEx", "", "Notifications"); for (int i = 0; i < reply.Notifications.Length; i++) { Notification notification = reply.Notifications[i]; DB.LogGenera("FedEx", "", string.Concat("Notification no. {0}", i)); if (notification.SeveritySpecified) { DB.LogGenera("FedEx", "", string.Concat(" Severity: {0}", notification.Severity)); } DB.LogGenera("FedEx", "", string.Concat(" Code: {0}", notification.Code)); DB.LogGenera("FedEx", "", string.Concat(" Message: {0}", notification.Message)); DB.LogGenera("FedEx", "", string.Concat(" Source: {0}", notification.Source)); } }
public void ShowRateReply(RateReply reply) { DB.LogGenera("FedEx", "", "RateReply details:"); foreach (RateReplyDetail rateDetail in reply.RateReplyDetails) { DB.LogGenera("FedEx", "", "ServiceType: {0}" + rateDetail.ServiceType); //DB.LogGenera("FedEx","",); foreach (RatedShipmentDetail shipmentDetail in rateDetail.RatedShipmentDetails) { ShowShipmentRateDetails(shipmentDetail); } ShowDeliveryDetails(rateDetail); DB.LogGenera("FedEx", "", "**********************************************************"); } ShowNotifications(reply); }
public List <ShippingRate> GetRates() { List <ShippingRate> result = new List <ShippingRate>(); RateRequest request = new RateRequest(); // request.WebAuthenticationDetail = new WebAuthenticationDetail(); request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential(); request.WebAuthenticationDetail.UserCredential.Key = "Qc0L7y4hA4oXJl29"; request.WebAuthenticationDetail.UserCredential.Password = "******"; // request.ClientDetail = new ClientDetail(); request.ClientDetail.AccountNumber = "510087500"; request.ClientDetail.MeterNumber = "119056534"; // request.TransactionDetail = new TransactionDetail(); request.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(request); // RateService service = new RateService(); RateReply reply = service.getRates(request); if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) { foreach (var item in reply.RateReplyDetails) { result.Add(new ShippingRate() { Method = item.ServiceType.ToString(), Price = item.RatedShipmentDetails[0].ShipmentRateDetail.TotalNetCharge.Amount, }); } } return(result); }
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); }
/// <summary> /// /// </summary> /// <param name="reply"></param> /// <returns></returns> private static List <KeyValuePair <string, decimal> > ShowRateReply(RateReply reply) { var rates = new List <KeyValuePair <string, decimal> >(); foreach (var rateReplyDetail in reply.RateReplyDetails) { if (rateReplyDetail.ServiceTypeSpecified) { if (rateReplyDetail.PackagingTypeSpecified) { foreach (var shipmentDetail in rateReplyDetail.RatedShipmentDetails) { rates.Add( new KeyValuePair <string, decimal>( rateReplyDetail.ServiceType.ToString().ToLower().Replace("_", " "), ShowPackageRateDetails(shipmentDetail.RatedPackages))); } } } } return(rates); }
public void ExecuteRequest() { RateService service = new RateService(); try { if (RequestedShipment == null) { return; } RateReply reply = service.getRates(this); if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) { foreach (var rateReplyDetail in reply.RateReplyDetails) { foreach (var shipmentDetail in rateReplyDetail.RatedShipmentDetails) { if (shipmentDetail == null) { continue; } if (shipmentDetail.ShipmentRateDetail == null) { continue; } _shipmentRate.Add(Mapper.Map <EisShipmentRate>(shipmentDetail.ShipmentRateDetail)); } } } } catch (SoapException e) { } catch (Exception e) { } }
//public static void FedExSetPackageLineItemsOriginal(RateRequest request, Person shipto, ProductCollection cart) //{ // request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[1]; // request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem(); // request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1"; // package sequence number // request.RequestedShipment.RequestedPackageLineItems[0].GroupPackageCount = "1"; // // package weight // request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight(); // request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB; // request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = (decimal)cart.TotalWeight; // // package dimensions // //***EAC TODO: need to follow box rules from Andy's email // request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions(); // request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "10"; // request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "13"; // request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "4"; // request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN; // //***EAC insured value - does not appear to be useful // //request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue = new Money(); // //request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Amount = 100; // //request.RequestedShipment.RequestedPackageLineItems[0].InsuredValue.Currency = "USD"; // // // //request.RequestedShipment.RequestedPackageLineItems[1] = new RequestedPackageLineItem(); // //request.RequestedShipment.RequestedPackageLineItems[1].SequenceNumber = "2"; // package sequence number // //request.RequestedShipment.RequestedPackageLineItems[1].GroupPackageCount = "1"; // //// package weight // //request.RequestedShipment.RequestedPackageLineItems[1].Weight = new Weight(); // //request.RequestedShipment.RequestedPackageLineItems[1].Weight.Units = WeightUnits.LB; // //request.RequestedShipment.RequestedPackageLineItems[1].Weight.Value = 25.0M; // //// package dimensions // //request.RequestedShipment.RequestedPackageLineItems[1].Dimensions = new Dimensions(); // //request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Length = "20"; // //request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Width = "13"; // //request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Height = "4"; // //request.RequestedShipment.RequestedPackageLineItems[1].Dimensions.Units = LinearUnits.IN; // //// insured value // //request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue = new Money(); // //request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue.Amount = 500; // //request.RequestedShipment.RequestedPackageLineItems[1].InsuredValue.Currency = "USD"; //} public static void FedExShowRateReply(RateReply reply, Person shipto, ProductCollection cart) { FedExNoelWrite("RateReply details:"); foreach (RateReplyDetail rateReplyDetail in reply.RateReplyDetails) { if (rateReplyDetail.ServiceTypeSpecified) { FedExNoelWrite("Service Type: " + rateReplyDetail.ServiceType); } if (rateReplyDetail.PackagingTypeSpecified) { FedExNoelWrite("Packaging Type: " + rateReplyDetail.PackagingType); } foreach (RatedShipmentDetail shipmentDetail in rateReplyDetail.RatedShipmentDetails) { FedExRate(shipmentDetail, shipto, cart); //FedExNoelWrite(); } FedExShowDeliveryDetails(rateReplyDetail); //FedExNoelWrite("**********************************************************"); } }
public decimal GetPrice(Delivery delivery, string currencyCode) { decimal decRate = 0; try { ServiceType stType = new ServiceType(); switch (delivery.ShippingOption.ShippingOptionName) { case "FedExPriorityOvernight": stType = ServiceType.PRIORITY_OVERNIGHT; break; case "FedExStandardOvernight": stType = ServiceType.STANDARD_OVERNIGHT; break; } CurrentUserInfo uinfo = MembershipContext.AuthenticatedUser; RateReply reply = new RateReply(); // Cache the data for 10 minutes with a key using (CachedSection <RateReply> cs = new CachedSection <RateReply>(ref reply, 60, true, null, "FexExRatesAPI-" + stType.ToString().Replace(" ", "-") + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, ""))) { if (cs.LoadData) { //Create the request RateRequest request = CreateRateRequest(delivery, stType); //Create the service RateService service = new RateService(); // Call the web service passing in a RateRequest and returning a RateReply reply = service.getRates(request); cs.Data = reply; } reply = cs.Data; } if (reply.HighestSeverity == NotificationSeverityType.SUCCESS) { foreach (RateReplyDetail repDetail in reply.RateReplyDetails) { foreach (RatedShipmentDetail rsd in repDetail.RatedShipmentDetails) { //Add an offset to handle the differencse in the testing envinronment decRate = ValidationHelper.GetDecimal(rsd.ShipmentRateDetail.TotalNetFedExCharge.Amount * 1.08m, 0); } } } else { //Clean up the cached value so the next time the value is pulled again CacheHelper.ClearCache("FexExRatesAPI-" + stType.ToString().Replace(" ", "-") + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, "")); } } catch (Exception ex) { //Log the error EventLogProvider.LogException("FedExCarrier - GetPrice", "EXCEPTION", ex); //Set some base rate for the shipping decRate = 10; } return(decRate); }
void FedExGetRates(Shipments shipments, out string rtShipRequest, out string rtShipResponse, decimal extraFee, decimal markupPercent, decimal shippingTaxRate, Cache cache, ref ShippingMethodCollection shippingMethods) { rtShipRequest = string.Empty; rtShipResponse = string.Empty; var maxWeight = AppConfigProvider.GetAppConfigValueUsCulture <decimal>("RTShipping.Fedex.MaxWeight", StoreId, true); if (maxWeight == 0) { maxWeight = 150; } if (ShipmentWeight > maxWeight) { shippingMethods.ErrorMsg = "FedEx " + AppConfigProvider.GetAppConfigValue("RTShipping.CallForShippingPrompt", StoreId, true); return; } foreach (var shipment in shipments) { HasFreeItems = shipments .SelectMany(packages => packages) .Where(package => package.IsFreeShipping) .Any(); var rateRequest = CreateRateRequest(shipment); rtShipRequest = SerializeToString(rateRequest); string cacheKey = null; RateReply rateReply = null; if (cache != null) { // Hash the content var md5 = System.Security.Cryptography.MD5.Create(); using (var hashDataStream = new MemoryStream()) { using (var hashDataWriter = new StreamWriter(hashDataStream, Encoding.UTF8, 1024, true)) hashDataWriter.Write(StripShipTimestampNode(rtShipRequest)); hashDataStream.Flush(); hashDataStream.Position = 0; cacheKey = string.Format("RTShipping.FedEx.{0}", md5.ComputeHash(hashDataStream).ToString("-")); } // See if the cache contains the content var cachedResponse = cache.Get(cacheKey) as RateReply; if (cachedResponse != null) { rateReply = cachedResponse; } } try { if (rateReply == null) { var rateService = new RateService { Url = FedexServer, }; rateReply = rateService.getRates(rateRequest); rtShipResponse = SerializeToString(rateReply); if (cache != null && cacheKey != null) { cache.Insert(cacheKey, rateReply, null, DateTime.Now.AddMinutes(15), Cache.NoSlidingExpiration); } } if (rateReply.RateReplyDetails == null || (rateReply.HighestSeverity != NotificationSeverityType.SUCCESS && rateReply.HighestSeverity != NotificationSeverityType.NOTE && rateReply.HighestSeverity != NotificationSeverityType.WARNING)) { rtShipResponse = "Error: Call Not Successful " + rateReply.Notifications[0].Message; return; } // Create a list of available services foreach (var rateReplyDetail in rateReply.RateReplyDetails) { var ratedShipmentDetail = rateReplyDetail.RatedShipmentDetails .Where(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) .FirstOrDefault(); var rateName = string.Format("FedEx {0}", FedExGetCodeDescription(rateReplyDetail.ServiceType.ToString())); if (!ShippingMethodIsAllowed(rateName, FedExName)) { continue; } var 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 != 0) { totalCharges = decimal.Round(totalCharges * (1 + (markupPercent / 100m)), 2, MidpointRounding.AwayFromZero); } var vat = decimal.Round(totalCharges * shippingTaxRate, 2, MidpointRounding.AwayFromZero); if (!shippingMethods.MethodExists(rateName)) { var shippingMethod = new ShippingMethod { Carrier = FedExName, Name = rateName, Freight = totalCharges, VatRate = vat, IsRealTime = true, Id = Shipping.GetShippingMethodID(rateName), }; if (HasFreeItems) { shippingMethod.FreeItemsRate = totalCharges; } shippingMethods.Add(shippingMethod); } else { var shippingMethodIndex = shippingMethods.GetIndex(rateName); var shippingMethod = shippingMethods[shippingMethodIndex]; shippingMethod.Freight += totalCharges; shippingMethod.VatRate += vat; if (HasFreeItems) { shippingMethod.FreeItemsRate += totalCharges; } shippingMethods[shippingMethodIndex] = shippingMethod; } } // 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 (var shippingMethod in shippingMethods.PerCarrier(FedExName)) { if (shippingMethod.Freight != 0) //Don't add the fee to free methods. { shippingMethod.Freight += extraFee; } } } catch (SoapException exception) { rtShipResponse = "FedEx Error: " + exception.Detail.InnerXml; } catch (Exception exception) { while (exception.InnerException != null) { exception = exception.InnerException; } rtShipResponse = "FedEx Error: " + exception.Message; } } }
private static List<ShippingNotification> ShowNotifications(RateReply reply) { // Add Notifications List<ShippingNotification> notifs = new List<ShippingNotification>(); for (int i = 0; i < reply.Notifications.Count(); i++) { Notification n = reply.Notifications[i]; ShippingNotification notif = new ShippingNotification { NotificationID = i, Severity = n.Severity.ToString(), Code = n.Code, Message = n.Message, Source = n.Source }; notifs.Add(notif); } return notifs; }
public static ShippingResponse GetRate(string dataType = "json") { try { if (dataType.ToUpper() == "JSON" || dataType.ToUpper() == "JSONP") { ValidateJSON(); } else { ValidateXML(); } RateRequest standardRequest = CreateRateRequest(_auth); RateRequest freightRequest = CreateRateRequest(_auth); standardRequest.RequestedShipment.FreightShipmentDetail = null; freightRequest.RequestedShipment.RequestedPackageLineItems = null; RateService service = new RateService(_environment); // Initializes the service try { // Call the web service passing in a RateRequest and returing a RateReply decimal totalweight = standardRequest.RequestedShipment.RequestedPackageLineItems.Sum(x => x.Weight.Value); RateReply reply = new RateReply(); if (totalweight < 90) { reply = service.getRates(standardRequest); } else if (totalweight >= 150) { //reply = service.getRates(freightRequest); reply = service.getRates(standardRequest); } else { // make both calls reply = service.getRates(standardRequest); /*RateReply freightreply = service.getRates(freightRequest); List<Notification> allnotifications = new List<Notification>(); List<RateReplyDetail> alldetails = new List<RateReplyDetail>(); if (standardreply.HighestSeverity == NotificationSeverityType.SUCCESS || standardreply.HighestSeverity == NotificationSeverityType.NOTE || standardreply.HighestSeverity == NotificationSeverityType.WARNING) { reply.HighestSeverity = standardreply.HighestSeverity; allnotifications.AddRange(standardreply.Notifications.ToList<Notification>()); alldetails.AddRange(standardreply.RateReplyDetails.ToList<RateReplyDetail>()); reply.TransactionDetail = standardreply.TransactionDetail; reply.Version = standardreply.Version; } if (freightreply.HighestSeverity == NotificationSeverityType.SUCCESS || freightreply.HighestSeverity == NotificationSeverityType.NOTE || freightreply.HighestSeverity == NotificationSeverityType.WARNING) { reply.HighestSeverity = freightreply.HighestSeverity; allnotifications.AddRange(freightreply.Notifications.ToList<Notification>()); alldetails.AddRange(freightreply.RateReplyDetails.ToList<RateReplyDetail>()); reply.TransactionDetail = freightreply.TransactionDetail; reply.Version = freightreply.Version; } reply.Notifications = allnotifications.ToArray<Notification>(); reply.RateReplyDetails = alldetails.ToArray<RateReplyDetail>();*/ } ShippingResponse resp = new ShippingResponse(); // Check if the call was successful if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) { List<ShipmentRateDetails> details = new List<ShipmentRateDetails>(); details = GetRateDetails(reply); resp = new ShippingResponse { Status = "OK", Status_Description = "", Result = details }; } else { List<ShipmentRateDetails> details = new List<ShipmentRateDetails>(); ShipmentRateDetails detail = new ShipmentRateDetails(); detail.Notifications = ShowNotifications(reply); details.Add(detail); resp = new ShippingResponse { Status = "ERROR", Status_Description = "", Result = details }; } return resp; } catch (SoapException e) { throw new Exception(e.Detail.InnerText); } catch (Exception e) { throw new Exception(e.Message); } } catch (Exception e) { ShippingResponse resp2 = new ShippingResponse { Status = "ERROR", Status_Description = e.Message, Result = null }; return resp2; } }
private static List<ShipmentRateDetails> GetRateDetails(RateReply reply) { List<ShipmentRateDetails> details = new List<ShipmentRateDetails>(); if (reply.RateReplyDetails != null) { foreach (RateReplyDetail replyDetail in reply.RateReplyDetails) { ShipmentRateDetails detail = new ShipmentRateDetails(); if (replyDetail.ServiceTypeSpecified) { detail.ServiceType = replyDetail.ServiceType.ToString(); } if (replyDetail.PackagingTypeSpecified) { detail.PackagingType = replyDetail.PackagingType.ToString(); } List<RateDetail> rateDetails = new List<RateDetail>(); foreach (RatedShipmentDetail shipmentDetail in replyDetail.RatedShipmentDetails) { ShipmentRateDetail shipDetail = shipmentDetail.ShipmentRateDetail; RateDetail rateDetail = new RateDetail(); rateDetail.RateType = shipDetail.RateType.ToString(); if (shipDetail.TotalBillingWeight != null) { rateDetail.TotalBillingWeight = new KeyValuePair<decimal, string>(shipDetail.TotalBillingWeight.Value, shipmentDetail.ShipmentRateDetail.TotalBillingWeight.Units.ToString()); } if (shipDetail.TotalBaseCharge != null) { rateDetail.TotalBaseCharge = new KeyValuePair<decimal, string>(shipDetail.TotalBaseCharge.Amount, shipDetail.TotalBaseCharge.Currency); } if (shipDetail.TotalFreightDiscounts != null) { rateDetail.TotalFreightDiscounts = new KeyValuePair<decimal, string>(shipDetail.TotalFreightDiscounts.Amount, shipDetail.TotalFreightDiscounts.Currency); } if (shipDetail.TotalSurcharges != null) { rateDetail.TotalFreightDiscounts = new KeyValuePair<decimal, string>(shipDetail.TotalSurcharges.Amount, shipDetail.TotalSurcharges.Currency); } if (shipDetail.Surcharges != null) { List<ShippingSurcharge> shippingSurcharges = new List<ShippingSurcharge>(); foreach (Surcharge detailSurcharge in shipDetail.Surcharges) { ShippingSurcharge surcharge = new ShippingSurcharge { Type = detailSurcharge.SurchargeType.ToString(), Charge = new KeyValuePair<decimal, string>(detailSurcharge.Amount.Amount, detailSurcharge.Amount.Currency) }; shippingSurcharges.Add(surcharge); } rateDetail.Surcharges = shippingSurcharges; } if (shipDetail.TotalNetCharge != null) { rateDetail.NetCharge = new KeyValuePair<decimal, string>(shipDetail.TotalNetCharge.Amount, shipDetail.TotalNetCharge.Currency); } rateDetails.Add(rateDetail); } detail.Rates = rateDetails; detail.TransitTime = replyDetail.TransitTime.ToString(); detail.Notifications = ShowNotifications(reply); details.Add(detail); } } return details; }
public decimal GetPrice(Delivery delivery, string currencyCode) { decimal decRate = 0; try { ServiceType stType = new ServiceType(); switch (delivery.ShippingOption.ShippingOptionName) { case "FedExPriorityOvernight": stType = ServiceType.PRIORITY_OVERNIGHT; break; case "FedExStandardOvernight": stType = ServiceType.STANDARD_OVERNIGHT; break; } CurrentUserInfo uinfo = MembershipContext.AuthenticatedUser; RateReply reply = new RateReply(); // Cache the data for 10 minutes with a key using (CachedSection<RateReply> cs = new CachedSection<RateReply>(ref reply, 60, true, null, "FexExRatesAPI-" + stType.ToString().Replace(" ", "-") + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, ""))) { if (cs.LoadData) { //Create the request RateRequest request = CreateRateRequest(delivery, stType); //Create the service RateService service = new RateService(); // Call the web service passing in a RateRequest and returning a RateReply reply = service.getRates(request); cs.Data = reply; } reply = cs.Data; } if (reply.HighestSeverity == NotificationSeverityType.SUCCESS) { foreach (RateReplyDetail repDetail in reply.RateReplyDetails) { foreach (RatedShipmentDetail rsd in repDetail.RatedShipmentDetails) { //Add an offset to handle the differencse in the testing envinronment decRate = ValidationHelper.GetDecimal(rsd.ShipmentRateDetail.TotalNetFedExCharge.Amount * 1.08m, 0); } } } else { //Clean up the cached value so the next time the value is pulled again CacheHelper.ClearCache("FexExRatesAPI-" + stType.ToString().Replace(" ", "-") + uinfo.UserID + "-" + delivery.DeliveryAddress.AddressZip + "-" + ValidationHelper.GetString(delivery.Weight, "")); } } catch (Exception ex) { //Log the error EventLogProvider.LogException("FedExCarrier - GetPrice", "EXCEPTION", ex); //Set some base rate for the shipping decRate = 10; } return decRate; }
private List<ShippingOption> ParseAnswer(RateReply reply) { var res = new List<ShippingOption>(); var enabledServices = EnabledService; foreach (var rateDetail in reply.RateReplyDetails) { var shippingOption = new ShippingOption(); if (!String.IsNullOrEmpty(enabledServices) && !enabledServices.Contains(rateDetail.ServiceType.ToString())) { continue; } string serviceName = GetServiceName(rateDetail.ServiceType.ToString()); shippingOption.Name = serviceName; foreach (RatedShipmentDetail shipmentDetail in rateDetail.RatedShipmentDetails) { shippingOption.Rate = Rate > 0 ? (float)shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount * Rate + Extracharge : (float)shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + Extracharge; // Vladimir: Старый код вытаскивал только некоторые Rate. Не знаю зачем. Пусть будут все. //if (shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_SHIPMENT) //{ // shippingOption.Rate = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + Extracharge; // if (Rate > 0) // { // shippingOption.Rate *= Rate; // } // break; //} //if (shipmentDetail.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_LIST_SHIPMENT) // Get List Rates (not discount rates) //{ // shippingOption.Rate = Rate > 0 ? shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount * Rate + Extracharge // : shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + Extracharge; // break; //} //var shippingRate = shipmentDetail.ShipmentRateDetail.TotalNetCharge.Amount + Extracharge; //if (Rate > 0) //{ // shippingRate *= Rate; //} //shippingOption.Rate = shippingRate; } res.Add(shippingOption); } return res; }