Beispiel #1
0
        public async Task TestAddressValidation(Address address, bool expectedIsValid)
        {
            const string storeId = "some-test-store";

            // Arrange
            var storeService             = new Mock <IStoreService>();
            var taxProviderSearchService = new Mock <ITaxProviderSearchService>();

            var taxProviderSearchCriteria = new TaxProviderSearchCriteria
            {
                StoreIds = new[] { storeId },
                Keyword  = typeof(AvaTaxRateProvider).Name
            };

            taxProviderSearchService.Setup(x => x.SearchTaxProvidersAsync(taxProviderSearchCriteria)).ReturnsAsync(new TaxProviderSearchResult
            {
                TotalCount = 1,
                Results    = new List <TaxProvider>
                {
                    new AvaTaxRateProvider
                    {
                        IsActive = true,
                        Settings = Settings
                    }
                }
            });

            storeService.Setup(x => x.GetByIdAsync(storeId, null)).ReturnsAsync(new Store
            {
                Id = storeId
            });

            var options = new Mock <IOptions <AvaTaxSecureOptions> >();

            options.Setup(x => x.Value).Returns(Options);

            var target = new AddressValidationService(storeService.Object, CreateAvaTaxClient, taxProviderSearchService.Object, options.Object);

            // Act
            var result = await target.ValidateAddressAsync(address, storeId);

            // Assert
            Assert.Equal(expectedIsValid, result.AddressIsValid);
        }
Beispiel #2
0
        public async Task <List <SpecialInstructionData> > GetSpecialInstructionsForLoadAsync(LoadEntity load)
        {
            if (load == null)
            {
                throw new Exception($"Load cannot be null");
            }

            GuardCustomer(load.CustomerId);

            var orderedStops = load.LoadStops?.OrderBy(_ => _.StopNbr).ToList();
            var origin       = orderedStops?.FirstOrDefault();
            var destination  = orderedStops?.LastOrDefault();

            if (origin == null || destination == null)
            {
                return(new List <SpecialInstructionData>());
            }

            var matchingGroups = await _context.SpecialInstructions.AsNoTracking()
                                 .Include(x => x.SpecialInstructionEquipment)
                                 .Where(_ => _.CustomerId == load.CustomerId &&
                                        (_.OriginCity == null || _.OriginCity == origin.City) &&
                                        (_.OriginState == null || _.OriginState == origin.State) &&
                                        (_.OriginPostalCode == null || _.OriginPostalCode == origin.PostalCode) &&
                                        (_.OriginCountry == null || _.OriginCountry == origin.Country) &&
                                        (_.DestinationCity == null || _.DestinationCity == destination.City) &&
                                        (_.DestinationState == null || _.DestinationState == destination.State) &&
                                        (_.DestinationPostalCode == null || _.DestinationPostalCode == destination.PostalCode) &&
                                        (_.DestinationCountry == null || _.DestinationCountry == destination.Country) &&
                                        (!_.SpecialInstructionEquipment.Any() || _.SpecialInstructionEquipment.Any(equipment => equipment.EquipmentId == load.EquipmentId))
                                        )
                                 .ToListAsync();

            // Address standardization has to happen after initial query
            matchingGroups = matchingGroups.Where(_ =>
                                                  (_.OriginAddress1 == null || AddressValidationService.StandardizeAddress(origin.Address1, true)
                                                   .Equals(AddressValidationService.StandardizeAddress(_.OriginAddress1, true), StringComparison.OrdinalIgnoreCase)) &&
                                                  (_.DestinationAddress1 == null || AddressValidationService.StandardizeAddress(destination.Address1, true)
                                                   .Equals(AddressValidationService.StandardizeAddress(_.DestinationAddress1, true), StringComparison.OrdinalIgnoreCase))
                                                  ).ToList();

            return(RankInstructions(matchingGroups));
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            AddressValidationRequest request = CreateAddressValidationRequest();
            //
            AddressValidationService service = new AddressValidationService();

            if (usePropertyFile())
            {
                service.Url = getProperty("endpoint");
            }
            //
            try
            {
                // Call the AddressValidationService passing in an AddressValidationRequest and returning an AddressValidationReply
                AddressValidationReply reply = service.addressValidation(request);
                //
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    ShowAddressValidationReply(reply);
                }
                else
                {
                    foreach (Notification notification in reply.Notifications)
                    {
                        Console.WriteLine(notification.Message);
                    }
                }
            }
            catch (SoapException e)
            {
                Console.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Press any key to quit!");
            Console.ReadKey();
        }
