Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
abuzuhri committed Jan 20, 2025
2 parents eb60796 + b33b533 commit 23686f6
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 11 deletions.
60 changes: 53 additions & 7 deletions Source/FikaAmazonAPI.SampleCode/FeedsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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<PriceMessage>();
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();
Expand All @@ -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")
Expand Down Expand Up @@ -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");
Expand All @@ -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()
{
Expand All @@ -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
}
}
});
Expand Down
83 changes: 83 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/ConstructJSONFeedService.cs
Original file line number Diff line number Diff line change
@@ -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<PriceMessage> messages)
{
int index = jsonMessagesData.messages.Count;
foreach (var itm in messages)
{
var patcheValueData = new PatcheValueData()
{
currency = itm.StandardPrice.currency,
our_price = new List<PriceData>()
{
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.StandardPrice.Value } } }
},
};

if (itm.MinimumSellerAllowedPrice != null)
{
patcheValueData.minimum_seller_allowed_price = new List<PriceData>()
{
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.MinimumSellerAllowedPrice.Value } } }
};
}

if (itm.MaximumSellerAllowedPrice != null)
{
patcheValueData.maximum_seller_allowed_price = new List<PriceData>()
{
new PriceData(){ schedule = new List<SchedulePriceData>(){ new SchedulePriceData() { value_with_tax= itm.MaximumSellerAllowedPrice.Value } } }
};
}

var msg = new MessagesData()
{
messageId = ++index,
sku = itm.SKU,
operationType = "PATCH",
productType = "PRODUCT",
patches = new List<PatcheData>{
new PatcheData()
{
op = "replace",
path = "/attributes/purchasable_offer",
value =new List<PatcheValueData>{ patcheValueData }
}
}
};

jsonMessagesData.messages.Add(msg);
}
}

public string GetJSON()
{
string jsonString = JsonConvert.SerializeObject(jsonMessagesData, Formatting.Indented, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});

return jsonString;
}
}
}
10 changes: 10 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/HeaderData.cs
Original file line number Diff line number Diff line change
@@ -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; }

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;

namespace FikaAmazonAPI.ConstructFeed.JsonMessages
{
public class JsonMessagesData
{
public HeaderData header { get; set; }
public IList<MessagesData> messages { get; set; } = new List<MessagesData>();
}
}
15 changes: 15 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/MessagesData.cs
Original file line number Diff line number Diff line change
@@ -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<PatcheData> patches { get; set; }
//public IList<attributes> attributes { get; set; }

}
}
11 changes: 11 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheData.cs
Original file line number Diff line number Diff line change
@@ -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<PatcheValueData> value { get; set; }
}
}
18 changes: 18 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PatcheValueData.cs
Original file line number Diff line number Diff line change
@@ -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<PriceData> our_price { get; set; }
public IList<PriceData> minimum_seller_allowed_price { get; set; }
public IList<PriceData> maximum_seller_allowed_price { get; set; }
}
}
13 changes: 13 additions & 0 deletions Source/FikaAmazonAPI/ConstructFeed/JsonMessages/PriceData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace FikaAmazonAPI.ConstructFeed.JsonMessages
{
public class PriceData
{
public IList<SchedulePriceData> schedule { get; set; }
}
public class SchedulePriceData
{
public decimal value_with_tax { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand Down
6 changes: 3 additions & 3 deletions Source/FikaAmazonAPI/FikaAmazonAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<Product>CSharp Amazon Sp API</Product>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<LangVersion>8.0</LangVersion>
<Version>1.7.35</Version>
<AssemblyVersion>1.7.35</AssemblyVersion>
<FileVersion>1.7.35</FileVersion>
<Version>1.7.36</Version>
<AssemblyVersion>1.7.36</AssemblyVersion>
<FileVersion>1.7.36</FileVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/abuzuhri/Amazon-SP-API-CSharp</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down

0 comments on commit 23686f6

Please sign in to comment.