public FedExShippingProvider(int storeId, ShippingProviderType providerType) : base(storeId, providerType) { bool isTestGateway = WA.Parser.ToBool(settings.TryGetValueOrEmpty("isTestGateway")).GetValueOrDefault(false); fedExApi = new FedExApi( settings.TryGetValueOrEmpty("apiKey"), settings.TryGetValueOrEmpty("apiPassword"), settings.TryGetValueOrEmpty("accountNumber"), settings.TryGetValueOrEmpty("meterNumber"), settings.TryGetValueOrEmpty("smartPostHubId"), isTestGateway ); isSmartPostEnabled = !string.IsNullOrEmpty(settings.TryGetValueOrEmpty("smartPostHubId")); if (isSmartPostEnabled) { fedExApiNoSmartPost = new FedExApi( settings.TryGetValueOrEmpty("apiKey"), settings.TryGetValueOrEmpty("apiPassword"), settings.TryGetValueOrEmpty("accountNumber"), settings.TryGetValueOrEmpty("meterNumber"), string.Empty, isTestGateway ); } }
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); }