From a337326615d9255e7116ef4b4402b39bf7337513 Mon Sep 17 00:00:00 2001 From: Sruli Elias Date: Wed, 30 Aug 2023 12:02:31 -0400 Subject: [PATCH 1/3] Added details to AmazonInvalidInputException Added details to AmazonInvalidInputException --- .../AmazonSpApiSDK/Models/Exceptions/AmazonException.cs | 7 +++++-- Source/FikaAmazonAPI/Services/RequestService.cs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs index 494d9095..54b3b1ff 100644 --- a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs @@ -38,9 +38,12 @@ public AmazonUnauthorizedException(string msg, RestResponse response = null) : b public class AmazonInvalidInputException : AmazonException { - public AmazonInvalidInputException(string msg, RestResponse response = null) : base(msg, response) - { + public string Details { get; set; } + public AmazonInvalidInputException(string msg, string details = null, RestResponse response = null) : base(msg, response) + { + this.Details = details; + //this.Data["Details"] = details; } } public class AmazonQuotaExceededException : AmazonException diff --git a/Source/FikaAmazonAPI/Services/RequestService.cs b/Source/FikaAmazonAPI/Services/RequestService.cs index b9ab757d..a6c383f5 100644 --- a/Source/FikaAmazonAPI/Services/RequestService.cs +++ b/Source/FikaAmazonAPI/Services/RequestService.cs @@ -285,7 +285,7 @@ protected void ParseResponse(RestResponse response) case "InvalidSignature": throw new AmazonInvalidSignatureException(error.Message, response); case "InvalidInput": - throw new AmazonInvalidInputException(error.Message, response); + throw new AmazonInvalidInputException(error.Message, error.Details, response); case "QuotaExceeded": throw new AmazonQuotaExceededException(error.Message, response); case "InternalFailure": From 25776a2e7557b705de87dceada7234da2ad5e4e4 Mon Sep 17 00:00:00 2001 From: TManITtech <69358597+TManITtech@users.noreply.github.com> Date: Wed, 30 Aug 2023 12:10:31 -0400 Subject: [PATCH 2/3] Merge from original (#1) * Add Send Invoice method in Messaging API * change v1.7.2 * sample --------- Co-authored-by: Mehran Ahmadifar Co-authored-by: Poseur Co-authored-by: Tareq Abuzuhri Co-authored-by: Tareq Abuzuhri --- .../FikaAmazonAPI.SampleCode/FeedsSample.cs | 6 +- Source/FikaAmazonAPI.SampleCode/Program.cs | 32 ++++---- .../Models/Messaging/InvoiceRequest.cs | 70 ++++++++++++++++++ .../Models/Messaging/InvoiceResponse.cs | 74 +++++++++++++++++++ Source/FikaAmazonAPI/FikaAmazonAPI.csproj | 6 +- Source/FikaAmazonAPI/Services/ApiUrls.cs | 1 + .../Services/MessagingService.cs | 15 +++- 7 files changed, 182 insertions(+), 22 deletions(-) create mode 100644 Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Messaging/InvoiceRequest.cs create mode 100644 Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Messaging/InvoiceResponse.cs diff --git a/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs b/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs index 42ad184a..e580c94b 100644 --- a/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs +++ b/Source/FikaAmazonAPI.SampleCode/FeedsSample.cs @@ -155,10 +155,10 @@ public void AddOfferMessageMessage() GetFeedDetails(feedID); } - public async void SubmitFeedPRICING(double PRICE, string SKU) + public void SubmitFeedPRICING(double PRICE, string SKU) { - ConstructFeedService createDocument = new ConstructFeedService("A3J37AJU4O9RHK", "1.02"); + ConstructFeedService createDocument = new ConstructFeedService(amazonConnection.GetCurrentSellerID, "1.02"); var list = new List(); list.Add(new PriceMessage() @@ -174,7 +174,7 @@ public async void SubmitFeedPRICING(double PRICE, string SKU) var xml = createDocument.GetXML(); - var feedID = await amazonConnection.Feed.SubmitFeedAsync(xml, FeedType.POST_PRODUCT_PRICING_DATA); + var feedID = amazonConnection.Feed.SubmitFeed(xml, FeedType.POST_PRODUCT_PRICING_DATA); GetFeedDetails(feedID); diff --git a/Source/FikaAmazonAPI.SampleCode/Program.cs b/Source/FikaAmazonAPI.SampleCode/Program.cs index ec8b44c0..ddbb1b95 100644 --- a/Source/FikaAmazonAPI.SampleCode/Program.cs +++ b/Source/FikaAmazonAPI.SampleCode/Program.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Configuration; +using FikaAmazonAPI.Utils; +using Microsoft.Extensions.Configuration; using static FikaAmazonAPI.Utils.Constants; namespace FikaAmazonAPI.SampleCode @@ -27,22 +28,25 @@ static async Task Main(string[] args) IsDebugMode = true }); - var x = amazonConnection.CatalogItem.GetCatalogItem202204(new FikaAmazonAPI.Parameter.CatalogItems.ParameterGetCatalogItem() + + //FeedsSample feedsSample = new FeedsSample(amazonConnection); + //feedsSample.SubmitFeedPRICING(69.3F, "8809606851663"); + + var feeds = amazonConnection.Feed.GetFeeds(new Parameter.Feed.ParameterGetFeed() { - ASIN = "B01I3JW7PK", - includedData = new List { - IncludedData.summaries, - IncludedData.identifiers, - IncludedData.summaries, - IncludedData.productTypes, - IncludedData.dimensions, - IncludedData.images, - IncludedData.relationships, - IncludedData.attributes//, - - } + processingStatuses = ProcessingStatuses.IN_QUEUE, + pageSize = 100, + feedTypes = new List { FeedType.POST_PRODUCT_PRICING_DATA }, + marketplaceIds = new List { MarketPlace.UnitedArabEmirates.ID } }); + foreach (var feed in feeds) + { + Console.WriteLine("FeedId " + feed.FeedId); + //var result = amazonConnection.Feed.CancelFeed(feed.FeedId); + } + + Console.ReadLine(); diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Messaging/InvoiceRequest.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Messaging/InvoiceRequest.cs new file mode 100644 index 00000000..d97facc1 --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Messaging/InvoiceRequest.cs @@ -0,0 +1,70 @@ +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Messaging +{ + using System; + using System.Linq; + using System.Text; + using Newtonsoft.Json; + using System.Collections.Generic; + using System.Runtime.Serialization; + using System.ComponentModel.DataAnnotations; + + [DataContract] + public partial class InvoiceRequest : IEquatable, IValidatableObject + { + public InvoiceRequest(List attachments = default(List), DateTime? coverageStartDate = default(DateTime?), DateTime? coverageEndDate = default(DateTime?)) + { + this.Attachments = attachments; + } + + [DataMember(Name = "attachments", EmitDefaultValue = false)] + public List Attachments { get; set; } + + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class InvoiceRequest {\n"); + sb.Append(" Attachments: ").Append(Attachments).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + public virtual string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + public override bool Equals(object input) + { + return this.Equals(input as InvoiceRequest); + } + + public bool Equals(InvoiceRequest input) + { + if (input == null) + return false; + + return + ( + this.Attachments == input.Attachments || + this.Attachments != null && + this.Attachments.SequenceEqual(input.Attachments) + ); + } + + public override int GetHashCode() + { + unchecked // Overflow is fine, just wrap + { + int hashCode = 41; + if (this.Attachments != null) + hashCode = hashCode * 59 + this.Attachments.GetHashCode(); + return hashCode; + } + } + + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + yield break; + } + } +} \ No newline at end of file diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Messaging/InvoiceResponse.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Messaging/InvoiceResponse.cs new file mode 100644 index 00000000..30358cd9 --- /dev/null +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Messaging/InvoiceResponse.cs @@ -0,0 +1,74 @@ +namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Messaging +{ + using System; + using System.Text; + using Newtonsoft.Json; + using System.Collections.Generic; + using System.Runtime.Serialization; + using System.ComponentModel.DataAnnotations; + + [DataContract] + public partial class InvoiceResponse : IEquatable, IValidatableObject + { + public InvoiceResponse(ErrorList errors = default(ErrorList)) + { + this.Errors = errors; + } + + public InvoiceResponse() + { + this.Errors = default(ErrorList); + } + + [DataMember(Name = "errors", EmitDefaultValue = false)] + public ErrorList Errors { get; set; } + + public override string ToString() + { + var sb = new StringBuilder(); + sb.Append("class InvoiceResponse {\n"); + sb.Append(" Errors: ").Append(Errors).Append("\n"); + sb.Append("}\n"); + return sb.ToString(); + } + + public virtual string ToJson() + { + return JsonConvert.SerializeObject(this, Formatting.Indented); + } + + public override bool Equals(object input) + { + return this.Equals(input as InvoiceResponse); + } + + public bool Equals(InvoiceResponse input) + { + if (input == null) + return false; + + return + ( + this.Errors == input.Errors || + (this.Errors != null && + this.Errors.Equals(input.Errors)) + ); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = 41; + if (this.Errors != null) + hashCode = hashCode * 59 + this.Errors.GetHashCode(); + return hashCode; + } + } + + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + { + yield break; + } + } +} \ No newline at end of file diff --git a/Source/FikaAmazonAPI/FikaAmazonAPI.csproj b/Source/FikaAmazonAPI/FikaAmazonAPI.csproj index 602f3210..312cef41 100644 --- a/Source/FikaAmazonAPI/FikaAmazonAPI.csproj +++ b/Source/FikaAmazonAPI/FikaAmazonAPI.csproj @@ -7,9 +7,9 @@ CSharp Amazon Sp API true 8.0 - 1.7.1 - 1.7.1 - 1.7.1 + 1.7.2 + 1.7.2 + 1.7.2 true https://github.com/abuzuhri/Amazon-SP-API-CSharp MIT diff --git a/Source/FikaAmazonAPI/Services/ApiUrls.cs b/Source/FikaAmazonAPI/Services/ApiUrls.cs index 3d9e43b0..c9f590c8 100644 --- a/Source/FikaAmazonAPI/Services/ApiUrls.cs +++ b/Source/FikaAmazonAPI/Services/ApiUrls.cs @@ -177,6 +177,7 @@ protected class MessaginApiUrls public static string GetAttributes(string amazonOrderId) => $"{_resourceBaseUrl}/orders/{amazonOrderId}/attributes"; public static string CreateDigitalAccessKey(string amazonOrderId) => $"{_resourceBaseUrl}/orders/{amazonOrderId}/messages/digitalAccessKey"; public static string CreateUnexpectedProblem(string amazonOrderId) => $"{_resourceBaseUrl}/orders/{amazonOrderId}/messages/unexpectedProblem"; + public static string SendInvoice(string amazonOrderId) => $"{_resourceBaseUrl}/orders/{amazonOrderId}/messages/invoice"; } protected class EasyShip20220323 { diff --git a/Source/FikaAmazonAPI/Services/MessagingService.cs b/Source/FikaAmazonAPI/Services/MessagingService.cs index b9f00958..e3bedc41 100644 --- a/Source/FikaAmazonAPI/Services/MessagingService.cs +++ b/Source/FikaAmazonAPI/Services/MessagingService.cs @@ -194,7 +194,18 @@ public async Task CreateUnexpectedProblemAsync(string amazonOrderId, Creat return false; } + public bool SendInvoice(string amazonOrderId, InvoiceRequest invoiceRequest) => + Task.Run(() => SendInvoiceAsync(amazonOrderId, invoiceRequest)).ConfigureAwait(false).GetAwaiter().GetResult(); + public async Task SendInvoiceAsync(string amazonOrderId, InvoiceRequest invoiceRequest, CancellationToken cancellationToken = default) + { + List> queryParameters = new List>(); + queryParameters.Add(new KeyValuePair("marketplaceIds", AmazonCredential.MarketPlace.ID)); + await CreateAuthorizedRequestAsync(MessaginApiUrls.SendInvoice(amazonOrderId), RestSharp.Method.Post, queryParameters, postJsonObj: invoiceRequest, cancellationToken: cancellationToken); - + var response = await ExecuteRequestAsync(RateLimitType.Messaging_CreateUnexpectedProblem, cancellationToken); + if (response != null) + return true; + return false; + } } -} +} \ No newline at end of file From 6333337271672017d0c18e8939a9b56f05360c3e Mon Sep 17 00:00:00 2001 From: TManITtech Date: Thu, 28 Sep 2023 15:31:07 -0400 Subject: [PATCH 3/3] Added new field EventFilter.OrderChangeTypes --- .../AmazonSpApiSDK/Models/Exceptions/AmazonException.cs | 1 + .../AmazonSpApiSDK/Models/Notifications/EventFilter.cs | 8 ++++++++ Source/FikaAmazonAPI/FikaAmazonAPI.csproj | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs index 54b3b1ff..71157b6d 100644 --- a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Exceptions/AmazonException.cs @@ -46,6 +46,7 @@ public AmazonInvalidInputException(string msg, string details = null, RestRespon //this.Data["Details"] = details; } } + public class AmazonQuotaExceededException : AmazonException { public AmazonQuotaExceededException(string msg, RestResponse response = null) : base(msg, response) diff --git a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Notifications/EventFilter.cs b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Notifications/EventFilter.cs index 1d05167c..8b083174 100644 --- a/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Notifications/EventFilter.cs +++ b/Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Notifications/EventFilter.cs @@ -26,6 +26,13 @@ public class EventFilter : AggregationFilter [JsonProperty(PropertyName = "eventFilterType")] public string EventFilterType { get; set; } + /// + /// Gets or Sets OrderChangeTypes + /// + [DataMember(Name = "orderChangeTypes", EmitDefaultValue = false)] + [JsonProperty(PropertyName = "orderChangeTypes")] + public IList OrderChangeTypes { get; set; } + /// /// Get the string presentation of the object @@ -37,6 +44,7 @@ public override string ToString() sb.Append("class EventFilter {\n"); sb.Append(" MarketplaceIds: ").Append(MarketplaceIds).Append("\n"); sb.Append(" EventFilterType: ").Append(EventFilterType).Append("\n"); + sb.Append(" OrderChangeTypes: ").Append(OrderChangeTypes).Append("\n"); sb.Append("}\n"); return sb.ToString(); } diff --git a/Source/FikaAmazonAPI/FikaAmazonAPI.csproj b/Source/FikaAmazonAPI/FikaAmazonAPI.csproj index 312cef41..25c1f88e 100644 --- a/Source/FikaAmazonAPI/FikaAmazonAPI.csproj +++ b/Source/FikaAmazonAPI/FikaAmazonAPI.csproj @@ -7,9 +7,9 @@ CSharp Amazon Sp API true 8.0 - 1.7.2 - 1.7.2 - 1.7.2 + 1.7.3 + 1.7.3 + 1.7.3 true https://github.com/abuzuhri/Amazon-SP-API-CSharp MIT