Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
abuzuhri committed Aug 30, 2023
2 parents 103e816 + fd5d44a commit ff0ffb4
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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<InvoiceRequest>, IValidatableObject
{
public InvoiceRequest(List<Attachment> attachments = default(List<Attachment>), DateTime? coverageStartDate = default(DateTime?), DateTime? coverageEndDate = default(DateTime?))
{
this.Attachments = attachments;
}

[DataMember(Name = "attachments", EmitDefaultValue = false)]
public List<Attachment> 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<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
yield break;
}
}
}
Original file line number Diff line number Diff line change
@@ -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<InvoiceResponse>, 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<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
yield break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of value-added services available for a shipping service offering.
/// </summary>
[DataContract]
[CollectionDataContract]
public class AvailableValueAddedServiceGroupList : List<AvailableValueAddedServiceGroup> {

/// <summary>
Expand All @@ -32,5 +32,5 @@ public override string ToString() {
return JsonConvert.SerializeObject(this, Formatting.Indented);
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of charges based on the shipping service charges applied on a package.
/// </summary>
[DataContract]
[CollectionDataContract]
public class ChargeList : List<ChargeComponent> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of ineligible shipping service offerings.
/// </summary>
[DataContract]
[CollectionDataContract]
public class IneligibleRateList : List<IneligibleRate> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of items.
/// </summary>
[DataContract]
[CollectionDataContract]
public class ItemList : List<Item> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of post-purchase details about a package that will be shipped using a shipping service.
/// </summary>
[DataContract]
[CollectionDataContract]
public class PackageDocumentDetailList : List<PackageDocumentDetail> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of documents related to a package.
/// </summary>
[DataContract]
[CollectionDataContract]
public class PackageDocumentList : List<PackageDocument> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of packages to be shipped through a shipping service offering.
/// </summary>
[DataContract]
[CollectionDataContract]
public class PackageList : List<Package> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of the format options for a label.
/// </summary>
[DataContract]
[CollectionDataContract]
public class PrintOptionList : List<PrintOption> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of eligible shipping service offerings.
/// </summary>
[DataContract]
[CollectionDataContract]
public class RateList : List<Rate> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// The value-added services to be added to a shipping service purchase.
/// </summary>
[DataContract]
[CollectionDataContract]
public class RequestedValueAddedServiceList : List<RequestedValueAddedService> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of the document specifications supported for a shipment service offering.
/// </summary>
[DataContract]
[CollectionDataContract]
public class SupportedDocumentSpecificationList : List<SupportedDocumentSpecification> {

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
/// <summary>
/// A list of tax detail information.
/// </summary>
[DataContract]
[CollectionDataContract]
public class TaxDetailList : List<TaxDetail> {

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Source/FikaAmazonAPI/Services/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
15 changes: 13 additions & 2 deletions Source/FikaAmazonAPI/Services/MessagingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,18 @@ public async Task<bool> 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<bool> SendInvoiceAsync(string amazonOrderId, InvoiceRequest invoiceRequest, CancellationToken cancellationToken = default)
{
List<KeyValuePair<string, string>> queryParameters = new List<KeyValuePair<string, string>>();
queryParameters.Add(new KeyValuePair<string, string>("marketplaceIds", AmazonCredential.MarketPlace.ID));
await CreateAuthorizedRequestAsync(MessaginApiUrls.SendInvoice(amazonOrderId), RestSharp.Method.Post, queryParameters, postJsonObj: invoiceRequest, cancellationToken: cancellationToken);


var response = await ExecuteRequestAsync<InvoiceResponse>(RateLimitType.Messaging_CreateUnexpectedProblem, cancellationToken);
if (response != null)
return true;
return false;
}
}
}
}
2 changes: 1 addition & 1 deletion Source/FikaAmazonAPI/Services/ShippingServiceV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public bool CancelShipment(string shipmentId) =>
Task.Run(() => CancelShipmentAsync(shipmentId)).ConfigureAwait(false).GetAwaiter().GetResult();
public async Task<bool> CancelShipmentAsync(string shipmentId, CancellationToken cancellationToken = default)
{
await CreateAuthorizedRequestAsync(ShippingApiV2Urls.CancelShipment(shipmentId), RestSharp.Method.Post, cancellationToken: cancellationToken);
await CreateAuthorizedRequestAsync(ShippingApiV2Urls.CancelShipment(shipmentId), RestSharp.Method.Put, cancellationToken: cancellationToken);
var response = await ExecuteRequestAsync<CancelShipmentResponse>(RateLimitType.ShippingV2_CancelShipment, cancellationToken);
if (response != null)
return true;
Expand Down

0 comments on commit ff0ffb4

Please sign in to comment.