-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #838 from lucasabond/CancellationRequestService
Added support for Fulfillment Order Cancellation Request
- Loading branch information
Showing
5 changed files
with
164 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
|
||
namespace ShopifySharp | ||
{ | ||
/// <summary> | ||
/// An object representing a Shopify fulfillment cancellation request. | ||
/// </summary> | ||
public class CancellationRequest | ||
{ | ||
/// <summary> | ||
/// An optional reason for the cancellation request. | ||
/// </summary> | ||
[JsonProperty("message")] | ||
public string Message { get; set; } | ||
|
||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
ShopifySharp/Services/CancellationRequest/CancellationRequestService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using ShopifySharp.Infrastructure; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp | ||
{ | ||
/// <summary> | ||
/// The CancellationRequest resource represents a cancellation request made by the merchant or an order management app to a fulfillment service for a fulfillment order. | ||
/// </summary> | ||
public class CancellationRequestService : ShopifyService, ICancellationRequestService | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="CancellationRequestService" />. | ||
/// </summary> | ||
/// <param name="myShopifyUrl">The shop's *.myshopify.com URL.</param> | ||
/// <param name="shopAccessToken">An API access token for the shop.</param> | ||
public CancellationRequestService(string myShopifyUrl, string shopAccessToken) : base(myShopifyUrl, shopAccessToken) { } | ||
|
||
public virtual async Task<FulfillmentOrder> CreateAsync(long fulfillmentOrderId, string message, CancellationToken cancellationToken = default) | ||
{ | ||
var req = PrepareRequest($@"fulfillment_orders/{fulfillmentOrderId}/cancellation_request.json"); | ||
var cancellationRequest = new CancellationRequest { Message = message }; | ||
var body = cancellationRequest.ToDictionary(); | ||
|
||
var content = new JsonContent(new | ||
{ | ||
cancellation_request = body | ||
}); | ||
|
||
var response = await ExecuteRequestAsync<FulfillmentOrder>(req, HttpMethod.Post, cancellationToken, content, "fulfillment_order"); | ||
return response.Result; | ||
} | ||
|
||
public virtual async Task<FulfillmentOrder> AcceptAsync(long fulfillmentOrderId, string message, CancellationToken cancellationToken = default) | ||
{ | ||
var req = PrepareRequest($"fulfillment_orders/{fulfillmentOrderId}/cancellation_request/accept.json"); | ||
var cancellationRequest = new CancellationRequest { Message = message }; | ||
var body = cancellationRequest.ToDictionary(); | ||
|
||
var content = new JsonContent(new | ||
{ | ||
cancellation_request = body | ||
}); | ||
|
||
var response = await ExecuteRequestAsync<FulfillmentOrder>(req, HttpMethod.Post, cancellationToken, content, "fulfillment_order"); | ||
return response.Result; | ||
} | ||
|
||
public virtual async Task<FulfillmentOrder> RejectAsync(long fulfillmentOrderId, string message, CancellationToken cancellationToken = default) | ||
{ | ||
var req = PrepareRequest($@"fulfillment_orders/{fulfillmentOrderId}/cancellation_request/reject.json"); | ||
var cancellationRequest = new CancellationRequest { Message = message }; | ||
var body = cancellationRequest.ToDictionary(); | ||
|
||
var content = new JsonContent(new | ||
{ | ||
cancellation_request = body | ||
}); | ||
|
||
var response = await ExecuteRequestAsync<FulfillmentOrder>(req, HttpMethod.Post, cancellationToken, content, "fulfillment_order"); | ||
return response.Result; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
ShopifySharp/Services/CancellationRequest/ICancellationRequestService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ShopifySharp | ||
{ | ||
/// <summary> | ||
/// The CancellationRequest resource represents a cancellation request made by the merchant or an order management app to a fulfillment service for a fulfillment order. | ||
/// <see href="https://shopify.dev/docs/api/admin-rest/2022-07/resources/cancellationrequest">API Reference</see> | ||
/// </summary> | ||
public interface ICancellationRequestService | ||
{ | ||
/// <summary> | ||
/// Sends a cancellation request to the fulfillment service of a fulfillment order. | ||
/// <see href="https://shopify.dev/docs/api/admin-rest/2022-07/resources/cancellationrequest#post-fulfillment-orders-fulfillment-order-id-cancellation-request">API Reference</see> | ||
/// </summary> | ||
/// <param name="fulfillmentOrderId"></param> | ||
/// <param name="message">An optional reason for the cancellation request</param> | ||
/// <param name="cancellationToken">Cancellation Token</param> | ||
/// <exception cref="ShopifyException"></exception> | ||
Task<FulfillmentOrder> CreateAsync(long fulfillmentOrderId, string message, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Accepts a cancellation request sent to a fulfillment service for a fulfillment order. | ||
/// <see href="https://shopify.dev/docs/api/admin-rest/2022-07/resources/cancellationrequest#post-fulfillment-orders-fulfillment-order-id-cancellation-request-accept">API Reference</see> | ||
/// </summary> | ||
/// <param name="fulfillmentOrderId"></param> | ||
/// <param name="message">An optional reason for accepting the cancellation request</param> | ||
/// <param name="cancellationToken">Cancellation Token</param> | ||
/// <exception cref="ShopifyException"></exception> | ||
Task<FulfillmentOrder> AcceptAsync(long fulfillmentOrderId, string message, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Rejects a cancellation request sent to a fulfillment service for a fulfillment order. | ||
/// <see href="https://shopify.dev/docs/api/admin-rest/2022-07/resources/cancellationrequest#post-fulfillment-orders-fulfillment-order-id-cancellation-request-reject">API Reference</see> | ||
/// </summary> | ||
/// <param name="fulfillmentOrderId"></param> | ||
/// <param name="message">An optional reason for rejecting the cancellation request</param> | ||
/// <param name="cancellationToken">Cancellation Token</param> | ||
/// <exception cref="ShopifyException"></exception> | ||
Task<FulfillmentOrder> RejectAsync(long fulfillmentOrderId, string message, CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters