Exemplo n.º 1
0
        public void getAmazonJPProductsDetail(string ItemCode, int SearchQuantity = 1, Guid?StoregeJPId = null)
        {
            SearchProductInfo item = new SearchProductInfo();

            try
            {
                AmazonUtils util   = new AmazonUtils();
                Item        result = util.Detail(ItemCode);

                string strPrice = result.OfferSummary?.LowestNewPrice?.FormattedPrice;
                strPrice = Regex.Matches(strPrice, @"[0-9]*[\.,]?[0-9]+")[0].Value;
                double price = Convert.ToDouble(strPrice);

                item = new SearchProductInfo()
                {
                    JanCode     = result.ASIN,
                    Image       = result.LargeImage != null?result.LargeImage.URL:result.MediumImage.URL,
                    LinkWeb     = result.DetailPageURL,
                    NameJP      = result.ItemAttributes.Title,
                    NameEN      = TranslateUtils.TranslateGoogleTextEN(result.ItemAttributes.Title),
                    PriceTax    = price,
                    Quantity    = SearchQuantity,
                    Amount      = price * SearchQuantity,
                    ProductCode = result.ASIN,
                    Notes       = "",
                    Material    = "",
                    MadeIn      = "Japan",
                };
                SearchAndSave(item, ItemCode, SearchQuantity, StoregeJPId);
            }
            catch (Exception ex) { throw new Exception(ex.Message, ex); }
        }
Exemplo n.º 2
0
        public override string ProcessFormString(Order order, PaymentService.PageWithPaymentButton page)
        {
            var gatewayUrl = new Uri(Url);
            var sum        = String.Format(CultureInfo.InvariantCulture, "USD {0:0.00}", order.Sum);
            var pars       = new Dictionary <string, string>
            {
                { "immediateReturn", "1" },
                { "signatureVersion", "2" },
                { "signatureMethod", "HmacSHA256" },
                { "accessKey", AccessKey },
                { "amount", sum },
                { "description", Configuration.SettingsMain.ShopName },
                // {"amazonPaymentsAccountId", AccountId},
                { "returnUrl", SuccessUrl },
                { "referenceId", order.OrderID.ToString() }
            };

            pars.Add("signature", AmazonUtils.SignParameters(pars, SecretKey, "POST", gatewayUrl.Host, gatewayUrl.AbsolutePath));
            return(new PaymentFormHandler
            {
                Url = Url,
                InputValues = pars,
                Page = page
            }.ProcessRequest());
        }
Exemplo n.º 3
0
        public void Write(DateTime date)
        {
            DoValidation(Condition.Value);
            PutNewline();


            Put(AmazonUtils.ConvertToUnixEpochMilliSeconds(date).ToString(CultureInfo.InvariantCulture));

            context.ExpectingValue = false;
        }
Exemplo n.º 4
0
        //private IList<ItemBuyBoxResponse> RequestItemsBuyBoxByAdv(ILogService logger, IList<Item> items, AmazonApi api)
        //{
        //    var results = new List<ItemBuyBoxResponse>();
        //    var index = 0;
        //    //var indexToSleep = 0;
        //    while (index < items.Count)
        //    {
        //        var checkedItems = items.Skip(index).Take(10).ToList();
        //        var resp = RetryHelper.ActionWithRetries(() =>
        //            api.RetrieveOffersWithMerchant(logger, checkedItems.Select(i => i.ASIN).ToList()),
        //            logger);
        //        if (resp != null && resp.Items != null && resp.Items.Any() && resp.Items[0].Item != null)
        //        {
        //            foreach (var item in checkedItems)
        //            {
        //                var status = BuyBoxStatusCode.Undefined;
        //                decimal? price = null;
        //                decimal? salePrice = null;
        //                decimal? amountSaved = null;
        //                string merchantName = null;
        //                var el = resp.Items[0].Item.FirstOrDefault(i => i.ASIN == item.ASIN);
        //                if (el != null && el.Offers != null)
        //                {
        //                    if (el != null && el.Offers != null && el.Offers.Offer != null)
        //                    {
        //                        var itemId = item.Id;
        //                        var firstOffer = el.Offers.Offer.FirstOrDefault();
        //                        if (firstOffer != null)
        //                        {
        //                            merchantName = firstOffer.Merchant.Name;
        //                            if (String.IsNullOrEmpty(merchantName))
        //                            {
        //                                status = BuyBoxStatusCode.NoWinner;
        //                            }
        //                            else
        //                            {
        //                                status = (merchantName == AddressService.Name)
        //                                    ? BuyBoxStatusCode.Win
        //                                    : BuyBoxStatusCode.NotWin;
        //                            }

        //                            if (firstOffer.OfferListing != null && firstOffer.OfferListing.Length > 0)
        //                            {
        //                                //Note: firstOffer.OfferListing[0].Price.Amount stored price in "1499" format without any separators
        //                                if (firstOffer.OfferListing[0].Price != null)
        //                                {
        //                                    price = StringHelper.TryGetInt(firstOffer.OfferListing[0].Price.Amount);
        //                                    if (price != null)
        //                                        price = price/100;
        //                                }

        //                                if (firstOffer.OfferListing[0].SalePrice != null)
        //                                {
        //                                    salePrice = StringHelper.TryGetInt(firstOffer.OfferListing[0].SalePrice.Amount);
        //                                    if (salePrice != null)
        //                                        salePrice = salePrice/100;
        //                                }

        //                                if (firstOffer.OfferListing[0].AmountSaved != null)
        //                                {
        //                                    amountSaved = StringHelper.TryGetInt(firstOffer.OfferListing[0].AmountSaved.Amount);
        //                                    if (amountSaved != null)
        //                                        amountSaved = amountSaved/100;
        //                                }
        //                            }
        //                        }
        //                    }
        //                }
        //                results.Add(new ItemBuyBoxResponse()
        //                {
        //                    ASIN = item.ASIN,
        //                    CheckedDate = DateTime.UtcNow,
        //                    Status = status,
        //                    WinnerPrice = price,
        //                    WinnerSalePrice = salePrice,
        //                    WinnerAmountSaved = amountSaved,
        //                    WinnerMerchantName = merchantName
        //                });
        //            }
        //        }
        //        index += 10;

        //        Thread.Sleep(TimeSpan.FromSeconds(5));
        //    }
        //    return results;
        //}


        public int ProcessOfferChanges(AmazonSQSReader reader, IList <string> sellerIds)
        {
            var index             = 0;
            var maxCount          = 100;
            var existNotification = true;

            using (var db = _dbFactory.GetRWDb())
            {
                while (index < maxCount &&
                       existNotification)
                {
                    var notifications = reader.GetNotification();
                    existNotification = notifications.Any();

                    _log.Info("Receive notifications, count=" + notifications.Count);

                    foreach (var n in notifications)
                    {
                        try
                        {
                            var changeDate =
                                AmazonSQSReader.TryGetDate(
                                    n.NotificationPayload.AnyOfferChangedNotification.OfferChangeTrigger
                                    .TimeOfOfferChange);
                            if (!changeDate.HasValue)
                            {
                                throw new ArgumentNullException("ChangeDate");
                            }

                            _log.Info("Notification change date=" + changeDate);

                            LowestPrice buyBoxPrice          = null;
                            OfferCount  buyBoxAmazonOffers   = null;
                            OfferCount  buyBoxMerchantOffers = null;
                            LowestPrice merchantLowestPrices = null;
                            LowestPrice amazonLowestPrices   = null;
                            OfferCount  merchantOffers       = null;
                            OfferCount  amazonOffers         = null;

                            if (n.NotificationPayload.AnyOfferChangedNotification != null &&
                                n.NotificationPayload.AnyOfferChangedNotification.Summary != null)
                            {
                                if (n.NotificationPayload.AnyOfferChangedNotification.Summary.BuyBoxPrices != null)
                                {
                                    buyBoxPrice = n.NotificationPayload.AnyOfferChangedNotification.Summary.BuyBoxPrices
                                                  .FirstOrDefault(
                                        b => b.Condition == "new");
                                }

                                if (n.NotificationPayload.AnyOfferChangedNotification.Summary.BuyBoxEligibleOffers !=
                                    null)
                                {
                                    buyBoxAmazonOffers = n.NotificationPayload.AnyOfferChangedNotification.Summary
                                                         .BuyBoxEligibleOffers
                                                         .FirstOrDefault(o => o.FulfillmentChannel == "Amazon" && o.Condition == "new");
                                    buyBoxMerchantOffers =
                                        n.NotificationPayload.AnyOfferChangedNotification.Summary.BuyBoxEligibleOffers
                                        .FirstOrDefault(
                                            o => o.FulfillmentChannel == "Merchant" && o.Condition == "new");
                                }

                                if (n.NotificationPayload.AnyOfferChangedNotification.Summary.OfferCounts != null)
                                {
                                    amazonOffers = n.NotificationPayload.AnyOfferChangedNotification.Summary.OfferCounts
                                                   .FirstOrDefault(o => o.FulfillmentChannel == "Amazon" && o.Condition == "new");
                                    merchantOffers = n.NotificationPayload.AnyOfferChangedNotification.Summary
                                                     .OfferCounts
                                                     .FirstOrDefault(o => o.FulfillmentChannel == "Merchant" && o.Condition == "new");
                                }

                                if (n.NotificationPayload.AnyOfferChangedNotification.Summary.LowestPrices != null)
                                {
                                    amazonLowestPrices = n.NotificationPayload.AnyOfferChangedNotification.Summary
                                                         .LowestPrices
                                                         .FirstOrDefault(
                                        p => p.FulfillmentChannel == "Amazon" &&
                                        p.Condition == "new");

                                    merchantLowestPrices = n.NotificationPayload.AnyOfferChangedNotification.Summary
                                                           .LowestPrices.FirstOrDefault(
                                        p => p.FulfillmentChannel == "Merchant" &&
                                        p.Condition == "new");
                                }
                            }

                            var offerChangeEvent = new OfferChangeEvent()
                            {
                                ASIN          = n.NotificationPayload.AnyOfferChangedNotification.OfferChangeTrigger.ASIN,
                                MarketplaceId =
                                    n.NotificationPayload.AnyOfferChangedNotification.OfferChangeTrigger.MarketplaceId,
                                ChangeDate = changeDate.Value,

                                BuyBoxLandedPrice = buyBoxPrice != null && buyBoxPrice.LandedPrice != null
                                        ? decimal.Parse(buyBoxPrice.LandedPrice.Amount)
                                        : (decimal?)null,
                                BuyBoxListingPrice = buyBoxPrice != null && buyBoxPrice.ListingPrice != null
                                        ? decimal.Parse(buyBoxPrice.ListingPrice.Amount)
                                        : (decimal?)null,
                                BuyBoxShipping = buyBoxPrice != null && buyBoxPrice.Shipping != null
                                        ? decimal.Parse(buyBoxPrice.Shipping.Amount)
                                        : (decimal?)null,
                                BuyBoxEligibleOffersAmazon =
                                    buyBoxAmazonOffers != null
                                        ? AmazonSQSReader.TryGetInt(buyBoxAmazonOffers.Value)
                                        : (int?)null,
                                BuyBoxEligibleOffersMerchant =
                                    buyBoxMerchantOffers != null
                                        ? AmazonSQSReader.TryGetInt(buyBoxMerchantOffers.Value)
                                        : (int?)null,

                                ListPrice =
                                    AmazonSQSReader.GetPrice(
                                        n.NotificationPayload.AnyOfferChangedNotification.Summary.ListPrice),
                                LowestLandedPriceAmazon =
                                    amazonLowestPrices != null
                                        ? AmazonSQSReader.GetPrice(amazonLowestPrices.LandedPrice)
                                        : null,
                                LowestListingPriceAmazon =
                                    amazonLowestPrices != null
                                        ? AmazonSQSReader.GetPrice(amazonLowestPrices.ListingPrice)
                                        : null,
                                LowestShippingAmazon =
                                    amazonLowestPrices != null
                                        ? AmazonSQSReader.GetPrice(amazonLowestPrices.Shipping)
                                        : null,

                                LowestLandedPriceMerchant =
                                    merchantLowestPrices != null
                                        ? AmazonSQSReader.GetPrice(merchantLowestPrices.LandedPrice)
                                        : null,
                                LowestListingPriceMerchant =
                                    merchantLowestPrices != null
                                        ? AmazonSQSReader.GetPrice(merchantLowestPrices.ListingPrice)
                                        : null,
                                LowestShippingMerchant =
                                    merchantLowestPrices != null
                                        ? AmazonSQSReader.GetPrice(merchantLowestPrices.Shipping)
                                        : null,

                                NumberOfOffersAmazon =
                                    amazonOffers != null?AmazonSQSReader.TryGetInt(amazonOffers.Value) : (int?)null,
                                        NumberOfOffersMerchant =
                                            merchantOffers != null
                                        ? AmazonSQSReader.TryGetInt(merchantOffers.Value)
                                        : (int?)null,

                                        CreateDate = _time.GetAppNowTime(),
                            };

                            db.OfferChangeEvents.Add(offerChangeEvent);
                            db.Commit();

                            var offers = new List <OfferInfo>();
                            foreach (var offer in n.NotificationPayload.AnyOfferChangedNotification.Offers)
                            {
                                var newOffer = new OfferInfo()
                                {
                                    OfferChangeEventId = offerChangeEvent.Id,

                                    IsBuyBoxWinner      = offer.IsBuyBoxWinner,
                                    IsFeaturedMerchant  = offer.IsFeaturedMerchant,
                                    IsFulfilledByAmazon = offer.IsFulfilledByAmazon,
                                    ShipsDomestically   = offer.ShipsDomestically,

                                    SellerId      = offer.SellerId,
                                    FeedbackCount =
                                        offer.SellerFeedbackRating != null
                                            ? AmazonSQSReader.TryGetInt(offer.SellerFeedbackRating.FeedbackCount)
                                            : null,
                                    SellerPositiveFeedbackRating =
                                        offer.SellerFeedbackRating != null
                                            ? AmazonSQSReader.TryGetInt(
                                            offer.SellerFeedbackRating.SellerPositiveFeedbackRating)
                                            : null,

                                    ListingPrice = AmazonSQSReader.GetPrice(offer.ListingPrice),
                                    Shipping     = AmazonSQSReader.GetPrice(offer.Shipping),

                                    ShippingTimeMaximumHours =
                                        AmazonSQSReader.TryGetInt(offer.ShippingTime.MaximumHours),
                                    ShippingTimeMinimumHours =
                                        AmazonSQSReader.TryGetInt(offer.ShippingTime.MinimumHours),
                                    ShippingTimeAvailabilityType = offer.ShippingTime.AvailabilityType,

                                    ShipsFromCountry = offer.ShipsFrom != null ? offer.ShipsFrom.Country : null,
                                    ShipsFromState   = offer.ShipsFrom != null ? offer.ShipsFrom.State : null,

                                    CreateDate = _time.GetAppNowTime(),
                                };

                                db.OfferInfoes.Add(newOffer);
                                offers.Add(newOffer);
                            }
                            db.Commit();

                            //Update buybox
                            BuyBoxStatusCode status = BuyBoxStatusCode.NoWinner;
                            var winOffer            = offers.FirstOrDefault(o => o.IsBuyBoxWinner);
                            if (winOffer != null)
                            {
                                if (sellerIds.Contains(winOffer.SellerId))
                                {
                                    status = BuyBoxStatusCode.Win;
                                }
                                else
                                {
                                    status = BuyBoxStatusCode.NotWin;
                                }
                            }

                            db.BuyBoxStatus.Update(_log,
                                                   _time,
                                                   new BuyBoxStatusDTO()
                            {
                                ASIN          = offerChangeEvent.ASIN,
                                MarketplaceId = offerChangeEvent.MarketplaceId,
                                CheckedDate   = offerChangeEvent.ChangeDate,
                                WinnerPrice   = offerChangeEvent.BuyBoxListingPrice,

                                Status = status,
                            },
                                                   AmazonUtils.GetMarketByMarketplaceId(offerChangeEvent.MarketplaceId),
                                                   offerChangeEvent.MarketplaceId);
                        }
                        catch (Exception ex)
                        {
                            _log.Info("Process notification", ex);
                        }
                    }
                    index++;
                }
            }

            return(index);
        }
Exemplo n.º 5
0
        public static string GetMarketUrl(string asin, MarketType market, string marketplaceId)
        {
            if (String.IsNullOrEmpty(asin))
            {
                return(String.Empty);
            }

            if (market == MarketType.Amazon ||
                market == MarketType.AmazonEU ||
                market == MarketType.AmazonAU)
            {
                return(AmazonUtils.GetProductMarketUrl(asin, market, marketplaceId));
            }

            if (market == MarketType.eBay)
            {
                var parts = asin.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length > 0)
                {
                    return("http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&amp;rd=1&amp;item=" + parts[0]);
                }
            }

            if (market == MarketType.Magento)
            {
                //http://www.premiumapparel.com/index.php/catalog/product/view/id/40
                return("http://www.premiumapparel.com/index.php/catalog/product/view/id/" + asin);
            }

            if (market == MarketType.Walmart)
            {
                return(String.Format("https://www.walmart.com/ip/item/{0}", asin)); //?portalSelectedSellerId=bf505621-095c-4d24-ab6c-e285e41a4151
            }

            if (market == MarketType.WalmartCA)
            {
                return(String.Format("https://www.walmart.ca/ip/item/{0}", asin)); //?portalSelectedSellerId=bf505621-095c-4d24-ab6c-e285e41a4151
            }

            if (market == MarketType.Shopify)
            {
                return("");
            }

            if (market == MarketType.WooCommerce)
            {
                return("");
            }

            if (market == MarketType.Groupon)
            {
                return("");
            }

            if (market == MarketType.OverStock)
            {
                return("https://www.overstock.com/" + asin + "/product.html");
            }

            if (market == MarketType.Jet)
            {
                return("");
            }

            return("");
        }