示例#1
0
        public static ShippingRate RatePackage(FedExGlobalServiceSettings globals,
                                       MerchantTribe.Web.Logging.ILogger logger,
                                       FedExServiceSettings settings,
                                       IShipment package)
        {
            ShippingRate result = new ShippingRate();

                // Get ServiceType
                ServiceType currentServiceType = ServiceType.FEDEXGROUND;
                currentServiceType = (ServiceType)settings.ServiceCode;

                // Get PackageType
                PackageType currentPackagingType = PackageType.YOURPACKAGING;
                currentPackagingType = (PackageType)settings.Packaging;

                // Set max weight by service
                CarrierCodeType carCode = GetCarrierCode(currentServiceType);

                result.EstimatedCost = RateSinglePackage(globals, 
                                                        logger,
                                                        package, 
                                                        currentServiceType, 
                                                        currentPackagingType, 
                                                        carCode);

            return result;
        }
示例#2
0
        public static ShippingRate RatePackage(FedExGlobalServiceSettings globals,
                                               MerchantTribe.Web.Logging.ILogger logger,
                                               FedExServiceSettings settings,
                                               IShipment package)
        {
            ShippingRate result = new ShippingRate();

            // Get ServiceType
            ServiceType currentServiceType = ServiceType.FEDEXGROUND;

            currentServiceType = (ServiceType)settings.ServiceCode;

            // Get PackageType
            PackageType currentPackagingType = PackageType.YOURPACKAGING;

            currentPackagingType = (PackageType)settings.Packaging;

            // Set max weight by service
            CarrierCodeType carCode = GetCarrierCode(currentServiceType);

            result.EstimatedCost = RateSinglePackage(globals,
                                                     logger,
                                                     package,
                                                     currentServiceType,
                                                     currentPackagingType,
                                                     carCode);

            return(result);
        }
示例#3
0
        protected void btnTest_Click(object sender, EventArgs e)
        {
            this.SaveData();

            var testSettings = new FedExGlobalServiceSettings();
            testSettings.AccountNumber = this.AccountNumberField.Text;
            testSettings.DefaultDropOffType = (DropOffType)int.Parse(this.lstDropOffType.SelectedValue);
            testSettings.DefaultPackaging = (PackageType)int.Parse(this.lstPackaging.SelectedValue);
            testSettings.DiagnosticsMode = true;
            testSettings.ForceResidentialRates = this.chkResidential.Checked;
            testSettings.MeterNumber = this.MeterNumberField.Text.Trim();
            testSettings.UseListRates = this.chkListRates.Checked;
            testSettings.UserKey = this.KeyField.Text.Trim();
            testSettings.UserPassword = this.PasswordField.Text.Trim();

            var logger = new MerchantTribe.Web.Logging.TextLogger();

            var testSvc = new MerchantTribe.Shipping.FedEx.FedExProvider(testSettings, logger);
            testSvc.Settings.ServiceCode = int.Parse(this.lstServicesTest.SelectedValue);
            testSvc.Settings.Packaging = (int)testSettings.DefaultPackaging;

            var testShipment = new Shipment();
            testShipment.DestinationAddress = this.DestinationAddress.GetAsAddress();
            testShipment.SourceAddress = this.SourceAddress.GetAsAddress();
            var testItem = new Shippable();
            testItem.BoxHeight = decimal.Parse(this.TestHeight.Text);
            testItem.BoxLength = decimal.Parse(this.TestLength.Text);
            testItem.BoxWidth = decimal.Parse(this.TestWidth.Text);
            testItem.BoxLengthType = LengthType.Inches;
            testItem.BoxWeight = decimal.Parse(this.TestWeight.Text);
            testItem.BoxWeightType = MerchantTribe.Shipping.WeightType.Pounds;
            testShipment.Items.Add(testItem);

            StringBuilder sb = new StringBuilder();
            sb.Append("Starting Rate Test at " + DateTime.Now + "<br />");
            var rates = testSvc.RateShipment(testShipment);
            foreach (var r in rates)
            {
                sb.Append("Rate Found: " + r.EstimatedCost.ToString("C") + " | " + r.DisplayName + " (" + r.ServiceCodes + ", " + r.ServiceId + ")<br />");
            }
            sb.Append("<br />");
            sb.Append("LOG:<br />");
            foreach (var m in logger.Messages)
            {
                sb.Append(m + "<br />");
            }
            sb.Append("Finished Rate Test at " + DateTime.Now);
            this.litTestOuput.Text = sb.ToString();
        }
