public void ReCheckPaymentStatuses(IPaymentStatusApi api)
        {
            using (var db = _dbFactory.GetRWDb())
            {
                var orderIdsToUpdate = db.Orders.GetAll()
                                       .Where(o => o.Market == (int)MarketType.Shopify &&
                                              o.OrderStatus == OrderStatusEnumEx.Unshipped &&
                                              o.DropShipperId != DSHelper.OverseasId)
                                       .Select(o => o.MarketOrderId)
                                       .Distinct()
                                       .ToList();

                _log.Info("Items to recheck: " + orderIdsToUpdate.Count);
                var sleeper = new StepSleeper(TimeSpan.FromSeconds(1), 3);
                foreach (var orderId in orderIdsToUpdate)
                {
                    var riskStatus = RetryHelper.ActionWithRetries(() => { return(api.GetOrderRisk(orderId)); }, _log);
                    if (riskStatus?.PaymentValidationStatuses == (int)PaymentValidationStatuses.Red)
                    {
                        var validationInfo = new OrderValidationDTO()
                        {
                            CreateDate         = _time.GetAppNowTime(),
                            VerificationStatus = riskStatus.Recommendation,
                            Score = StringHelper.TryGetLong(riskStatus.Score)
                        };

                        var dbOrderList = db.Orders.GetAll().Where(o => o.MarketOrderId == orderId).ToList();
                        foreach (var dbOrder in dbOrderList)
                        {
                            if (dbOrder.OrderStatus == OrderStatusEnumEx.Shipped)
                            {
                                continue;
                            }

                            if (dbOrder.SignifydStatus == riskStatus.PaymentValidationStatuses)
                            {
                                continue;
                            }

                            dbOrder.SignifydDesc   = JsonConvert.SerializeObject(validationInfo, Formatting.Indented);
                            dbOrder.SignifydStatus = riskStatus.PaymentValidationStatuses;

                            _log.Info("OnHold By PaymentChecker, orderId=" + dbOrder.AmazonIdentifier);
                            dbOrder.OnHold           = true;
                            dbOrder.OnHoldUpdateDate = _time.GetAppNowTime();
                        }
                    }
                }

                db.Commit();
            }
        }
        public List <MessageString> ProcessApplyResult(ApplyOrderResult applyResult,
                                                       IUnitOfWork db,
                                                       ILogService log,
                                                       ITime time,
                                                       IOrderSynchronizer synchronizer,
                                                       AddressChecker addressChecker,
                                                       IOrderHistoryService orderHistoryService,
                                                       IWeightService weightService,
                                                       long?by)
        {
            var results = new List <MessageString>();

            if (applyResult.RateRecalcRequested)
            {
                var dtoOrder = db.ItemOrderMappings.GetOrderWithItems(weightService, OrderId, unmaskReferenceStyle: false, includeSourceItems: true);

                try
                {
                    RetryHelper.ActionWithRetries(() => synchronizer.UIUpdate(db,
                                                                              dtoOrder,
                                                                              isForceOverride: false,
                                                                              keepActiveShipping: true,
                                                                              keepCustomShipping: applyResult.ShipmentProviderChanged ? false : true,
                                                                              switchToMethodId: null),
                                                  log,
                                                  2,
                                                  300,
                                                  RetryModeType.Normal,
                                                  true);

                    orderHistoryService.AddRecord(dtoOrder.Id, OrderHistoryHelper.RecalculateRatesKey, null, true, by);
                }
                catch (Exception ex)
                {
                    results.Add(MessageString.Error("", "An unexpected error has occurred. Please try again. Detail: " + ex.Message));
                }
            }

            if (applyResult.AddressValidationRequested)
            {
                addressChecker.UpdateOrderAddressValidationStatus(db, EntityId, null);
            }

            return(results);
        }
        public void GetUSPSTrackingByStamps(string trackingNumber)
        {
            using (var db = _dbFactory.GetRWDb())
            {
                var shipmentProviderInfo = db.ShipmentProviders.GetByCompanyId(_company.Id)
                                           .FirstOrDefault(p => p.Type == (int)ShipmentProviderType.Stamps);

                var trackList = new List <string>()
                {
                    trackingNumber
                };

                var stateList = RetryHelper.ActionWithRetries(
                    () => StampComService.TrackShipment(trackList, shipmentProviderInfo),
                    _log,
                    1,
                    1000,
                    RetryModeType.Normal,
                    true);

                Console.WriteLine(stateList);
            }
        }
