Skip to content

Commit

Permalink
Merge pull request #834 from thomotron/feature/cancel-fulfillment-end…
Browse files Browse the repository at this point in the history
…point

Reimplement fulfilment cancel endpoint
  • Loading branch information
nozzlegear authored Jul 12, 2023
2 parents 7b2afcb + 2e7d906 commit 57ee301
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions ShopifySharp.Tests/Fulfillment_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion ShopifySharp/Services/Fulfillment/FulfillmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,18 @@ public virtual async Task<Fulfillment> UpdateTrackingAsync(long fulfillmentId, F
var response = await ExecuteRequestAsync<Fulfillment>(req, HttpMethod.Post, cancellationToken, content, "fulfillment");
return response.Result;
}

/// <summary>
/// Cancels a pending fulfillment with the given id.
/// </summary>
/// <param name="fulfillmentId">The fulfillment's id.</param>
/// <param name="cancellationToken">Cancellation Token</param>
public virtual async Task<Fulfillment> CancelAsync(long fulfillmentId, CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"fulfillments/{fulfillmentId}/cancel.json");

var response = await ExecuteRequestAsync<Fulfillment>(req, HttpMethod.Post, cancellationToken, rootElement: "fulfillment");
return response.Result;
}
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

---
Expand Down

0 comments on commit 57ee301

Please sign in to comment.