Beispiel #1
0
        public RateResponse Send(string serviceUrl)
        {
            RateResponse result = new RateResponse();

            string xmlToSend   = BuildXml();
            string responseXml = RateService.SendRequest(serviceUrl, xmlToSend);

            result.Parse(responseXml);

            if (globals.DiagnosticsMode)
            {
                _logger.LogMessage("FedEx Diagnostics - Request="
                                   + xmlToSend + "<br/>"
                                   + System.Environment.NewLine
                                   + "<br/>"
                                   + System.Environment.NewLine
                                   + " Response="
                                   + responseXml);
            }

            return(result);
        }
        public RateResponse Send(string serviceUrl)
        {
            RateResponse result = new RateResponse();

            string xmlToSend = BuildXml();
            string responseXml = RateService.SendRequest(serviceUrl, xmlToSend);
            result.Parse(responseXml);

            if (globals.DiagnosticsMode)
            {
                _logger.LogMessage("FedEx Diagnostics - Request="
                    + xmlToSend + "<br/>"
                    + System.Environment.NewLine
                    + "<br/>"
                    + System.Environment.NewLine
                    + " Response="
                    + responseXml);
            }

            return result;
        }
Beispiel #3
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);
        }