Example #4
0
        protected override void RunCallback()
        {
            var dbFactory       = new DbFactory();
            var time            = new TimeService(dbFactory);
            var log             = GetLogger();
            var settings        = new SettingsService(dbFactory);
            var quantityManager = new QuantityManager(GetLogger(), time);
            var actionService   = new SystemActionService(GetLogger(), time);
            var priceManager    = new PriceManager(GetLogger(), time, dbFactory, actionService, settings);

            using (var db = dbFactory.GetRWDb())
            {
                db.DisableValidation();

                RetryHelper.ActionWithRetries(() => quantityManager.FixupListingQuantity(db, settings), log, retryCount: 1, throwException: false);

                RetryHelper.ActionWithRetries(() => priceManager.FixupListingPrices(db), log, retryCount: 1, throwException: false);

                //RetryHelper.ActionWithRetries(() => priceManager.FixupBusinessPrices(db), log, retryCount: 1, throwException: false);
                //RetryHelper.ActionWithRetries(() => priceManager.FixupFBAPrices(db), log, retryCount: 1, throwException: false);

                RetryHelper.ActionWithRetries(() => priceManager.FixupWalmartPrices(db), log, retryCount: 1, throwException: false);
            }
        }
Example #5
0
        public void BuildReportWithUnassignedToAmazonBarcodes()
        {
            var results = new List <FoundItemInfo>();

            using (var db = _dbFactory.GetRWDb())
            {
                var barcodeQuery = from s in db.Styles.GetAll()
                                   join si in db.StyleItems.GetAll() on s.Id equals si.StyleId
                                   join sic in db.StyleItemCaches.GetAll() on si.Id equals sic.Id
                                   join sib in db.StyleItemBarcodes.GetAll() on si.Id equals sib.StyleItemId
                                   where !s.Deleted &&
                                   sic.RemainingQuantity > 0
                                   select new
                {
                    StyleId           = s.Id,
                    StyleString       = s.StyleID,
                    StyleItemId       = si.Id,
                    StyleSize         = si.Size,
                    Barcode           = sib.Barcode,
                    RemainingQuantity = sic.RemainingQuantity,
                };

                var allBarcodes = barcodeQuery.ToList();

                var amazonItems              = db.Items.GetAllViewAsDto(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId).ToList();
                var existBarcodes            = amazonItems.Select(i => i.Barcode).ToList();
                var notExistOnAmazonBarcodes = allBarcodes.Where(b => !String.IsNullOrEmpty(b.Barcode) &&
                                                                 !existBarcodes.Contains(b.Barcode) &&
                                                                 !b.Barcode.StartsWith("647") //Exclude our barcodes
                                                                 ).ToList();

                _log.Info("Not exist barcodes count=" + notExistOnAmazonBarcodes.Count());

                var index = 0;
                var step  = 5;
                while (index < notExistOnAmazonBarcodes.Count)
                {
                    var barcodesToCheck = notExistOnAmazonBarcodes.Skip(index).Take(step).ToList();
                    var foundItems      = RetryHelper.ActionWithRetries(() =>
                                                                        _amazonApi.GetProductForBarcode(barcodesToCheck.Select(b => b.Barcode).ToList()),
                                                                        _log,
                                                                        3,
                                                                        5000,
                                                                        RetryModeType.Normal);

                    var notEmptyItems = foundItems.Where(i => !String.IsNullOrEmpty(i.ASIN)).ToList();
                    if (notEmptyItems.Any())
                    {
                        foreach (var notEmptyItem in notEmptyItems)
                        {
                            var foundItem   = new FoundItemInfo(notEmptyItem);
                            var barcodeInfo = barcodesToCheck.FirstOrDefault(b => b.Barcode == notEmptyItem.Barcode);
                            if (barcodeInfo != null)
                            {
                                foundItem.StyleString       = barcodeInfo.StyleString;
                                foundItem.StyleSize         = barcodeInfo.StyleSize;
                                foundItem.RemainingQuantity = barcodeInfo.RemainingQuantity;
                            }
                            results.Add(foundItem);
                        }
                    }

                    index += step;
                }
            }

            var filename = "BarcodesExistOnAmazon_" + DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss") + ".xls";
            var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);

            ExportFoundItem(results, filepath);
        }
