Example #1
0
        public IList <CheckResult <AddressDTO> > CheckAddress(CallSource callSource,
                                                              AddressDTO inputAddress,
                                                              AddressProviderType[] applyAddressProviderTypes)
        {
            var checkResults = new List <CheckResult <AddressDTO> >();

            var actualAddressCheckers = _addressCheckers;

            if (applyAddressProviderTypes != null)
            {
                actualAddressCheckers = _addressCheckers.Where(a => applyAddressProviderTypes.Contains(a.Type)).ToList();
            }

            foreach (var checker in actualAddressCheckers)
            {
                var checkResult = checker.CheckAddress(callSource, inputAddress);
                checkResults.Add(checkResult);

                ////NOTE: break after first validation success result
                //if (checkResult.Status < (int)AddressValidationStatus.Invalid
                //    && checkResult.Status != (int)AddressValidationStatus.None)
                //    break;
            }
            return(checkResults);
        }
Example #2
0
        public CheckResult <AddressDTO> CheckAddress(CallSource callSource, AddressDTO inputAddress)
        {
            if (String.IsNullOrEmpty(inputAddress.BuyerEmail))
            {
                return(new CheckResult <AddressDTO>()
                {
                    Status = (int)AddressValidationStatus.Valid,
                    AdditionalData = null,
                });
            }

            var additionalData = new List <string>()
            {
                OrderNotifyType.AddressCheckWithPerviousCorrection.ToString()
            };

            Order lastCorrection = null;


            using (var db = _dbFactory.GetRDb())
            {
                lastCorrection = db.Orders.GetAddressCorrectionForBuyer(inputAddress.BuyerEmail,
                                                                        inputAddress.Address1,
                                                                        inputAddress.Address2,
                                                                        inputAddress.City,
                                                                        inputAddress.State,
                                                                        inputAddress.Country,
                                                                        inputAddress.Zip,
                                                                        inputAddress.ZipAddon);
            }
            if (lastCorrection != null)
            {
                var outputAddress = new AddressDTO()
                {
                    FullName = inputAddress.FullName,
                    Phone    = inputAddress.Phone,

                    Country  = lastCorrection.ManuallyShippingCountry,
                    City     = lastCorrection.ManuallyShippingCity,
                    State    = lastCorrection.ManuallyShippingState,
                    Address1 = lastCorrection.ManuallyShippingAddress1,
                    Address2 = lastCorrection.ManuallyShippingAddress2,
                    Zip      = lastCorrection.ManuallyShippingZip,
                    ZipAddon = lastCorrection.ManuallyShippingZipAddon,
                };

                return(new CheckResult <AddressDTO>()
                {
                    Status = (int)AddressValidationStatus.Valid,
                    AdditionalData = additionalData,
                    Data = outputAddress
                });
            }
            return(new CheckResult <AddressDTO>()
            {
                Status = (int)AddressValidationStatus.Invalid,
                AdditionalData = additionalData,
            });
        }
Example #3
0
 public ICallLine CreateCall(CallData callData) => CallSource.CreateCall(this, new OutgoingCall(
                                                                             callData.OriginalLine,
                                                                             callData.DateTime,
                                                                             callData.InternalNumber,
                                                                             this,
                                                                             callData.CoCode,
                                                                             callData.CdCode,
                                                                             callData.Duration,
                                                                             callData.Cost));
Example #4
0
 public IList <CheckResult <AddressDTO> > CheckAddress(CallSource callSource,
                                                       IUnitOfWork db,
                                                       AddressDTO address,
                                                       long?orderId,
                                                       out AddressDTO addressWithCorrection)
 {
     return(new AddressChecker(_log, _dbFactory, _addressService, _orderHistory, _time).CheckAddress(CallSource.Service,
                                                                                                     db,
                                                                                                     address,
                                                                                                     orderId,
                                                                                                     out addressWithCorrection));
 }
