public new async Task <AddressValidationResult> ValidateAsync(
            string address,
            bool skipChecksumValidation,
            bool skipWhiteAndBlacklistCheck)
        {
            if (!IconKeys.IsValidAddress(address))
            {
                return(AddressValidationResult.AddressIsInvalid(AddressValidationError.FormatIsInvalid));
            }

            var addressObj = new Address(address);

            if (addressObj.GetPrefix() == AddressPrefix.FromString(AddressPrefix.Contract))
            {
                return(AddressValidationResult.AddressIsInvalid(AddressValidationError.FormatIsInvalid));
            }

            if (skipWhiteAndBlacklistCheck)
            {
                address = address.ToLowerInvariant();

                if (await _blockchainService.IsContractAsync(address) &&
                    !await _whitelistedAddressRepository.ContainsAsync(address) &&
                    await _blacklistedAddressRepository.ContainsAsync(address))
                {
                    return(AddressValidationResult.AddressIsInvalid(AddressValidationError.AddressIsBlacklisted));
                }
            }

            return(AddressValidationResult.AddressIsValid());
        }
        private AddressValidationResult ValidateAddress(CustomerAddress address)
        {
            var result = new AddressValidationResult();

            if (address != null)
            {
                result.validationResult = address.Validate();

                if (address.ID > 0)
                {
                    result.isFromDifferentCustomer = address.OriginalAddress.AddressCustomerID != mCart.Customer.ID;
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public AddressValidationResult ValidateAddress(string street, string city, string state, string postalCode, string countryCode)
        {
            if (string.Equals(countryCode, "US", StringComparison.OrdinalIgnoreCase) || string.Equals(countryCode, "PR", StringComparison.OrdinalIgnoreCase))
            {
                try
                {
                    var addressToValidate = new Address(street, city, state, postalCode, countryCode);
                    var result            = new AddressValidationResult(ValidateAddress(addressToValidate), addressToValidate);

                    return(result);
                }
                catch (Exception ex)
                {
                    return(new AddressValidationResult(ex));
                }
            }
            else
            {
                //not a US country code
                return(new AddressValidationResult("Validation can only be completed on US and Puerto Rican addresses", AddressValidationResult.ResponseStatus.NotUSAddress));
            }
        }
Exemplo n.º 4
0
        public async Task Get_address_validity(string address, AddressTagType?tagType, string tag, AddressValidationResult validationResult)
        {
            //ARRANGE
            var client = PrepareClient <AppSettings>((options) =>
            {
                var aggregator = CreateMocksAndSetupFactories(options);

                options.IntegrationName = $"{nameof(TransactionExecutorClientTests)}+{nameof(Get_address_validity)}";
                aggregator.HealthProvider.Setup(x => x.GetDiseaseAsync()).ReturnsAsync(Disease);
                aggregator.AddressValidator.Setup(x => x.ValidateAsync(address, tagType, tag))
                .ReturnsAsync(new AddressValidityResponse(validationResult));
            });

            //ACT
            var result = await client.GetAddressValidityAsync(address, tagType, tag);

            //ASSERT

            Assert.True(result != null);
            Assert.True(result.Result == validationResult);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Endpoint: [GET] /api/addresses/{address}/validity?[tag=string]
 /// </summary>
 /// <param name="result">Result of the address validation.</param>
 public AddressValidityResponse(AddressValidationResult result)
 {
     Result = result;
 }