Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement fulfilment cancel endpoint #834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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