Example #5
0
        public CheckResult <AddressDTO> CheckAddress(CallSource callSource, AddressDTO inputAddress)
        {
            //var geocoder = new GoogleGeocoder() {ApiKey = _addressProviderInfo.Key1};

            ////Should be only if UI call
            //if (callSource == CallSource.UI)
            //{
            //    //Ignore address2
            //    inputAddress.Address2 = "";
            //}
            //var searchString = AddressHelper.ToString(inputAddress, " ");
            //IEnumerable<GoogleAddress> addresses = geocoder.Geocode(searchString);
            //var firstMatch = addresses.FirstOrDefault();

            //var isValid = firstMatch != null
            //    && firstMatch.LocationType == GoogleLocationType.Rooftop
            //    && !firstMatch.IsPartialMatch;

            //var message = String.Empty;
            //if (firstMatch != null)
            //{
            //    message = "LocationType=" + firstMatch.LocationType
            //        + ", IsPartialMatch=" + StringHelper.ToYesNo(firstMatch.IsPartialMatch);
            //}

            //return new CheckResult<AddressDTO>()
            //{
            //    Status = isValid ? (int)AddressValidationStatus.Valid : (int)AddressValidationStatus.Invalid,
            //    Message = message,
            //    AdditionalData = new List<string>() { OrderNotifyType.AddressCheckGoogleGeocode.ToString() }
            //};

            return(new CheckResult <AddressDTO>()
            {
                Status = (int)AddressValidationStatus.Valid,
                Message = "[Service unavailable]",
                AdditionalData = new List <string>()
                {
                    OrderNotifyType.AddressCheckGoogleGeocode.ToString()
                }
            });
        }
Example #6
0
        private void SetupTableView()
        {
            HasHistoryCalls(true);

            var source = new CallSource(_tableView, ViewModel.CallHistory, ViewModel.Delete, ViewModel.CallActionInfo);

            _tableView.Source = source;

            source.CallEvent -= OnSource_CallEvent;
            source.CallEvent += OnSource_CallEvent;

            source.OpenCallerProfileEvent -= OnSource_OpenCallerProfileEvent;
            source.OpenCallerProfileEvent += OnSource_OpenCallerProfileEvent;

            source.DeleteCallEvent -= OnSource_DeleteCallEvent;
            source.DeleteCallEvent += OnSource_DeleteCallEvent;

            source.CallStackEvent -= OnSource_CallStackEvent;
            source.CallStackEvent += OnSource_CallStackEvent;

            _tableView.ReloadData();
        }
Example #7
0
        public CheckResult <AddressDTO> CheckAddress(CallSource callSource, AddressDTO inputAddress)
        {
            //outputAddress = null;

            var fedexApi = new FedexAddressApi(_log,
                                               _time,
                                               _addressProviderInfo.EndPoint,
                                               _addressProviderInfo.UserName,
                                               _addressProviderInfo.Password,
                                               _addressProviderInfo.Key1,
                                               _addressProviderInfo.Key2,
                                               _addressProviderInfo.Key3,
                                               _portalName);

            //Should be only if UI call
            if (callSource == CallSource.UI)
            {
                //Ignore address2
                inputAddress.Address2 = "";
            }
            var searchString = AddressHelper.ToString(inputAddress, " ");
            var result       = fedexApi.ValidateAddress(inputAddress);

            var isValid = result != null &&
                          result.Data != null &&
                          result.Data.ValidationStatus < (int)AddressValidationStatus.Invalid;

            return(new CheckResult <AddressDTO>()
            {
                Status = isValid ? (int)AddressValidationStatus.Valid : (int)AddressValidationStatus.Invalid,
                Message = "Effective Address: " + StringHelper.Join(", ", result.Data.Address1, result.Data.Address2, result.Data.City, result.Data.State, result.Data.Zip, result.Data.Country),
                AdditionalData = new List <string>()
                {
                    OrderNotifyType.AddressCheckFedex.ToString(), result.Data?.IsResidential.ToString(), result.Data?.State
                },
                Data = result.Data
            });
        }
        public IList <CheckResult <AddressDTO> > CheckAddress(CallSource callSource,
                                                              IUnitOfWork db,
                                                              AddressDTO address,
                                                              long?orderId,
                                                              out AddressDTO addressWithCorrection)
        {
            if (orderId.HasValue && orderId.Value == 0)
            {
                throw new ArgumentOutOfRangeException("order.Id", "Should be non zero");
            }

            addressWithCorrection = null;

            var checkResults = _addressService.CheckAddress(callSource,
                                                            address);

            OrderNotify dbStampsOrderNotify = null;

            foreach (var subResult in checkResults)
            {
                //Stamps
                if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckStamps.ToString())
                {
                    if (orderId.HasValue)
                    {
                        dbStampsOrderNotify = new OrderNotify()
                        {
                            OrderId    = orderId.Value,
                            Type       = (int)OrderNotifyType.AddressCheckStamps,
                            Message    = StringHelper.Substring(subResult.Message, 512),
                            Status     = (int)subResult.Status,
                            CreateDate = _time.GetAppNowTime()
                        };

                        db.OrderNotifies.Add(dbStampsOrderNotify);
                    }
                }

                //Previous correction address
                if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckWithPerviousCorrection.ToString())
                {
                    addressWithCorrection = subResult.Data;

                    if (orderId.HasValue)
                    {
                        db.OrderNotifies.Add(new OrderNotify()
                        {
                            OrderId    = orderId.Value,
                            Type       = (int)OrderNotifyType.AddressCheckWithPerviousCorrection,
                            Message    = StringHelper.Substring(subResult.Message, 512),
                            Status     = subResult.Status,
                            CreateDate = _time.GetUtcTime()
                        });
                    }

                    if (subResult.Status < (int)AddressValidationStatus.Invalid &&
                        subResult.Status != (int)AddressValidationStatus.None)
                    {
                        if (addressWithCorrection != null &&
                            String.IsNullOrEmpty(addressWithCorrection.Address1) &&
                            String.IsNullOrEmpty(addressWithCorrection.Address2) &&
                            String.IsNullOrEmpty(addressWithCorrection.City) &&
                            String.IsNullOrEmpty(addressWithCorrection.State) &&
                            String.IsNullOrEmpty(addressWithCorrection.Country) &&
                            String.IsNullOrEmpty(addressWithCorrection.Zip) &&
                            String.IsNullOrEmpty(addressWithCorrection.ZipAddon))
                        {
                            addressWithCorrection = null;
                        }

                        if (addressWithCorrection != null)
                        {
                            /*
                             * Похоже идея автоматически менять адрес на предыдущий не совсем хорошая, есть клиент например который хотел послать посылку на новый адрес а мы послали на старый 110-4229580-1843404
                             * Давай теперь вместо автоматического исправления адреса просто писать коммент, «previous delivery to %Old_Address% was successful”
                             */

                            if (orderId.HasValue)
                            {
                                var addressString = AddressHelper.ToString(addressWithCorrection, ", ");

                                db.OrderComments.Add(new OrderComment()
                                {
                                    OrderId    = orderId.Value,
                                    Message    = String.Format("[System] Previous delivery to \"{0}\" was successful", addressString),
                                    Type       = (int)CommentType.Address,
                                    CreateDate = _time.GetUtcTime()
                                });
                            }

                            //NOTE: Previous correction address uses only to create order comment
                            addressWithCorrection = null;
                        }
                    }
                }

                if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckMelissa.ToString())
                {
                    //Nothing
                }

                if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckGoogleGeocode.ToString())
                {
                    if (orderId.HasValue)
                    {
                        db.OrderNotifies.Add(new OrderNotify()
                        {
                            OrderId    = orderId.Value,
                            Type       = (int)OrderNotifyType.AddressCheckGoogleGeocode,
                            Message    = StringHelper.Substring(subResult.Message, 512),
                            Status     = subResult.Status,
                            CreateDate = _time.GetUtcTime()
                        });
                    }
                }
                if (subResult.AdditionalData?[0] == OrderNotifyType.AddressCheckFedex.ToString())
                {
                    if (orderId.HasValue)
                    {
                        db.OrderNotifies.Add(new OrderNotify()
                        {
                            OrderId    = orderId.Value,
                            Type       = (int)OrderNotifyType.AddressCheckFedex,
                            Message    = StringHelper.Substring(subResult.Message, 512),
                            Status     = subResult.Status,
                            CreateDate = _time.GetUtcTime()
                        });
                    }

                    var stampsResult = checkResults.FirstOrDefault(r => r.AdditionalData[0] == OrderNotifyType.AddressCheckStamps.ToString());
                    if (stampsResult != null && stampsResult.Status >= (int)AddressValidationStatus.Invalid)
                    {
                        if (subResult.Status < (int)AddressValidationStatus.Invalid)
                        {
                            if (addressWithCorrection == null &&
                                subResult.Data != null)
                            {
                                var correctionCandidate = subResult.Data;
                                correctionCandidate.FullName = address.FullName;
                                //TASK: If stamps verify it replace it, and don’t show errors.
                                var addressCandidateResults = _addressService.CheckAddress(callSource,
                                                                                           correctionCandidate,
                                                                                           new Core.Models.Settings.AddressProviderType[] { Core.Models.Settings.AddressProviderType.Stamps });

                                var stampsCandidateResult = addressCandidateResults.FirstOrDefault(r => r.AdditionalData[0] == OrderNotifyType.AddressCheckStamps.ToString());
                                if (stampsCandidateResult.Status < (int)AddressValidationStatus.Invalid)
                                {
                                    _log.Info("Replacing address to Fedex Effective address");

                                    stampsResult.Status = stampsCandidateResult.Status;
                                    if (dbStampsOrderNotify != null)
                                    {
                                        dbStampsOrderNotify.Status = stampsCandidateResult.Status;
                                    }

                                    if (orderId.HasValue)
                                    {
                                        db.OrderComments.Add(new OrderComment()
                                        {
                                            OrderId    = orderId.Value,
                                            Message    = String.Format("[System] Address was replaced by Fedex \"Effective address\""),
                                            Type       = (int)CommentType.Address,
                                            CreateDate = _time.GetUtcTime()
                                        });
                                    }

                                    addressWithCorrection = subResult.Data;
                                }
                            }
                        }
                    }
                }
            }

            return(checkResults);
        }
Example #9
0
 public IList <CheckResult <AddressDTO> > CheckAddress(CallSource callSource,
                                                       AddressDTO inputAddress)
 {
     return(CheckAddress(callSource, inputAddress, null));
 }
        public CheckResult <AddressDTO> CheckAddress(CallSource callSource, AddressDTO inputAddress)
        {
            var additionalData = new List <string>()
            {
                OrderNotifyType.AddressCheckMelissa.ToString()
            };

            if (ShippingUtils.IsInternational(inputAddress.FinalCountry))
            {
                return(new CheckResult <AddressDTO>()
                {
                    IsSuccess = false,
                    AdditionalData = additionalData
                });
            }

            //The Check action will validate the individual input data pieces for validity and correct them if possible.
            //If the data is correctable, additional information will often be appended as well. US and Canada only.
            //Set the Server URL to the form input
            var url = "https://personator.melissadata.net/v3/WEB/ContactVerify/doContactVerify";

            url += "?t=";                //TransmissionReference
            url += "&id=" + _customerId; // "114035921";
            url += "&act=Check";
            //-Plus4
            //Returns the 4-digit plus4 for the input address. If this column is requested, the PostalCode field will
            //only contain the 5-digit ZIP for U.S. addresses.
            //-PrivateMailBox
            //Returns the private mail box number for the address in the AddressLine field, if any. Private mailboxes
            //are private mail boxes in commercial mail receiving agencies, like a UPS Store. If requested, the Private
            //mailbox will be populated in this field instead of the Address field.
            //-Suite
            //Returns the suite for the address in the AddressLine field, if any. If requested, the suite will be
            //populated in this field instead of the Address field.
            url += "&cols=Plus4"; //Columns "Plus4,PrivateMailBox,Suite";
            url += "&opt=";       //Options
            url += "&first=";
            url += "&last=";
            url += "&full=" + HttpUtility.UrlEncode(inputAddress.FinalFullName);
            url += "&comp=";
            url += "&a1=" + HttpUtility.UrlEncode(inputAddress.FinalAddress1);
            url += "&a2=" + HttpUtility.UrlEncode(inputAddress.FinalAddress2);
            url += "&city=" + HttpUtility.UrlEncode(inputAddress.FinalCity);
            url += "&state=" + HttpUtility.UrlEncode(inputAddress.FinalState);
            url += "&postal=" + HttpUtility.UrlEncode(inputAddress.FinalZip
                                                      + (!String.IsNullOrEmpty(inputAddress.FinalZipAddon) ? "-" + inputAddress.FinalZipAddon : ""));
            url += "&ctry=" + HttpUtility.UrlEncode(inputAddress.FinalCountry);
            url += "&lastlines=";
            url += "&freeform=";
            url += "&email=";
            url += "&phone=" + HttpUtility.UrlEncode(inputAddress.FinalPhone);
            url += "&reserved=";

            //url = url.Replace("#", "%23");
            var uri = new Uri(url);

            CheckResult <AddressDTO> result = null;

            try
            {
                var request = (HttpWebRequest)WebRequest.Create(uri);
                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    using (var responseStream = response.GetResponseStream())
                    {
                        var doc = new XmlDocument();
                        doc.Load(responseStream);

                        result = ProcessResult(doc);
                        result.AdditionalData = additionalData;
                    }
                }
            }
            catch (Exception ex)
            {
                result = new CheckResult <AddressDTO>()
                {
                    IsSuccess      = false,
                    Message        = ex.Message,
                    AdditionalData = additionalData
                };
            }

            if (result.Data != null)
            {
                var outputAddress = result.Data;
                if (!String.IsNullOrEmpty(outputAddress.AddressKey))
                {
                    if (inputAddress.Address1 == outputAddress.Address1 &&
                        inputAddress.Address2 == outputAddress.Address2 &&
                        inputAddress.City == outputAddress.City &&
                        inputAddress.Country == outputAddress.Country &&
                        inputAddress.State == outputAddress.State &&
                        inputAddress.Zip == outputAddress.Zip &&
                        inputAddress.ZipAddon == outputAddress.ZipAddon)
                    {
                        result.Data = null;
                    }
                }
                else
                {
                    result.Data = null;
                }
            }

            return(result);
        }
        public CheckResult <AddressDTO> CheckAddress(CallSource callSource, AddressDTO inputAddress)
        {
            _log.Info("StampsAddressCheckService, inputAddress=" + inputAddress);

            try
            {
                var status = RetryHelper.ActionWithRetries(() => StampComService.ValidateAddress(
                                                               _log,
                                                               _addressProviderInfo,
                                                               inputAddress),
                                                           _log,
                                                           throwException: true);

                return(new CheckResult <AddressDTO>()
                {
                    Status = (int)status,
                    AdditionalData = new List <string>()
                    {
                        OrderNotifyType.AddressCheckStamps.ToString()
                    },
                });
            }

            catch (FaultException ex)
            {
                if (ExceptionHelper.IsStampsConversationSyncEx(ex) ||
                    ExceptionHelper.IsStampsCommunicationEx(ex))
                {
                    return(new CheckResult <AddressDTO>()
                    {
                        Status = (int)AddressValidationStatus.ExceptionCommunication,
                        Message = ex.Message,
                        AdditionalData = new List <string>()
                        {
                            OrderNotifyType.AddressCheckStamps.ToString()
                        }
                    });
                }
                return(new CheckResult <AddressDTO>()
                {
                    Status = (int)AddressValidationStatus.Exception,
                    Message = ex.Message,
                    AdditionalData = new List <string>()
                    {
                        OrderNotifyType.AddressCheckStamps.ToString()
                    }
                });
            }

            catch (Exception ex)
            {
                var message = ex.Message;
                if (message.Contains("First and Last Name, with two chars each or Full Name with two char First and Last Name or Company Name with two chars is required for both sender and recipient"))
                {
                    return(new CheckResult <AddressDTO>()
                    {
                        Status = (int)AddressValidationStatus.InvalidRecipientName,
                        Message = ex.Message,
                        AdditionalData = new List <string>()
                        {
                            OrderNotifyType.AddressCheckStamps.ToString()
                        }
                    });
                }
                return(new CheckResult <AddressDTO>()
                {
                    Status = (int)AddressValidationStatus.Exception,
                    Message = ex.Message,
                    AdditionalData = new List <string>()
                    {
                        OrderNotifyType.AddressCheckStamps.ToString()
                    }
                });
            }
        }