示例#4
0
 public RateRequest(FedExGlobalServiceSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger)
 {
     RequestHeader = new Header();
     ReturnType = ReturnShipmentIndicatorType.NONRETURN;
     ShipDate = DateTime.Now.AddHours(4);
     globals = globalSettings;
     _logger = logger;
     Service = ServiceType.FEDEXGROUND;
     Packaging = PackageType.YOURPACKAGING;
     WeightUnits = WeightType.LBS;
     OriginAddress = new Address();
     DestinationAddress = new Address();
     Dimensions = new DimensionsBlock();
     this.ContainsAlcohol = false;
     this.SpecialServices = new RateSpecialServices();
     this.PackageCount = 0;
 }
示例#5
0
 public RateRequest(FedExGlobalServiceSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger)
 {
     RequestHeader        = new Header();
     ReturnType           = ReturnShipmentIndicatorType.NONRETURN;
     ShipDate             = DateTime.Now.AddHours(4);
     globals              = globalSettings;
     _logger              = logger;
     Service              = ServiceType.FEDEXGROUND;
     Packaging            = PackageType.YOURPACKAGING;
     WeightUnits          = WeightType.LBS;
     OriginAddress        = new Address();
     DestinationAddress   = new Address();
     Dimensions           = new DimensionsBlock();
     this.ContainsAlcohol = false;
     this.SpecialServices = new RateSpecialServices();
     this.PackageCount    = 0;
 }
        public static List<IShippingService> FindAll(Accounts.Store currentStore)
        {
            
            List<IShippingService> result = new List<IShippingService>();

            result = Service.FindAll();

            //result.Add(new MerchantTribe.Shipping.Fedex.FedExProvider());
            //FedEx            
            MerchantTribe.Shipping.FedEx.FedExGlobalServiceSettings fedexGlobal = new FedExGlobalServiceSettings();
            fedexGlobal.UserKey = currentStore.Settings.ShippingFedExKey;
            fedexGlobal.UserPassword = currentStore.Settings.ShippingFedExPassword;
            fedexGlobal.AccountNumber = currentStore.Settings.ShippingFedExAccountNumber;
            fedexGlobal.MeterNumber = currentStore.Settings.ShippingFedExMeterNumber;
            fedexGlobal.DefaultDropOffType = (MerchantTribe.Shipping.FedEx.DropOffType)currentStore.Settings.ShippingFedExDropOffType;
            fedexGlobal.DefaultPackaging = (MerchantTribe.Shipping.FedEx.PackageType)currentStore.Settings.ShippingFedExDefaultPackaging;
            fedexGlobal.DiagnosticsMode = currentStore.Settings.ShippingFedExDiagnostics;
            fedexGlobal.ForceResidentialRates = currentStore.Settings.ShippingFedExForceResidentialRates;
            fedexGlobal.UseListRates = currentStore.Settings.ShippingFedExUseListRates;
            result.Add(new MerchantTribe.Shipping.FedEx.FedExProvider(fedexGlobal, new EventLog()));

            // Load US Postal
            MerchantTribe.Shipping.USPostal.USPostalServiceGlobalSettings uspostalGlobal = new MerchantTribe.Shipping.USPostal.USPostalServiceGlobalSettings();
            uspostalGlobal.DiagnosticsMode = currentStore.Settings.ShippingUSPostalDiagnostics;
            result.Add(new MerchantTribe.Shipping.USPostal.DomesticProvider(uspostalGlobal, new EventLog()));
            result.Add(new MerchantTribe.Shipping.USPostal.InternationalProvider(uspostalGlobal, new EventLog()));
             
            // Load UPS
            MerchantTribe.Shipping.Ups.UPSServiceGlobalSettings upsglobal = new MerchantTribe.Shipping.Ups.UPSServiceGlobalSettings();
            upsglobal.AccountNumber = currentStore.Settings.ShippingUpsAccountNumber;
            upsglobal.LicenseNumber = currentStore.Settings.ShippingUpsLicense;
            upsglobal.Username = currentStore.Settings.ShippingUpsUsername;
            upsglobal.Password = currentStore.Settings.ShippingUpsPassword;
            upsglobal.DefaultPackaging = (MerchantTribe.Shipping.Ups.PackagingType)currentStore.Settings.ShippingUpsDefaultPackaging;
            upsglobal.DiagnosticsMode = currentStore.Settings.ShippingUPSDiagnostics;
            upsglobal.ForceResidential = currentStore.Settings.ShippingUpsForceResidential;
            upsglobal.IgnoreDimensions = currentStore.Settings.ShippingUpsSkipDimensions;
            upsglobal.PickUpType = (MerchantTribe.Shipping.Ups.PickupType)currentStore.Settings.ShippingUpsPickupType;
            result.Add(new MerchantTribe.Shipping.Ups.UPSService(upsglobal, new EventLog()));            
            
            return result;
        }
