From 7f6ac629b3bbbcd93d4847a956d22b328726c185 Mon Sep 17 00:00:00 2001 From: Joshua Harms Date: Wed, 12 Jul 2023 23:21:48 -0500 Subject: [PATCH 1/4] Add FulfillmentShipping.OriginAddress Fixes #897 --- ShopifySharp/Entities/FulfillmentShipping.cs | 8 +++- .../FulfillmentShippingOriginAddress.cs | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 ShopifySharp/Entities/FulfillmentShippingOriginAddress.cs diff --git a/ShopifySharp/Entities/FulfillmentShipping.cs b/ShopifySharp/Entities/FulfillmentShipping.cs index 95366727..c596ddef 100644 --- a/ShopifySharp/Entities/FulfillmentShipping.cs +++ b/ShopifySharp/Entities/FulfillmentShipping.cs @@ -28,10 +28,16 @@ public class FulfillmentShipping [JsonProperty("tracking_info")] public TrackingInfo TrackingInfo { get; set; } + /// + /// The address of the fulfillment location. + /// + [JsonProperty("origin_address")] + public FulfillmentShippingOriginAddress OriginAddress { get; set; } + /// /// The fulfillment order line items to be requested for fulfillment. If left blank, all line items of the fulfillment order are requested for fulfillment. /// [JsonProperty("line_items_by_fulfillment_order")] public IEnumerable FulfillmentRequestOrderLineItems { get; set; } } -} \ No newline at end of file +} diff --git a/ShopifySharp/Entities/FulfillmentShippingOriginAddress.cs b/ShopifySharp/Entities/FulfillmentShippingOriginAddress.cs new file mode 100644 index 00000000..2901396e --- /dev/null +++ b/ShopifySharp/Entities/FulfillmentShippingOriginAddress.cs @@ -0,0 +1,43 @@ +using Newtonsoft.Json; + +namespace ShopifySharp +{ + public class FulfillmentShippingOriginAddress + { + /// + /// The street address of the fulfillment location. + /// + [JsonProperty("address1")] + public string Address1 { get; set; } + + /// + /// The second line of the address. Typically the number of the apartment, suite, or unit. + /// + [JsonProperty("address2")] + public string Address2 { get; set; } + + /// + /// The city of the fulfillment location. + /// + [JsonProperty("city")] + public string City { get; set; } + + /// + /// (Required) The two-letter country code (ISO 3166-1 alpha-2 format) of the fulfillment location. + /// + [JsonProperty("country_code")] + public string CountryCode { get; set; } + + /// + /// The province of the fulfillment location. + /// + [JsonProperty("province_code")] + public string ProvinceCode { get; set; } + + /// + /// The zip code of the fulfillment location. + /// + [JsonProperty("zip")] + public string Zip { get; set; } + } +} From 92e47239fb1660d51e155a69ec30bc601ab4e6c6 Mon Sep 17 00:00:00 2001 From: Joshua Harms Date: Wed, 12 Jul 2023 23:39:29 -0500 Subject: [PATCH 2/4] Add test for creating fulfillments with origin address --- ShopifySharp.Tests/Fulfillment_Tests.cs | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ShopifySharp.Tests/Fulfillment_Tests.cs b/ShopifySharp.Tests/Fulfillment_Tests.cs index 100abeac..9f1bd229 100644 --- a/ShopifySharp.Tests/Fulfillment_Tests.cs +++ b/ShopifySharp.Tests/Fulfillment_Tests.cs @@ -109,6 +109,24 @@ public async Task Creates_Fulfillments_With_Tracking_Number() Assert.NotEmpty(created.TrackingUrls); } + [Fact] + public async Task Creates_Fulfillments_With_Origin_Address() + { + var order = await Fixture.CreateOrder(); + var created = await Fixture.Create(order.Id.Value, originAddress: true); + + Assert.NotNull(created); + Assert.True(created.Id.HasValue); + Assert.Equal("success", created.Status); + Assert.Equal("US", created.OriginAddress.CountryCode); + Assert.Equal("MN", created.OriginAddress.ProvinceCode); + Assert.Equal("123 4th Street", created.OriginAddress.Address1); + Assert.Equal("Minneapolis", created.OriginAddress.City); + Assert.Equal("MN", created.OriginAddress.ProvinceCode); + Assert.Equal("55401", created.OriginAddress.Zip); + Assert.Equal("US", created.OriginAddress.CountryCode); + } + [Fact] public async Task Creates_Partial_Fulfillments() { @@ -270,7 +288,7 @@ public async Task> ListFulfillmentOrders(long orde return orders; } - public async Task Create(long orderId, bool partialFulfillment = false) + public async Task Create(long orderId, bool partialFulfillment = false, bool originAddress = false) { var fulfillmentOrders = await ListFulfillmentOrders(orderId); var lineItems = fulfillmentOrders.Select(o => new LineItemsByFulfillmentOrder @@ -294,6 +312,16 @@ public async Task Create(long orderId, bool partialFulfillment = fa Company = "Jack Black's Pack, Stack and Track", Url = "https://example.com/123456789", Number = "123456789" + }, + OriginAddress = originAddress == false + ? null + : new FulfillmentShippingOriginAddress + { + Address1 = "123 4th Street", + City = "Minneapolis", + ProvinceCode = "MN", + Zip = "55401", + CountryCode = "US" } }); From d807cafb318451a7a4758613e5a25181abd70973 Mon Sep 17 00:00:00 2001 From: Joshua Harms Date: Wed, 12 Jul 2023 23:40:48 -0500 Subject: [PATCH 3/4] Rename to FulfillmentOriginAddress --- ShopifySharp.Tests/Fulfillment_Tests.cs | 2 +- ...ntShippingOriginAddress.cs => FulfillmentOriginAddress.cs} | 4 ++-- ShopifySharp/Entities/FulfillmentShipping.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename ShopifySharp/Entities/{FulfillmentShippingOriginAddress.cs => FulfillmentOriginAddress.cs} (95%) diff --git a/ShopifySharp.Tests/Fulfillment_Tests.cs b/ShopifySharp.Tests/Fulfillment_Tests.cs index 9f1bd229..20b09e53 100644 --- a/ShopifySharp.Tests/Fulfillment_Tests.cs +++ b/ShopifySharp.Tests/Fulfillment_Tests.cs @@ -315,7 +315,7 @@ public async Task Create(long orderId, bool partialFulfillment = fa }, OriginAddress = originAddress == false ? null - : new FulfillmentShippingOriginAddress + : new FulfillmentOriginAddress { Address1 = "123 4th Street", City = "Minneapolis", diff --git a/ShopifySharp/Entities/FulfillmentShippingOriginAddress.cs b/ShopifySharp/Entities/FulfillmentOriginAddress.cs similarity index 95% rename from ShopifySharp/Entities/FulfillmentShippingOriginAddress.cs rename to ShopifySharp/Entities/FulfillmentOriginAddress.cs index 2901396e..5c835f2d 100644 --- a/ShopifySharp/Entities/FulfillmentShippingOriginAddress.cs +++ b/ShopifySharp/Entities/FulfillmentOriginAddress.cs @@ -2,7 +2,7 @@ namespace ShopifySharp { - public class FulfillmentShippingOriginAddress + public class FulfillmentOriginAddress { /// /// The street address of the fulfillment location. @@ -40,4 +40,4 @@ public class FulfillmentShippingOriginAddress [JsonProperty("zip")] public string Zip { get; set; } } -} +} \ No newline at end of file diff --git a/ShopifySharp/Entities/FulfillmentShipping.cs b/ShopifySharp/Entities/FulfillmentShipping.cs index c596ddef..b58493ef 100644 --- a/ShopifySharp/Entities/FulfillmentShipping.cs +++ b/ShopifySharp/Entities/FulfillmentShipping.cs @@ -32,7 +32,7 @@ public class FulfillmentShipping /// The address of the fulfillment location. /// [JsonProperty("origin_address")] - public FulfillmentShippingOriginAddress OriginAddress { get; set; } + public FulfillmentOriginAddress OriginAddress { get; set; } /// /// The fulfillment order line items to be requested for fulfillment. If left blank, all line items of the fulfillment order are requested for fulfillment. From d497856b86ddc2d3ce88c339d1198f8d47ff4cdf Mon Sep 17 00:00:00 2001 From: Joshua Harms Date: Wed, 12 Jul 2023 23:43:05 -0500 Subject: [PATCH 4/4] Change type of Fulfillment.OriginAddress to FulfillmentOriginAddress The Fulfillment.OriginAddress was previously type `Address`, which is a generic address entity used by several address endpoints. It was not meant to be used as the origin address for a fulfillment. Most properties on that object were always null for the origin address. --- ShopifySharp/Entities/Fulfillment.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ShopifySharp/Entities/Fulfillment.cs b/ShopifySharp/Entities/Fulfillment.cs index e487c960..0750c398 100644 --- a/ShopifySharp/Entities/Fulfillment.cs +++ b/ShopifySharp/Entities/Fulfillment.cs @@ -128,9 +128,9 @@ public class Fulfillment : ShopifyObject public string Name { get; set; } /// - /// The address of the fulfillment location + /// The address of the fulfillment location. /// [JsonProperty("origin_address")] - public Address OriginAddress { get; set; } + public FulfillmentOriginAddress OriginAddress { get; set; } } }