Example #6
0
        public void BuildReportMissingSizesOnAmazon()
        {
            List <string> asinWithErrors;

            //var amazonParentItem = _amazonApi.GetItems(_log, _time, new List<string>() { "B01NCKLUGM" }, ItemFillMode.Defualt, out asinWithErrors);

            using (var db = _dbFactory.GetRWDb())
            {
                var allParentItems = db.ParentItems
                                     .GetAllAsDto(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId)
                                     .Where(pi => !String.IsNullOrEmpty(pi.ASIN))
                                     .ToList();
                var allChildItems = db.Items.GetAllViewAsDto(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId).ToList();

                var allSizesQuery = from s in db.Styles.GetAll()
                                    join si in db.StyleItems.GetAll() on s.Id equals si.StyleId
                                    join sic in db.StyleItemCaches.GetAll() on si.Id equals sic.Id
                                    where !s.Deleted &&
                                    sic.RemainingQuantity > 0
                                    select new
                {
                    StyleId           = s.Id,
                    StyleString       = s.StyleID,
                    StyleItemId       = si.Id,
                    StyleSize         = si.Size,
                    RemainingQuantity = sic.RemainingQuantity,
                };

                var allStyleSizes = allSizesQuery.ToList();

                var results = new List <ItemDTO>();

                foreach (var parentItem in allParentItems)
                {
                    var childItems                = allChildItems.Where(ch => ch.ParentASIN == parentItem.ASIN).ToList();
                    var parentItemStyleIdList     = childItems.Where(ch => ch.StyleId.HasValue).Select(ch => ch.StyleId.Value).ToList();
                    var parentItemStyleItemIdList = childItems.Where(ch => ch.StyleItemId.HasValue).Select(ch => ch.StyleItemId.Value).ToList();
                    var styleStyleItemList        = allStyleSizes.Where(si => parentItemStyleIdList.Contains(si.StyleId)).ToList();

                    var missingStyleItemList = styleStyleItemList.Where(si => !parentItemStyleItemIdList.Contains(si.StyleItemId)).ToList();

                    if (missingStyleItemList.Any())
                    {
                        _log.Info(parentItem.ASIN + " may has missing sizes");

                        var amazonParentItem = RetryHelper.ActionWithRetries(() =>
                                                                             _amazonApi.GetProductForASIN(new List <string>()
                        {
                            parentItem.ASIN
                        }).FirstOrDefault(),
                                                                             _log,
                                                                             3,
                                                                             5000,
                                                                             RetryModeType.Normal);

                        if (amazonParentItem != null && amazonParentItem.Listings != null)
                        {
                            var amazonChildItems = amazonParentItem.Listings;
                            foreach (var missingStyleItem in missingStyleItemList)
                            {
                                var possibleSizes = db.SizeMappings.GetAllAsDto()
                                                    .Where(m => m.StyleSize == missingStyleItem.StyleSize)
                                                    .ToList();
                                possibleSizes.Insert(0, new SizeMappingDTO()
                                {
                                    StyleSize = missingStyleItem.StyleSize,
                                    ItemSize  = missingStyleItem.StyleSize
                                });

                                ListingDTO existChildItem  = null;
                                var        existChildItems = amazonChildItems.Where(ai => possibleSizes.Any(s => s.ItemSize == ai.ListingSize)).ToList();
                                if (existChildItems.Any() && existChildItems.All(ch => !String.IsNullOrEmpty(ch.ListingColor)))
                                {
                                    var missingStyleItemColor = childItems.FirstOrDefault(ch => ch.StyleId == missingStyleItem.StyleId)?.Color;
                                    existChildItems = existChildItems.Where(ch => ch.ListingColor == missingStyleItemColor).ToList();
                                }
                                existChildItem = existChildItems.FirstOrDefault();
                                if (existChildItem != null)
                                {
                                    _log.Info("Added ParentASIN=" + parentItem.ASIN
                                              + ", styleId=" + missingStyleItem.StyleString
                                              + ", size=" + missingStyleItem.StyleSize);
                                    results.Add(new ItemDTO()
                                    {
                                        ParentASIN      = parentItem.ASIN,
                                        ASIN            = existChildItem.ASIN,
                                        Size            = existChildItem.ListingSize,
                                        Color           = existChildItem.ListingColor,
                                        SourceMarketUrl = "https://www.amazon.com/dp/" + existChildItem.ASIN,

                                        StyleString       = missingStyleItem.StyleString,
                                        StyleSize         = missingStyleItem.StyleSize,
                                        RemainingQuantity = missingStyleItem.RemainingQuantity
                                    });
                                }
                            }
                        }
                    }
                }

                _log.Info("Listings with possible missing sizes: " + results.Count);

                var filename = "MissingItemsOnAmazon_" + DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss") + ".xls";
                var filepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filename);
                ExportMissingItem(results, filepath);
            }
        }
        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()
                    }
                });
            }
        }