Beispiel #4
0
        private static async Task ValidateAddress(IRequestFactory requestFactory)
        {
            using (IAddressValidationService validationService = new AddressValidationService(requestFactory))
            {
                Console.WriteLine("Type an address to validate/cleanse:");
                var criteria = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(criteria))
                {
                    return;
                }

                var result = await validationService.AddressValidateAsync(criteria);

                if (result.address == null)
                {
                    Console.WriteLine("No match found. " + result.reason);
                }
                else
                {
                    WriteAddressDetails(result.address);
                }
            }
        }
Beispiel #5
0
        protected void FEDEX(Person p)
        {
            string straddress2 = p.Addr1;
            string strzipcode  = p.Zip5;
            string address     = string.Empty;
            string zipfour     = string.Empty;
            string ststate     = string.Empty;
            string zip         = string.Empty;

            string[] split    = null;
            string   delimStr = "-";

            char[] delimiter = delimStr.ToCharArray();
            btn2Submit.Enabled      = true;
            lblAVS_Shipping.Visible = false;

            AddressValidationRequest request = CreateAddressValidationRequest(straddress2, strzipcode);
            //
            AddressValidationService addressValidationService = new AddressValidationService();

            //
            try
            {
                // This is the call to the web service passing in an AddressValidationRequest and returning an AddressValidationReply
                AddressValidationReply reply = addressValidationService.addressValidation(request);
                //
                int score = Convert.ToInt32(reply.AddressResults[0].ProposedAddressDetails[0].Score);
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    foreach (AddressValidationResult result in reply.AddressResults)
                    {
                        foreach (ProposedAddressDetail detail in result.ProposedAddressDetails)
                        {
                            address = detail.Address.StreetLines[0];
                            zip     = detail.Address.PostalCode;
                            split   = zip.Split(delimiter);
                            zip     = split[0];
                            //zipfour = split[1];
                        }
                        if (score < 20)//(split.Length<2) (zipfour == null || zipfour.Length < 4)
                        {
                            lblAVS_Shipping.Text    = "Address Not Found (FedEx)";
                            btn2Submit.Enabled      = false;
                            lblAVS_Shipping.Visible = true;
                        }
                        else
                        {
                            lblAVS_Shipping.Text    = "SUCCESS";
                            btn2Submit.Enabled      = true;
                            lblAVS_Shipping.Visible = false;
                        }
                    }
                }
                else
                {
                    foreach (Notification notification in reply.Notifications)
                    {
                        lblAVS_Shipping.Text = notification.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                //yma add this since fedex return exception when no valid address found
                lblAVS_Shipping.Text    = "Address Not Found (FedEx)";
                btn2Submit.Enabled      = false;
                lblAVS_Shipping.Visible = true;

                //Write to log
                Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEnt = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry();
                logEnt.Message = "\r\n" + "FedEx Address Verification error." + "\r\n" + "Source: " + ex.Source + "\r\n" + "Description: " + ex.Message + "\r\n" + "Stack Trace: " + ex.StackTrace;
                Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(logEnt, "Logs");
            }
        }
        public AddressServiceResponse ValidationServiceClient(ShipServiceInfo clsService, AddressInfo clsAddress)
        {
            string ClassificationType = string.Empty;
            string serviceURL         = string.Empty;

            AddressValidationService service = new AddressValidationService();

            F21.Service.AddressServiceResponse fedExResponse = new F21.Service.AddressServiceResponse();

            try
            {
                if (F21.Framework.ConfigManager.GetAppSetting2("mode").Equals("production", StringComparison.OrdinalIgnoreCase))
                {
                    serviceURL = F21.Framework.ConfigManager.GetAppSetting2("Live_FedExAddressUrl");
                }
                else
                {
                    serviceURL = F21.Framework.ConfigManager.GetAppSetting2("Test_FedExAddressUrl");
                }


                if (string.IsNullOrEmpty(serviceURL))
                {
                    fedExResponse.isSuccess    = false;
                    fedExResponse.ErrorMessage = "Address validation service url is empty.";

                    return(fedExResponse);
                }

                AddressValidationRequest request = CreateAddressValidationRequest(clsService, clsAddress);

                // Test URL : https://wsbeta.fedex.com:443/web-services/addressvalidation
                service.Url = serviceURL;

                AddressValidationReply reply = service.addressValidation(request);

                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    //FedExAddressClassificationType Enum
                    fedExResponse = ShowAddressValidationReply(reply);

                    fedExResponse.HighestSeverity = reply.HighestSeverity.ToString();
                    fedExResponse.isSuccess       = true;
                    fedExResponse.ErrorMessage    = "";
                }
                else
                {
                    fedExResponse.HighestSeverity = reply.HighestSeverity == null ? "" : reply.HighestSeverity.ToString();
                    fedExResponse.isSuccess       = false;

                    foreach (Notification notification in reply.Notifications)
                    {
                        System.Diagnostics.Debug.WriteLine(notification.Message);
                        fedExResponse.ErrorMessage = notification.Message;
                    }
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw ex;
            }
            catch (System.ServiceModel.CommunicationException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(fedExResponse);
        }
        public string Result()
        {
            string FinalResult               = "no";
            bool   isContrySupported         = false;
            bool   isResolved                = false;
            AddressValidationRequest request = CreateAddressValidationRequest();
            //
            AddressValidationService service = new AddressValidationService();

            if (usePropertyFile())
            {
                service.Url = getProperty("endpoint");
            }
            //
            try
            {
                // Call the AddressValidationService passing in an AddressValidationRequest and returning an AddressValidationReply
                AddressValidationReply reply = service.addressValidation(request);
                //
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    //ShowAddressValidationReply(reply);
                    foreach (AddressValidationResult result in reply.AddressResults)
                    {
                        //Console.WriteLine("Address Id : " + result.ClientReferenceId);
                        // if (result.ClassificationSpecified) { Console.WriteLine("Classification: " + result.Classification); }
                        //  if (result.StateSpecified) { Console.WriteLine("State: " + result.State); }
                        //   Console.WriteLine("Proposed Address--");
                        //    Address address = result.EffectiveAddress;
                        //  foreach (String street in address.StreetLines)
                        //  {
                        //      Console.WriteLine("   Street: " + street);
                        // }
                        //  Console.WriteLine("     City: " + address.City);
                        //  Console.WriteLine("    ST/PR: " + address.StateOrProvinceCode);
                        // Console.WriteLine("   Postal: " + address.PostalCode);
                        // Console.WriteLine("  Country: " + address.CountryCode);
                        // Console.WriteLine();
                        //  Console.WriteLine("Address Attributes:");
                        foreach (AddressAttribute attribute in result.Attributes)
                        {
                            if (attribute.Name == "CountrySupported" && attribute.Value == "true")
                            {
                                isContrySupported = true;
                            }
                            else if (attribute.Name == "Resolved" && attribute.Value == "true")
                            {
                                isResolved = true;
                            }
                            //Console.WriteLine("  " + attribute.Name + ": " + attribute.Value);
                        }
                    }
                }
                else
                {
                    // foreach (Notification notification in reply.Notifications)
                    //     Console.WriteLine(notification.Message);
                }
            }
            catch (SoapException e)
            {
                // Console.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                // Console.WriteLine(e.Message);
            }
            //  Console.WriteLine("Press any key to quit!");
            //Console.ReadKey();
            if (isContrySupported && isResolved)
            {
                FinalResult = "yes";
            }
            return(FinalResult);
        }
        public IList <ShippingLoadCarrierGroupData> GetLoadCarrierGroupsForLoad(Guid loadId)
        {
            //TODO: Add validation that user belongs to customer

            var load = _context.Loads
                       .Include(_ => _.LoadStops)
                       .SingleOrDefault(_ => _.LoadId == loadId);

            if (load == null)
            {
                throw new Exception($"Could not find load: {loadId}");
            }

            GuardCustomer(load.CustomerId);

            var orderedStops = load.LoadStops?.OrderBy(_ => _.StopNbr).ToList();
            var origin       = orderedStops?.FirstOrDefault();
            var destination  = orderedStops?.LastOrDefault();

            if (origin == null || destination == null)
            {
                return(null);
            }

            var carriers       = _securityService.GetContractedCarriersByPrimaryCustomerIdAsync();
            var matchingGroups = _context.LoadCarrierGroups
                                 .Include(_ => _.LoadCarrierGroupType)
                                 .Include(_ => _.LoadCarrierGroupCarriers)
                                 .ThenInclude(_ => _.Carrier)
                                 .Where(_ => _.CustomerId == load.CustomerId &&
                                        (_.OriginCity == null || _.OriginCity == origin.City) &&
                                        (_.OriginState == null || _.OriginState == origin.State) &&
                                        (_.OriginPostalCode == null || _.OriginPostalCode == origin.PostalCode) &&
                                        (_.OriginCountry == null || _.OriginCountry == origin.Country) &&
                                        (_.DestinationCity == null || _.DestinationCity == destination.City) &&
                                        (_.DestinationState == null || _.DestinationState == destination.State) &&
                                        (_.DestinationPostalCode == null || _.DestinationPostalCode == destination.PostalCode) &&
                                        (_.DestinationCountry == null || _.DestinationCountry == destination.Country) &&
                                        (!_.LoadCarrierGroupEquipment.Any() || _.LoadCarrierGroupEquipment.Any(loadCarrierGroupEquipment => loadCarrierGroupEquipment.EquipmentId == load.EquipmentId))
                                        )
                                 .ToListAsync();

            Task.WaitAll(carriers, matchingGroups);

            // Address standardization has to happen after initial query
            var groups = matchingGroups.Result.Where(_ =>
                                                     (_.OriginAddress1 == null || AddressValidationService.StandardizeAddress(origin.Address1, true)
                                                      .Equals(AddressValidationService.StandardizeAddress(_.OriginAddress1, true), StringComparison.OrdinalIgnoreCase)) &&
                                                     (_.DestinationAddress1 == null || AddressValidationService.StandardizeAddress(destination.Address1, true)
                                                      .Equals(AddressValidationService.StandardizeAddress(_.DestinationAddress1, true), StringComparison.OrdinalIgnoreCase))
                                                     ).ToList();

            var matchingGroupData = _mapper.Map <IList <ShippingLoadCarrierGroupData> >(groups);

            foreach (var group in matchingGroupData)
            {
                var carrierGroupType = (LoadCarrierGroupTypeEnum)group.LoadCarrierGroupTypeId;

                if (carrierGroupType == LoadCarrierGroupTypeEnum.Exclude)
                {
                    var excludeIds = group.Carriers.Select(carrier => carrier.CarrierId).ToArray();

                    var carrierList = carriers.Result
                                      .Where(x => !excludeIds.Contains(x.CarrierId))
                                      .ToList();

                    group.Carriers = carrierList;
                }
                //Make sure we are returning only carriers scacs that the customer has a contract with
                else
                {
                    var includeIds = group.Carriers.Select(carrier => carrier.CarrierId).ToArray();

                    var carrierList = carriers.Result
                                      .Where(x => includeIds.Contains(x.CarrierId))
                                      .ToList();

                    group.Carriers = carrierList;
                }
            }

            return(matchingGroupData.Where(group => group.Carriers.Any()).ToList());
        }
Beispiel #9
0
        protected void FEDEX(Person p)
        {
            string straddress2 = p.Addr1;
            string strzipcode  = p.Zip5;
            string address     = string.Empty;
            string zipfour     = string.Empty;
            string ststate     = string.Empty;
            string zip         = string.Empty;

            string[] split    = null;
            string   delimStr = "-";

            char[] delimiter = delimStr.ToCharArray();
            //btn2Submit.Enabled = true;
            lblAVS_Shipping.Visible          = false;
            this.divVerifyErrDisplay.Visible = false;

            AddressValidationRequest request = CreateAddressValidationRequest(straddress2, strzipcode);
            //
            AddressValidationService addressValidationService = new AddressValidationService();

            //
            try
            {
                // This is the call to the web service passing in an AddressValidationRequest and returning an AddressValidationReply
                AddressValidationReply reply = addressValidationService.addressValidation(request);
                //
                int score = Convert.ToInt32(reply.AddressResults[0].ProposedAddressDetails[0].Score);
                if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                {
                    foreach (AddressValidationResult result in reply.AddressResults)
                    {
                        foreach (ProposedAddressDetail detail in result.ProposedAddressDetails)
                        {
                            address = detail.Address.StreetLines[0];
                            zip     = detail.Address.PostalCode;
                            split   = zip.Split(delimiter);
                            zip     = split[0];
                            //zipfour = split[1];
                        }
                        if (score < 20)                                 //(split.Length<2) (zipfour == null || zipfour.Length < 4)
                        {
                            lblAVS_Shipping.Text = "Address Not Found"; //intentionally missing period  so I can tell if its usps or fedex
                            //btn2Submit.Enabled = false;
                            lblAVS_Shipping.Visible          = true;
                            this.divVerifyErrDisplay.Visible = true;
                        }
                        else
                        {
                            lblAVS_Shipping.Text = "SUCCESS";
                            //btn2Submit.Enabled = true;
                            lblAVS_Shipping.Visible          = false;
                            this.divVerifyErrDisplay.Visible = false;
                        }
                    }
                }
                else
                {
                    foreach (Notification notification in reply.Notifications)
                    {
                        lblAVS_Shipping.Text = notification.Message;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }