Example #1
0
        public CheckResult Check(IUnitOfWork db,
                                 DTOMarketOrder order,
                                 IList <ListingOrderDTO> items,
                                 AddressValidationStatus addressValidationStatus)
        {
            if (order.Id == 0)
            {
                throw new ArgumentOutOfRangeException("order.Id", "Should be non zero");
            }

            if (order.OrderStatus == OrderStatusEnumEx.Pending)
            {
                throw new ArgumentException("order.OrderStatus", "Not supported status Pending");
            }


            if (addressValidationStatus >= AddressValidationStatus.Invalid)
            {
                var address     = order.GetAddressDto();
                var isFFAddress = AddressHelper.IsFFAddress(address);

                if (isFFAddress)
                {
                    return(new CheckResult()
                    {
                        IsSuccess = true
                    });
                }
            }

            return(new CheckResult()
            {
                IsSuccess = false
            });
        }
Example #2
0
        public CheckResult Check(IUnitOfWork db,
                                 DTOMarketOrder order,
                                 IList <ListingOrderDTO> items,
                                 AddressValidationStatus addressValidationStatus)
        {
            if (order.Id == 0)
            {
                throw new ArgumentOutOfRangeException("order.Id", "Should be non zero");
            }

            if (order.OrderStatus == OrderStatusEnumEx.Pending)
            {
                throw new ArgumentException("order.OrderStatus", "Not supported status Pending");
            }

            if (ShippingUtils.IsLatvia(order.FinalShippingCountry))
            {
                if ((order.ShippingZip ?? "").Contains("LV-"))
                {
                    return(new CheckResult()
                    {
                        IsSuccess = true,
                        AdditionalData = new[] { (order.ShippingZip ?? "").Replace("LV-", "LV") }
                    });
                }
            }

            return(new CheckResult()
            {
                IsSuccess = false
            });
        }
Example #3
0
        internal static string ToSerializedValue(this AddressValidationStatus value)
        {
            switch (value)
            {
            case AddressValidationStatus.Valid:
                return("Valid");

            case AddressValidationStatus.Invalid:
                return("Invalid");

            case AddressValidationStatus.Ambiguous:
                return("Ambiguous");
            }
            return(null);
        }
Example #4
0
        public CheckResult Check(IUnitOfWork db,
                                 DTOMarketOrder order,
                                 IList <ListingOrderDTO> items,
                                 AddressValidationStatus addressValidationStatus)
        {
            if (order.Id == 0)
            {
                throw new ArgumentOutOfRangeException("order.Id", "Should be non zero");
            }

            if (order.OrderStatus == OrderStatusEnumEx.Pending)
            {
                throw new ArgumentException("order.OrderStatus", "Not supported status Pending");
            }

            if (ShippingUtils.IsCanada(order.FinalShippingCountry))
            {
                var state = order.FinalShippingState;
                if ((state ?? "").Length > 2)
                {
                    var stateAbbr = db.States.GetCodeByName(state);
                    if (!String.IsNullOrEmpty(stateAbbr))
                    {
                        return(new CheckResult()
                        {
                            IsSuccess = true,
                            AdditionalData = new[] { stateAbbr }
                        });
                    }
                }
            }

            return(new CheckResult()
            {
                IsSuccess = false
            });
        }
Example #5
0
        internal static AddressResourceData DeserializeAddressResourceData(JsonElement element)
        {
            IDictionary <string, string> tags                          = default;
            AzureLocation                      location                = default;
            ResourceIdentifier                 id                      = default;
            string                             name                    = default;
            ResourceType                       type                    = default;
            SystemData                         systemData              = default;
            Optional <ShippingAddress>         shippingAddress         = default;
            ContactDetails                     contactDetails          = default;
            Optional <AddressValidationStatus> addressValidationStatus = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = new AzureLocation(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("shippingAddress"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            shippingAddress = ShippingAddress.DeserializeShippingAddress(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("contactDetails"))
                        {
                            contactDetails = ContactDetails.DeserializeContactDetails(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("addressValidationStatus"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            addressValidationStatus = new AddressValidationStatus(property0.Value.GetString());
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new AddressResourceData(id, name, type, systemData, tags, location, shippingAddress.Value, contactDetails, Optional.ToNullable(addressValidationStatus)));
        }
Example #6
0
        public CheckResult Check(IUnitOfWork db,
                                 DTOMarketOrder order,
                                 IList <ListingOrderDTO> items,
                                 AddressValidationStatus addressValidationStatus)
        {
            if (order.Id == 0)
            {
                throw new ArgumentOutOfRangeException("order.Id", "Should be non zero");
            }

            if (order.OrderStatus == OrderStatusEnumEx.Pending)
            {
                throw new ArgumentException("order.OrderStatus", "Not supported status Pending");
            }

            if (order.IsManuallyUpdated)
            {
                order.ManuallyPersonName = ReplaceFrench(order.ManuallyPersonName);
            }
            else
            {
                order.PersonName = ReplaceFrench(order.PersonName);
            }

            if (order.IsManuallyUpdated)
            {
                order.ManuallyShippingAddress1 = ReplaceFrench(order.ManuallyShippingAddress1);
            }
            else
            {
                order.ShippingAddress1 = ReplaceFrench(order.ShippingAddress1);
            }

            if (order.IsManuallyUpdated)
            {
                order.ManuallyShippingAddress2 = ReplaceFrench(order.ManuallyShippingAddress2);
            }
            else
            {
                order.ShippingAddress2 = ReplaceFrench(order.ShippingAddress2);
            }

            if (order.IsManuallyUpdated)
            {
                order.ManuallyShippingState = ReplaceFrench(order.ManuallyShippingState);
            }
            else
            {
                order.ShippingState = ReplaceFrench(order.ShippingState);
            }

            if (order.IsManuallyUpdated)
            {
                order.ManuallyShippingCity = ReplaceFrench(order.ManuallyShippingCity);
            }
            else
            {
                order.ShippingCity = ReplaceFrench(order.ShippingCity);
            }

            return(new CheckResult()
            {
                IsSuccess = false
            });
        }
        public CheckResult Check(IUnitOfWork db,
                                 DTOMarketOrder order,
                                 IList <ListingOrderDTO> items,
                                 AddressValidationStatus addressValidationStatus)
        {
            //NOTE: Skipping valid addresses
            if (addressValidationStatus < AddressValidationStatus.Invalid)
            {
                return(new CheckResult()
                {
                    IsSuccess = true
                });
            }

            var checkUSPSService   = new PersonatorAddressCheckService(_log, _htmlScraper, null);
            var address            = order.GetAddressDto();
            var addressCheckResult = checkUSPSService.ScrappingCheckAddress(address);
            var result             = new CheckResult()
            {
                IsSuccess = !addressCheckResult.IsNotServedByUSPSNote
            };

            _log.Info("AddressNotServedByUSPSChecker, hasNote=" + addressCheckResult.IsNotServedByUSPSNote);

            if (addressCheckResult.IsNotServedByUSPSNote)
            {
                var existNotifier = db.OrderEmailNotifies.IsExist(order.OrderId,
                                                                  OrderEmailNotifyType.OutputAddressNotServedByUSPSEmail);

                if (!existNotifier)
                {
                    var emailInfo = new AddressNotServedByUSPSEmailInfo(_emailService.AddressService,
                                                                        null,
                                                                        order.OrderId,
                                                                        (MarketType)order.Market,
                                                                        address,
                                                                        order.BuyerName,
                                                                        order.BuyerEmail,
                                                                        order.EarliestShipDate ?? (order.OrderDate ?? DateTime.Today).AddDays(1));

                    _emailService.SendEmail(emailInfo, CallSource.Service);
                    _log.Info("Send address not served by USPS email, orderId=" + order.Id);

                    db.OrderEmailNotifies.Add(new OrderEmailNotify()
                    {
                        OrderNumber = order.OrderId,
                        Reason      = "Address isn’t served by USPS",
                        Type        = (int)OrderEmailNotifyType.OutputAddressNotServedByUSPSEmail,
                        CreateDate  = _time.GetUtcTime(),
                    });
                }

                db.OrderComments.Add(new OrderComment()
                {
                    OrderId    = order.Id,
                    Message    = "Address isn’t served by USPS. Address verification email sent.",
                    Type       = (int)CommentType.OutputEmail,
                    CreateDate = _time.GetAppNowTime(),
                    UpdateDate = _time.GetAppNowTime()
                });

                db.Commit();
            }
            return(result);
        }
Example #8
0
 public AddressValidationResult(AddressValidationStatus status = AddressValidationStatus.Success, string message = null, IEnumerable <Address> correctedAddresses = null)
 {
     Status             = status;
     Message            = message;
     CorrectedAddresses = correctedAddresses;
 }
Example #9
0
        public CheckResult Check(IUnitOfWork db,
                                 DTOMarketOrder order,
                                 IList <ListingOrderDTO> items,
                                 AddressValidationStatus addressValidationStatus)
        {
            if (order.Id == 0)
            {
                throw new ArgumentOutOfRangeException("order.Id", "Should be non zero");
            }

            if (order.OrderStatus == OrderStatusEnumEx.Pending)
            {
                throw new ArgumentException("order.OrderStatus", "Not supported status Pending");
            }

            //International order has issue with PersonName
            if (ShippingUtils.IsInternational(order.FinalShippingCountry))
            {
                if (String.IsNullOrEmpty(order.FinalShippingPhone))
                {
                    var emailInfo = new PhoneMissingEmailInfo(_emailService.AddressService,
                                                              null,
                                                              order.OrderId,
                                                              (MarketType)order.Market,
                                                              items,
                                                              order.BuyerName,
                                                              order.BuyerEmail);

                    _emailService.SendEmail(emailInfo, CallSource.Service);
                    _log.Info("Send phone missing email, orderId=" + order.Id);

                    db.OrderEmailNotifies.Add(new OrderEmailNotify()
                    {
                        OrderNumber = order.OrderId,
                        Reason      = "System emailed, missing phone number",
                        Type        = (int)OrderEmailNotifyType.OutputPhoneMissingEmail,
                        CreateDate  = _time.GetUtcTime(),
                    });

                    db.OrderComments.Add(new OrderComment()
                    {
                        OrderId    = order.Id,
                        Message    = "[System] Missing phone email sent",
                        Type       = (int)CommentType.Address,
                        CreateDate = _time.GetAppNowTime(),
                        UpdateDate = _time.GetAppNowTime()
                    });

                    db.Commit();

                    return(new CheckResult()
                    {
                        IsSuccess = false
                    });
                }
            }

            return(new CheckResult()
            {
                IsSuccess = true
            });
        }
Example #10
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="AddressValidationStatus" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => AddressValidationStatus.CreateFrom(sourceValue);
        public CheckResult Check(IUnitOfWork db,
                                 DTOMarketOrder order,
                                 IList <ListingOrderDTO> items,
                                 AddressValidationStatus addressValidationStatus)
        {
            if (order.Id == 0)
            {
                throw new ArgumentOutOfRangeException("order.Id", "Should be non zero");
            }

            if (order.OrderStatus == OrderStatusEnumEx.Pending)
            {
                throw new ArgumentException("order.OrderStatus", "Not supported status Pending");
            }

            //International order has issue with PersonName
            if (!AddressHelper.IsStampsValidPersonName(order.FinalPersonName) &&
                (order.AddressValidationStatus == (int)AddressValidationStatus.InvalidRecipientName ||
                 ShippingUtils.IsInternationalState(order.FinalShippingState) ||
                 ShippingUtils.IsInternational(order.FinalShippingCountry)))
            {
                //If can resolved using BuyerName
                var nameKeywords = (order.FinalPersonName ?? "").Split(", .".ToCharArray()).Where(n => n.Length > 2).ToArray();
                if (!nameKeywords.Any())
                {
                    nameKeywords = (order.FinalPersonName ?? "").Split(", .".ToCharArray()).ToArray();
                }

                if (AddressHelper.IsStampsValidPersonName(order.BuyerName)
                    //NOTE: #1 Exclude prefix Mr., initials, like a.cheszes
                    //NOTE: #2 Include when name has only one letter
                    && StringHelper.ContrainOneOfKeywords(order.BuyerName, nameKeywords))
                {
                    db.OrderComments.Add(new OrderComment()
                    {
                        OrderId = order.Id,
                        Message = "[System] Incomplete recipient name was replaced with buyer name: "
                                  + order.FinalPersonName + "=>" + order.BuyerName,
                        Type       = (int)CommentType.Address,
                        CreateDate = _time.GetAppNowTime()
                    });

                    if (order.IsManuallyUpdated)
                    {
                        order.ManuallyPersonName = order.BuyerName;
                    }
                    else
                    {
                        order.PersonName = order.BuyerName;
                    }

                    return(new CheckResult()
                    {
                        IsSuccess = true,
                        AdditionalData = new[] { order.PersonName }
                    });
                }
                //Send email
                else
                {
                    var emailInfo = new IncompleteNameEmailInfo(_emailService.AddressService,
                                                                null,
                                                                order.OrderId,
                                                                (MarketType)order.Market,
                                                                order.GetAddressDto(),
                                                                items,
                                                                order.BuyerName,
                                                                order.BuyerEmail);

                    _emailService.SendEmail(emailInfo, CallSource.Service);
                    _log.Info("Send incomplete person name email, orderId=" + order.Id);

                    db.OrderEmailNotifies.Add(new OrderEmailNotify()
                    {
                        OrderNumber = order.OrderId,
                        Reason      = "System emailed, incomplete name",
                        Type        = (int)OrderEmailNotifyType.OutputIncompleteNameEmail,
                        CreateDate  = _time.GetUtcTime(),
                    });

                    db.OrderComments.Add(new OrderComment()
                    {
                        OrderId    = order.Id,
                        Message    = "[System] Incomplete name email sent",
                        Type       = (int)CommentType.Address,
                        CreateDate = _time.GetAppNowTime(),
                        UpdateDate = _time.GetAppNowTime()
                    });

                    db.Commit();

                    return(new CheckResult()
                    {
                        IsSuccess = false,
                        AdditionalData = new List <string>()
                        {
                            "OnHold"
                        }
                    });
                }
            }

            return(new CheckResult()
            {
                IsSuccess = false
            });
        }