示例#7
0
        private static decimal RateSinglePackage(FedExGlobalServiceSettings globalSettings,
                                                 MerchantTribe.Web.Logging.ILogger logger,
                                                 IShipment pak, 
                                                 ServiceType service, 
                                                 PackageType packaging,
                                                 CarrierCodeType carCode)
        {
            decimal result = 0m;




            try
            {



                // Auth Header Data
                var req = new FedExRateServices.RateRequest();
                req.WebAuthenticationDetail = new WebAuthenticationDetail();
                req.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
                req.WebAuthenticationDetail.UserCredential.Key = globalSettings.UserKey;
                req.WebAuthenticationDetail.UserCredential.Password = globalSettings.UserPassword;
                req.ClientDetail = new ClientDetail();
                req.ClientDetail.AccountNumber = globalSettings.AccountNumber;
                req.ClientDetail.MeterNumber = globalSettings.MeterNumber;
                req.ClientDetail.IntegratorId = "BVSoftware";
                req.Version = new VersionId();

                // Basic Transaction Data
                req.TransactionDetail = new TransactionDetail();
                req.TransactionDetail.CustomerTransactionId = System.Guid.NewGuid().ToString();
                req.ReturnTransitAndCommit = false;
                req.CarrierCodes = new CarrierCodeType[1] { carCode };

                // Shipment Details
                req.RequestedShipment = new RequestedShipment();

                req.RequestedShipment.LabelSpecification = new LabelSpecification();
                req.RequestedShipment.LabelSpecification.ImageType = ShippingDocumentImageType.PDF;
                req.RequestedShipment.LabelSpecification.LabelFormatType = LabelFormatType.COMMON2D;
                req.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail = new CustomerSpecifiedLabelDetail();

                req.RequestedShipment.DropoffType = GetDropOffType(globalSettings.DefaultDropOffType);
                req.RequestedShipment.PackagingType = GetPackageType(packaging);
                req.RequestedShipment.TotalWeight = new Weight();
                req.RequestedShipment.TotalWeight.Value = Math.Round(pak.Items.Sum(y => y.BoxWeight), 1);
                if (pak.Items[0].BoxWeightType == Shipping.WeightType.Kilograms)
                {
                    req.RequestedShipment.TotalWeight.Units = WeightUnits.KG;
                }
                else
                {
                    req.RequestedShipment.TotalWeight.Units = WeightUnits.LB;
                }

                // Uncomment these lines to get insured values passed in
                //
                //var totalValue = pak.Items.Sum(y => y.BoxValue);
                //req.RequestedShipment.TotalInsuredValue = new Money();
                //req.RequestedShipment.TotalInsuredValue.Amount = totalValue;
                //req.RequestedShipment.TotalInsuredValue.Currency = "USD";

                req.RequestedShipment.PackageCount = pak.Items.Count.ToString();

                req.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[pak.Items.Count];
                for (int i = 0; i < pak.Items.Count; i++)
                {
                    req.RequestedShipment.RequestedPackageLineItems[i] = new RequestedPackageLineItem();
                    req.RequestedShipment.RequestedPackageLineItems[i].GroupNumber = "1";
                    req.RequestedShipment.RequestedPackageLineItems[i].GroupPackageCount = (i + 1).ToString();                    
                    req.RequestedShipment.RequestedPackageLineItems[i].Weight = new Weight();
                    req.RequestedShipment.RequestedPackageLineItems[i].Weight.Value = pak.Items[i].BoxWeight;
                    req.RequestedShipment.RequestedPackageLineItems[i].Weight.Units = pak.Items[i].BoxWeightType == Shipping.WeightType.Kilograms ? WeightUnits.KG : WeightUnits.LB;
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions = new Dimensions();
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = pak.Items[i].BoxHeight.ToString();
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = pak.Items[i].BoxLength.ToString();
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width = pak.Items[i].BoxWidth.ToString();
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units = pak.Items[i].BoxLengthType == LengthType.Centimeters ? LinearUnits.CM : LinearUnits.IN;
                }

                req.RequestedShipment.Recipient = new Party();
                req.RequestedShipment.Recipient.Address = new FedExRateServices.Address();
                req.RequestedShipment.Recipient.Address.City = pak.DestinationAddress.City;
                req.RequestedShipment.Recipient.Address.CountryCode = GetCountryCode(pak.DestinationAddress.CountryData);
                req.RequestedShipment.Recipient.Address.PostalCode = pak.DestinationAddress.PostalCode;                                

                if (pak.DestinationAddress.CountryData.Bvin == "bf7389a2-9b21-4d33-b276-23c9c18ea0c0" || // US or Canada
                    pak.DestinationAddress.CountryData.Bvin == "94052dcf-1ac8-4b65-813b-b17b12a0491f")
                {
                    req.RequestedShipment.Recipient.Address.StateOrProvinceCode = pak.DestinationAddress.RegionData.Abbreviation; // GetStateCode(pak.DestinationAddress.RegionData);
                }
                else
                {
                    req.RequestedShipment.Recipient.Address.StateOrProvinceCode = string.Empty;
                }
                req.RequestedShipment.Recipient.Address.StreetLines = new string[2] { pak.DestinationAddress.Street, pak.DestinationAddress.Street2 };

                if (service == ServiceType.GROUNDHOMEDELIVERY)
                {
                    req.RequestedShipment.Recipient.Address.Residential = true;
                    req.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
                }
                else if (service == ServiceType.FEDEXGROUND)
                {
                    req.RequestedShipment.Recipient.Address.Residential = false;
                    req.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
                }
                else
                {
                    req.RequestedShipment.Recipient.Address.ResidentialSpecified = false;
                }

                req.RequestedShipment.Shipper = new Party();
                req.RequestedShipment.Shipper.AccountNumber = globalSettings.AccountNumber;
                req.RequestedShipment.Shipper.Address = new FedExRateServices.Address();
                req.RequestedShipment.Shipper.Address.City = pak.SourceAddress.City;
                req.RequestedShipment.Shipper.Address.CountryCode = GetCountryCode(pak.SourceAddress.CountryData);
                req.RequestedShipment.Shipper.Address.PostalCode = pak.SourceAddress.PostalCode;
                req.RequestedShipment.Shipper.Address.Residential = false;
                if (pak.SourceAddress.CountryData.Bvin == "bf7389a2-9b21-4d33-b276-23c9c18ea0c0" || // US or Canada
                    pak.SourceAddress.CountryData.Bvin == "94052dcf-1ac8-4b65-813b-b17b12a0491f")
                {
                    req.RequestedShipment.Shipper.Address.StateOrProvinceCode = pak.SourceAddress.RegionData.Abbreviation;
                }
                else
                {
                    req.RequestedShipment.Shipper.Address.StateOrProvinceCode = string.Empty;
                }
                req.RequestedShipment.Shipper.Address.StreetLines = new string[2] { pak.SourceAddress.Street, pak.SourceAddress.Street2 };


                var svc = new FedExRateServices.RateService();
                RateReply res = svc.getRates(req);

                if (res.HighestSeverity == NotificationSeverityType.ERROR ||
                    res.HighestSeverity == NotificationSeverityType.FAILURE)
                {
                    if (globalSettings.DiagnosticsMode == true)
                    {
                        foreach (var err in res.Notifications)
                        {
                            logger.LogMessage("FEDEX", err.Message, Web.Logging.EventLogSeverity.Debug);
                        }
                    }
                    result = 0m;
                }
                else
                {
                    result = 0m;

                    var lookingForService = GetServiceType(service);
                    var matchingResponse = res.RateReplyDetails.Where(y => y.ServiceType == lookingForService).FirstOrDefault();
                    if (matchingResponse != null)
                    {
                        var matchedRate = matchingResponse.RatedShipmentDetails.Where(
                            y => y.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_PACKAGE ||
                                y.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_SHIPMENT).FirstOrDefault();
                        if (matchedRate != null)                        
                        {
                            result = matchedRate.ShipmentRateDetail.TotalNetCharge.Amount;
                        }
                    }                                                                
                }
            }
            catch (Exception ex)
            {
                result = 0m;
                logger.LogException(ex);
            }

            return result;
        }
示例#8
0
        private static decimal RateSinglePackage(FedExGlobalServiceSettings globalSettings,
            MerchantTribe.Web.Logging.ILogger logger,
            IShipment pak,
            ServiceType service,
            PackageType packaging,
            CarrierCode carCode)
        {
            decimal result = 0m;

            //Try
            RateRequest req = new RateRequest(globalSettings, logger);
            req.RequestHeader.AccountNumber = globalSettings.AccountNumber;
            req.RequestHeader.MeterNumber = globalSettings.MeterNumber;
            req.RequestHeader.CarrierCode = carCode;

            req.DeclaredValue = 0.1m;

            // Destination Address
            Country destinationCountry = Country.FindByBvin(pak.DestinationAddress.CountryData.Bvin);
            if (destinationCountry != null)
            {
                req.DestinationAddress.CountryCode = destinationCountry.IsoCode;
                if (destinationCountry.IsoCode == "US" | destinationCountry.IsoCode == "CA")
                {
                    Region destinationRegion
                        = destinationCountry
                            .Regions
                            .Where(y => y.Abbreviation == pak.DestinationAddress.RegionData.Abbreviation)
                            .SingleOrDefault();

                    req.DestinationAddress.StateOrProvinceCode = destinationRegion.Abbreviation;
                }
            }
            req.DestinationAddress.PostalCode = pak.DestinationAddress.PostalCode;

            // Origin Address
            Country originCountry = Country.FindByBvin(pak.SourceAddress.CountryData.Bvin);
            if (originCountry != null)
            {
                req.OriginAddress.CountryCode = originCountry.IsoCode;
                if (originCountry.IsoCode == "US" | originCountry.IsoCode == "CA")
                {
                    Region originRegion =
                        originCountry.Regions.Where(y => y.Abbreviation == pak.SourceAddress.RegionData.Abbreviation)
                        .SingleOrDefault();
                    req.OriginAddress.StateOrProvinceCode = originRegion.Abbreviation;
                }
            }
            req.OriginAddress.PostalCode = pak.SourceAddress.PostalCode;

            // Dimensions
            req.Dimensions.Length = pak.Items[0].BoxLength;
            req.Dimensions.Width = pak.Items[0].BoxWidth;
            req.Dimensions.Height = pak.Items[0].BoxHeight;
            //switch ()
            //{
            //    case MerchantTribe.Commerce.Shipping.LengthType.Centimeters:
            //        req.Dimensions.Units = DimensionType.CM;
            //        break;
                //case MerchantTribe.Commerce.Shipping.LengthType.Inches:
                    req.Dimensions.Units = DimensionType.IN;
            //        break;
            //}

            req.PackageCount = 1;
            req.Packaging = packaging;
            req.ReturnType = ReturnShipmentIndicatorType.NONRETURN;
            req.Service = service;
            req.SpecialServices.ResidentialDelivery = globalSettings.ForceResidentialRates;
            req.Weight = pak.Items[0].BoxWeight;
            //switch (WebAppSettings.ApplicationWeightUnits)
            //{
            //    case MerchantTribe.Commerce.Shipping.WeightType.Kilograms:
            //        req.WeightUnits = WeightType.KGS;
            //        break;
            //    case MerchantTribe.Commerce.Shipping.WeightType.Pounds:
                    req.WeightUnits = WeightType.LBS;
            //        break;
            //}

            RateResponse res = req.Send();

            if (res.Errors.Count > 0)
            {
                result = 0m;
            }
            else
            {
                if (globalSettings.UseListRates)
                {
                    if (res.EstimatedCharges.ListCharges.NetCharge > 0)
                    {
                        result = res.EstimatedCharges.ListCharges.NetCharge;
                    }
                    else
                    {
                        result = res.EstimatedCharges.DiscountedCharges.NetCharge;
                    }
                }
                else
                {
                    result = res.EstimatedCharges.DiscountedCharges.NetCharge;
                }
            }

            return result;
        }
示例#9
0
 public FedExProvider(FedExGlobalServiceSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger)
 {
     _Logger = logger;
     GlobalSettings = globalSettings;
     Settings = new FedExServiceSettings();
 }
示例#10
0
 public FedExProvider(FedExGlobalServiceSettings globalSettings, MerchantTribe.Web.Logging.ILogger logger)
 {
     _Logger        = logger;
     GlobalSettings = globalSettings;
     Settings       = new FedExServiceSettings();
 }
示例#11
0
        private static decimal RateSinglePackage(FedExGlobalServiceSettings globalSettings,
                                                 MerchantTribe.Web.Logging.ILogger logger,
                                                 IShipment pak,
                                                 ServiceType service,
                                                 PackageType packaging,
                                                 CarrierCodeType carCode)
        {
            decimal result = 0m;



            try
            {
                // Auth Header Data
                var req = new FedExRateServices.RateRequest();
                req.WebAuthenticationDetail = new WebAuthenticationDetail();
                req.WebAuthenticationDetail.UserCredential          = new WebAuthenticationCredential();
                req.WebAuthenticationDetail.UserCredential.Key      = globalSettings.UserKey;
                req.WebAuthenticationDetail.UserCredential.Password = globalSettings.UserPassword;
                req.ClientDetail = new ClientDetail();
                req.ClientDetail.AccountNumber = globalSettings.AccountNumber;
                req.ClientDetail.MeterNumber   = globalSettings.MeterNumber;
                req.ClientDetail.IntegratorId  = "BVSoftware";
                req.Version = new VersionId();

                // Basic Transaction Data
                req.TransactionDetail = new TransactionDetail();
                req.TransactionDetail.CustomerTransactionId = System.Guid.NewGuid().ToString();
                req.ReturnTransitAndCommit = false;
                req.CarrierCodes           = new CarrierCodeType[1] {
                    carCode
                };

                // Shipment Details
                req.RequestedShipment = new RequestedShipment();

                req.RequestedShipment.LabelSpecification                         = new LabelSpecification();
                req.RequestedShipment.LabelSpecification.ImageType               = ShippingDocumentImageType.PDF;
                req.RequestedShipment.LabelSpecification.LabelFormatType         = LabelFormatType.COMMON2D;
                req.RequestedShipment.LabelSpecification.CustomerSpecifiedDetail = new CustomerSpecifiedLabelDetail();

                req.RequestedShipment.DropoffType       = GetDropOffType(globalSettings.DefaultDropOffType);
                req.RequestedShipment.PackagingType     = GetPackageType(packaging);
                req.RequestedShipment.TotalWeight       = new Weight();
                req.RequestedShipment.TotalWeight.Value = Math.Round(pak.Items.Sum(y => y.BoxWeight), 1);
                if (pak.Items[0].BoxWeightType == Shipping.WeightType.Kilograms)
                {
                    req.RequestedShipment.TotalWeight.Units = WeightUnits.KG;
                }
                else
                {
                    req.RequestedShipment.TotalWeight.Units = WeightUnits.LB;
                }

                // Uncomment these lines to get insured values passed in
                //
                //var totalValue = pak.Items.Sum(y => y.BoxValue);
                //req.RequestedShipment.TotalInsuredValue = new Money();
                //req.RequestedShipment.TotalInsuredValue.Amount = totalValue;
                //req.RequestedShipment.TotalInsuredValue.Currency = "USD";

                req.RequestedShipment.PackageCount = pak.Items.Count.ToString();

                req.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[pak.Items.Count];
                for (int i = 0; i < pak.Items.Count; i++)
                {
                    req.RequestedShipment.RequestedPackageLineItems[i]                   = new RequestedPackageLineItem();
                    req.RequestedShipment.RequestedPackageLineItems[i].GroupNumber       = "1";
                    req.RequestedShipment.RequestedPackageLineItems[i].GroupPackageCount = (i + 1).ToString();
                    req.RequestedShipment.RequestedPackageLineItems[i].Weight            = new Weight();
                    req.RequestedShipment.RequestedPackageLineItems[i].Weight.Value      = pak.Items[i].BoxWeight;
                    req.RequestedShipment.RequestedPackageLineItems[i].Weight.Units      = pak.Items[i].BoxWeightType == Shipping.WeightType.Kilograms ? WeightUnits.KG : WeightUnits.LB;
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions        = new Dimensions();
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Height = pak.Items[i].BoxHeight.ToString();
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Length = pak.Items[i].BoxLength.ToString();
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Width  = pak.Items[i].BoxWidth.ToString();
                    req.RequestedShipment.RequestedPackageLineItems[i].Dimensions.Units  = pak.Items[i].BoxLengthType == LengthType.Centimeters ? LinearUnits.CM : LinearUnits.IN;
                }

                req.RequestedShipment.Recipient                     = new Party();
                req.RequestedShipment.Recipient.Address             = new FedExRateServices.Address();
                req.RequestedShipment.Recipient.Address.City        = pak.DestinationAddress.City;
                req.RequestedShipment.Recipient.Address.CountryCode = GetCountryCode(pak.DestinationAddress.CountryData);
                req.RequestedShipment.Recipient.Address.PostalCode  = pak.DestinationAddress.PostalCode;

                if (pak.DestinationAddress.CountryData.Bvin == "bf7389a2-9b21-4d33-b276-23c9c18ea0c0" || // US or Canada
                    pak.DestinationAddress.CountryData.Bvin == "94052dcf-1ac8-4b65-813b-b17b12a0491f")
                {
                    req.RequestedShipment.Recipient.Address.StateOrProvinceCode = pak.DestinationAddress.RegionData.Abbreviation; // GetStateCode(pak.DestinationAddress.RegionData);
                }
                else
                {
                    req.RequestedShipment.Recipient.Address.StateOrProvinceCode = string.Empty;
                }
                req.RequestedShipment.Recipient.Address.StreetLines = new string[2] {
                    pak.DestinationAddress.Street, pak.DestinationAddress.Street2
                };

                if (service == ServiceType.GROUNDHOMEDELIVERY)
                {
                    req.RequestedShipment.Recipient.Address.Residential          = true;
                    req.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
                }
                else if (service == ServiceType.FEDEXGROUND)
                {
                    req.RequestedShipment.Recipient.Address.Residential          = false;
                    req.RequestedShipment.Recipient.Address.ResidentialSpecified = true;
                }
                else
                {
                    req.RequestedShipment.Recipient.Address.ResidentialSpecified = false;
                }

                req.RequestedShipment.Shipper = new Party();
                req.RequestedShipment.Shipper.AccountNumber       = globalSettings.AccountNumber;
                req.RequestedShipment.Shipper.Address             = new FedExRateServices.Address();
                req.RequestedShipment.Shipper.Address.City        = pak.SourceAddress.City;
                req.RequestedShipment.Shipper.Address.CountryCode = GetCountryCode(pak.SourceAddress.CountryData);
                req.RequestedShipment.Shipper.Address.PostalCode  = pak.SourceAddress.PostalCode;
                req.RequestedShipment.Shipper.Address.Residential = false;
                if (pak.SourceAddress.CountryData.Bvin == "bf7389a2-9b21-4d33-b276-23c9c18ea0c0" || // US or Canada
                    pak.SourceAddress.CountryData.Bvin == "94052dcf-1ac8-4b65-813b-b17b12a0491f")
                {
                    req.RequestedShipment.Shipper.Address.StateOrProvinceCode = pak.SourceAddress.RegionData.Abbreviation;
                }
                else
                {
                    req.RequestedShipment.Shipper.Address.StateOrProvinceCode = string.Empty;
                }
                req.RequestedShipment.Shipper.Address.StreetLines = new string[2] {
                    pak.SourceAddress.Street, pak.SourceAddress.Street2
                };


                var       svc = new FedExRateServices.RateService();
                RateReply res = svc.getRates(req);

                if (res.HighestSeverity == NotificationSeverityType.ERROR ||
                    res.HighestSeverity == NotificationSeverityType.FAILURE)
                {
                    if (globalSettings.DiagnosticsMode == true)
                    {
                        foreach (var err in res.Notifications)
                        {
                            logger.LogMessage("FEDEX", err.Message, Web.Logging.EventLogSeverity.Debug);
                        }
                    }
                    result = 0m;
                }
                else
                {
                    result = 0m;

                    var lookingForService = GetServiceType(service);
                    var matchingResponse  = res.RateReplyDetails.Where(y => y.ServiceType == lookingForService).FirstOrDefault();
                    if (matchingResponse != null)
                    {
                        var matchedRate = matchingResponse.RatedShipmentDetails.Where(
                            y => y.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_PACKAGE ||
                            y.ShipmentRateDetail.RateType == ReturnedRateType.PAYOR_ACCOUNT_SHIPMENT).FirstOrDefault();
                        if (matchedRate != null)
                        {
                            result = matchedRate.ShipmentRateDetail.TotalNetCharge.Amount;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result = 0m;
                logger.LogException(ex);
            }

            return(result);
        }
示例#12
0
        private static decimal RateSinglePackage(FedExGlobalServiceSettings globalSettings,
                                                 MerchantTribe.Web.Logging.ILogger logger,
                                                 IShipment pak,
                                                 ServiceType service,
                                                 PackageType packaging,
                                                 CarrierCode carCode)
        {
            decimal result = 0m;

            //Try
            RateRequest req = new RateRequest(globalSettings, logger);

            req.RequestHeader.AccountNumber = globalSettings.AccountNumber;
            req.RequestHeader.MeterNumber   = globalSettings.MeterNumber;
            req.RequestHeader.CarrierCode   = carCode;

            req.DeclaredValue = 0.1m;

            // Destination Address
            Country destinationCountry = Country.FindByBvin(pak.DestinationAddress.CountryData.Bvin);

            if (destinationCountry != null)
            {
                req.DestinationAddress.CountryCode = destinationCountry.IsoCode;
                if (destinationCountry.IsoCode == "US" | destinationCountry.IsoCode == "CA")
                {
                    Region destinationRegion
                        = destinationCountry
                          .Regions
                          .Where(y => y.Abbreviation == pak.DestinationAddress.RegionData.Abbreviation)
                          .SingleOrDefault();

                    req.DestinationAddress.StateOrProvinceCode = destinationRegion.Abbreviation;
                }
            }
            req.DestinationAddress.PostalCode = pak.DestinationAddress.PostalCode;

            // Origin Address
            Country originCountry = Country.FindByBvin(pak.SourceAddress.CountryData.Bvin);

            if (originCountry != null)
            {
                req.OriginAddress.CountryCode = originCountry.IsoCode;
                if (originCountry.IsoCode == "US" | originCountry.IsoCode == "CA")
                {
                    Region originRegion =
                        originCountry.Regions.Where(y => y.Abbreviation == pak.SourceAddress.RegionData.Abbreviation)
                        .SingleOrDefault();
                    req.OriginAddress.StateOrProvinceCode = originRegion.Abbreviation;
                }
            }
            req.OriginAddress.PostalCode = pak.SourceAddress.PostalCode;

            // Dimensions
            req.Dimensions.Length = pak.Items[0].BoxLength;
            req.Dimensions.Width  = pak.Items[0].BoxWidth;
            req.Dimensions.Height = pak.Items[0].BoxHeight;
            //switch ()
            //{
            //    case MerchantTribe.Commerce.Shipping.LengthType.Centimeters:
            //        req.Dimensions.Units = DimensionType.CM;
            //        break;
            //case MerchantTribe.Commerce.Shipping.LengthType.Inches:
            req.Dimensions.Units = DimensionType.IN;
            //        break;
            //}

            req.PackageCount = 1;
            req.Packaging    = packaging;
            req.ReturnType   = ReturnShipmentIndicatorType.NONRETURN;
            req.Service      = service;
            req.SpecialServices.ResidentialDelivery = globalSettings.ForceResidentialRates;
            req.Weight = pak.Items[0].BoxWeight;
            //switch (WebAppSettings.ApplicationWeightUnits)
            //{
            //    case MerchantTribe.Commerce.Shipping.WeightType.Kilograms:
            //        req.WeightUnits = WeightType.KGS;
            //        break;
            //    case MerchantTribe.Commerce.Shipping.WeightType.Pounds:
            req.WeightUnits = WeightType.LBS;
            //        break;
            //}


            RateResponse res = req.Send();

            if (res.Errors.Count > 0)
            {
                result = 0m;
            }
            else
            {
                if (globalSettings.UseListRates)
                {
                    if (res.EstimatedCharges.ListCharges.NetCharge > 0)
                    {
                        result = res.EstimatedCharges.ListCharges.NetCharge;
                    }
                    else
                    {
                        result = res.EstimatedCharges.DiscountedCharges.NetCharge;
                    }
                }
                else
                {
                    result = res.EstimatedCharges.DiscountedCharges.NetCharge;
                }
            }

            return(result);
        }