From d946ccb6d037951198a9c5734595988b686e494a Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Tue, 31 Jan 2023 17:07:41 +1030 Subject: [PATCH 1/3] Add fulfillment cancel endpoint Implements #833 --- .../Services/Fulfillment/FulfillmentService.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ShopifySharp/Services/Fulfillment/FulfillmentService.cs b/ShopifySharp/Services/Fulfillment/FulfillmentService.cs index 61789b39..ef5a0fe0 100644 --- a/ShopifySharp/Services/Fulfillment/FulfillmentService.cs +++ b/ShopifySharp/Services/Fulfillment/FulfillmentService.cs @@ -67,5 +67,18 @@ public virtual async Task UpdateTrackingAsync(long fulfillmentId, F var response = await ExecuteRequestAsync(req, HttpMethod.Post, cancellationToken, content, "fulfillment"); return response.Result; } + + /// + /// Cancels a pending fulfillment with the given id. + /// + /// The fulfillment's id. + /// Cancellation Token + public virtual async Task CancelAsync(long fulfillmentId, CancellationToken cancellationToken = default) + { + var req = PrepareRequest($"fulfillments/{fulfillmentId}/cancel.json"); + + var response = await ExecuteRequestAsync(req, HttpMethod.Post, cancellationToken, rootElement: "fulfillment"); + return response.Result; + } } -} \ No newline at end of file +} From 33a6ca40261bed7ffa83590eae4ffa012921d3ea Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Tue, 31 Jan 2023 17:08:14 +1030 Subject: [PATCH 2/3] Add test covering fulfillment cancellation --- ShopifySharp.Tests/Fulfillment_Tests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ShopifySharp.Tests/Fulfillment_Tests.cs b/ShopifySharp.Tests/Fulfillment_Tests.cs index 7ede8328..100abeac 100644 --- a/ShopifySharp.Tests/Fulfillment_Tests.cs +++ b/ShopifySharp.Tests/Fulfillment_Tests.cs @@ -151,6 +151,16 @@ public async Task Updates_Tracking_Fulfillments() Assert.Equal(trackingNum, updated.TrackingNumbers.First()); Assert.Equal(trackingUrl, updated.TrackingUrls.First()); } + + [Fact] + public async Task Cancels_Fulfillments() + { + var order = await Fixture.CreateOrder(); + var created = await Fixture.Create(order.Id.Value); + var cancelled = await Fixture.Service.CancelAsync(created.Id.Value); + + Assert.Equal("cancelled", cancelled.Status); + } } public class Fulfillment_Tests_Fixture : IAsyncLifetime From 2e7d9069c0469b336e2271e7abc054d6c3b6934f Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Tue, 31 Jan 2023 17:09:23 +1030 Subject: [PATCH 3/3] Update documentation --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 4dbdb202..db18cb14 100644 --- a/readme.md +++ b/readme.md @@ -1346,7 +1346,7 @@ Fulfillments can only be cancelled if their `Status` is `pending`. ```cs var service = new FulfillmentService(myShopifyUrl, shopAccessToken); -await service.CancelAsync(orderId, fulfillmentId); +await service.CancelAsync(fulfillmentId) ``` ---