diff --git a/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs b/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs index 8e23a823..f764d778 100644 --- a/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs +++ b/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs @@ -155,7 +155,7 @@ public void AddOfferMessageMessage() GetFeedDetails(feedID); } - public void SubmitFeedPRICING(double PRICE, string SKU) + public void SubmitFeedPRICING(decimal PRICE, string SKU) { ConstructFeedService createDocument = new ConstructFeedService(amazonConnection.GetCurrentSellerID, "1.02"); @@ -167,7 +167,7 @@ public void SubmitFeedPRICING(double PRICE, string SKU) StandardPrice = new StandardPrice() { currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(), - Value = (PRICE).ToString("0.00") + Value = decimal.Round(PRICE, 2) } }); createDocument.AddPriceMessage(list); @@ -180,6 +180,52 @@ public void SubmitFeedPRICING(double PRICE, string SKU) } + public async Task SubmitFeedPRICING_JSONAsync(string SKU, decimal PRICE, decimal? minPrice = null, decimal? maxPrice = null) + { + ConstructJSONFeedService createDocument = new ConstructJSONFeedService(amazonConnection.GetCurrentSellerID); + + var list = new List(); + var msg = new PriceMessage() + { + SKU = SKU, + StandardPrice = new StandardPrice() + { + currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(), + Value = decimal.Round(PRICE, 2) + } + }; + + if (maxPrice != null) + { + msg.MaximumSellerAllowedPrice = new StandardPrice() + { + currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(), + Value = decimal.Round(maxPrice.Value, 2) + }; + } + + if (minPrice != null) + { + msg.MinimumSellerAllowedPrice = new StandardPrice() + { + currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(), + Value = decimal.Round(minPrice.Value, 2) + }; + } + + + list.Add(msg); + createDocument.AddPriceMessage(list); + + var jsonString = createDocument.GetJSON(); + + string feedID = await amazonConnection.Feed.SubmitFeedAsync(jsonString, FeedType.JSON_LISTINGS_FEED, null, null, ContentType.JSON); + + + await GetJsonFeedDetails(feedID); + + } + public async Task SubmitFeedPricingWithSalePrice(string sku, decimal price, decimal salePrice, DateTime startDate, DateTime endDate) { var currencyCode = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(); @@ -193,14 +239,14 @@ public async Task SubmitFeedPricingWithSalePrice(string sku, decimal price, deci StandardPrice = new StandardPrice { currency = currencyCode, - Value = price.ToString("0.00") + Value = decimal.Round(price, 2) }, Sale = new Sale { SalePrice = new StandardPrice { currency = currencyCode, - Value = salePrice.ToString("0.00") + Value = decimal.Round(salePrice, 2) }, StartDate = startDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK"), EndDate = endDate.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffK") @@ -260,7 +306,7 @@ public async Task SubmitJsonFeedPricing(string sku, decimal price) } - public void SubmitFeedSale(double PRICE, string SKU) + public void SubmitFeedSale(decimal PRICE, string SKU) { ConstructFeedService createDocument = new ConstructFeedService("A3J37AJU4O9RHK", "1.02"); @@ -272,7 +318,7 @@ public void SubmitFeedSale(double PRICE, string SKU) StandardPrice = new StandardPrice() { currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(), - Value = (PRICE).ToString("0.00") + Value = decimal.Round(PRICE, 2) //(PRICE).ToString("0.00") }, Sale = new Sale() { @@ -281,7 +327,7 @@ public void SubmitFeedSale(double PRICE, string SKU) SalePrice = new StandardPrice() { currency = amazonConnection.GetCurrentMarketplace.CurrencyCode.ToString(), - Value = (PRICE - 10).ToString("0.00") + Value = decimal.Round(PRICE, 2) - 10 } } }); diff --git a/Source/FikaAmazonAPI.SampleCode/Program.cs b/Source/FikaAmazonAPI.SampleCode/Program.cs index 1af6ad1e..8597fa8f 100644 --- a/Source/FikaAmazonAPI.SampleCode/Program.cs +++ b/Source/FikaAmazonAPI.SampleCode/Program.cs @@ -25,15 +25,9 @@ static async Task Main(string[] args) IsDebugMode = true }, loggerFactory: factory); + FeedsSample feedsSample = new FeedsSample(amazonConnection); + feedsSample.SubmitFeedPRICING_JSONAsync("B087YHP3HQ.151", 131.77M, 67.70M, 131.77M); - ReportManagerSample reportManagerSample = new ReportManagerSample(amazonConnection); - reportManagerSample.CallReport(); - //var error = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_STRANDED_INVENTORY_UI_DATA); - //var dddd = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_FBA_MYI_ALL_INVENTORY_DATA); - //var dddd = amazonConnection.Reports.CreateReportAndDownloadFile(Utils.Constants.ReportTypes.GET_FBA_MYI_UNSUPPRESSED_INVENTORY_DATA); - //ReportManager reportManager = new ReportManager(amazonConnection); - - //var dddddd = reportManager.GetAFNInventoryQtyAsync().ConfigureAwait(false).GetAwaiter().GetResult(); Console.ReadLine(); diff --git a/Source/FikaAmazonAPI/ConstructFeed/ConstructJSONFeedService.cs b/Source/FikaAmazonAPI/ConstructFeed/ConstructJSONFeedService.cs new file mode 100644 index 00000000..f316fed2 --- /dev/null +++ b/Source/FikaAmazonAPI/ConstructFeed/ConstructJSONFeedService.cs @@ -0,0 +1,83 @@ +using FikaAmazonAPI.ConstructFeed.JsonMessages; +using FikaAmazonAPI.ConstructFeed.Messages; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace FikaAmazonAPI.ConstructFeed +{ + public class ConstructJSONFeedService + { + JsonMessagesData jsonMessagesData = new JsonMessagesData(); + public ConstructJSONFeedService(string sellerId, string version = "2.0", string issueLocale = "en_US") + { + jsonMessagesData.header = new HeaderData() + { + issueLocale = issueLocale, + sellerId = sellerId, + version = version + }; + + } + + + public void AddPriceMessage(IList messages) + { + int index = jsonMessagesData.messages.Count; + foreach (var itm in messages) + { + var patcheValueData = new PatcheValueData() + { + currency = itm.StandardPrice.currency, + our_price = new List() + { + new PriceData(){ schedule = new List(){ new SchedulePriceData() { value_with_tax= itm.StandardPrice.Value } } } + }, + }; + + if (itm.MinimumSellerAllowedPrice != null) + { + patcheValueData.minimum_seller_allowed_price = new List() + { + new PriceData(){ schedule = new List(){ new SchedulePriceData() { value_with_tax= itm.MinimumSellerAllowedPrice.Value } } } + }; + } + + if (itm.MaximumSellerAllowedPrice != null) + { + patcheValueData.maximum_seller_allowed_price = new List() + { + new PriceData(){ schedule = new List(){ new SchedulePriceData() { value_with_tax= itm.MaximumSellerAllowedPrice.Value } } } + }; + } + + var msg = new MessagesData() + { + messageId = ++index, + sku = itm.SKU, + operationType = "PATCH", + productType = "PRODUCT", + patches = new List{ + new PatcheData() + { + op = "replace", + path = "/attributes/purchasable_offer", + value =new List{ patcheValueData } + } + } + }; + + jsonMessagesData.messages.Add(msg); + } + } + + public string GetJSON() + { + string jsonString = JsonConvert.SerializeObject(jsonMessagesData, Formatting.Indented, new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore + }); + + return jsonString; + } + } +} diff --git a/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/HeaderData.cs b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/HeaderData.cs new file mode 100644 index 00000000..505b13cb --- /dev/null +++ b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/HeaderData.cs @@ -0,0 +1,10 @@ +namespace FikaAmazonAPI.ConstructFeed.JsonMessages +{ + public class HeaderData + { + public string sellerId { get; set; } + public string version { get; set; } + public string issueLocale { get; set; } + + } +} diff --git a/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/JsonMessagesData.cs b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/JsonMessagesData.cs new file mode 100644 index 00000000..fe1dd686 --- /dev/null +++ b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/JsonMessagesData.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace FikaAmazonAPI.ConstructFeed.JsonMessages +{ + public class JsonMessagesData + { + public HeaderData header { get; set; } + public IList messages { get; set; } = new List(); + } +} diff --git a/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/MessagesData.cs b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/MessagesData.cs new file mode 100644 index 00000000..67b0ddab --- /dev/null +++ b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/MessagesData.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace FikaAmazonAPI.ConstructFeed.JsonMessages +{ + public class MessagesData + { + public int messageId { get; set; } + public string sku { get; set; } + public string operationType { get; set; } + public string productType { get; set; } + public IList patches { get; set; } + //public IList attributes { get; set; } + + } +} diff --git a/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheData.cs b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheData.cs new file mode 100644 index 00000000..fb088f3f --- /dev/null +++ b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheData.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace FikaAmazonAPI.ConstructFeed.JsonMessages +{ + public class PatcheData + { + public string op { get; set; } + public string path { get; set; } + public IList value { get; set; } + } +} diff --git a/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheValueData.cs b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheValueData.cs new file mode 100644 index 00000000..491ce44e --- /dev/null +++ b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheValueData.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace FikaAmazonAPI.ConstructFeed.JsonMessages +{ + public class PatcheValueData + { + public string value { get; set; } + public string language_tag { get; set; } + public string marketplace_id { get; set; } + public string fulfillment_channel_code { get; set; } + public int? quantity { get; set; } + public int? lead_time_to_ship_max_days { get; set; } + public string currency { get; set; } + public IList our_price { get; set; } + public IList minimum_seller_allowed_price { get; set; } + public IList maximum_seller_allowed_price { get; set; } + } +} diff --git a/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PriceData.cs b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PriceData.cs new file mode 100644 index 00000000..f3bac771 --- /dev/null +++ b/Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PriceData.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace FikaAmazonAPI.ConstructFeed.JsonMessages +{ + public class PriceData + { + public IList schedule { get; set; } + } + public class SchedulePriceData + { + public decimal value_with_tax { get; set; } + } +} diff --git a/Source/FikaAmazonAPI/ConstructFeed/Messages/StandardPrice.cs b/Source/FikaAmazonAPI/ConstructFeed/Messages/StandardPrice.cs index 05946f84..2f6c5c68 100644 --- a/Source/FikaAmazonAPI/ConstructFeed/Messages/StandardPrice.cs +++ b/Source/FikaAmazonAPI/ConstructFeed/Messages/StandardPrice.cs @@ -5,7 +5,7 @@ namespace FikaAmazonAPI.ConstructFeed.Messages public class StandardPrice { [XmlText] - public string Value { get; set; } + public decimal Value { get; set; } [XmlAttribute] public string currency { get; set; } }