From 5d4e03eb2a444d36d2a28fd054e8618a3778d282 Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 28 Nov 2022 10:12:47 +1100 Subject: [PATCH 1/2] Ensure that LineItem.TipPaymentGateway is always deserialized so that the TipPaymentGatewaySpecified property gets set. --- ShopifySharp.Tests/Order_Tests.cs | 18 ++++++++++++++++++ ShopifySharp/Entities/LineItem.cs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ShopifySharp.Tests/Order_Tests.cs b/ShopifySharp.Tests/Order_Tests.cs index 5451cb2a..f0d56a21 100644 --- a/ShopifySharp.Tests/Order_Tests.cs +++ b/ShopifySharp.Tests/Order_Tests.cs @@ -205,6 +205,24 @@ public async Task Can_Be_Partially_Updated() // In previous versions of ShopifySharp, the updated JSON would have sent 'email=null', clearing out the email address. Assert.Equal(created.Email, updated.Email); } + + [Fact] + public void TipPaymentGatewaySpecified_GetDeserialized() + { + string orderJson = @"{ + ""id"": 123, + ""line_items"": [ + { + ""id"": 123, + ""tip_payment_gateway"": null + } + ] +} +"; + var order = Infrastructure.Serializer.Deserialize(orderJson); + Assert.Null(order.LineItems.First().TipPaymentGateway); + Assert.True(order.LineItems.First().TipPaymentGatewaySpecified); + } } public class Order_Tests_Fixture : IAsyncLifetime diff --git a/ShopifySharp/Entities/LineItem.cs b/ShopifySharp/Entities/LineItem.cs index 0f876053..7fcc6aaa 100644 --- a/ShopifySharp/Entities/LineItem.cs +++ b/ShopifySharp/Entities/LineItem.cs @@ -118,7 +118,7 @@ public class LineItem : ShopifyObject /// /// The payment gateway used to tender the tip, such as shopify_payments. Present only on tips. /// - [JsonProperty("tip_payment_gateway")] + [JsonProperty("tip_payment_gateway", NullValueHandling = NullValueHandling.Include)] public string TipPaymentGateway { get; set; } /// From 4ba1629fc8c9098d98ae2fc8880a619d9d057aab Mon Sep 17 00:00:00 2001 From: Clement Date: Mon, 28 Nov 2022 10:12:47 +1100 Subject: [PATCH 2/2] Ensure that LineItem.TipPaymentGateway is always deserialized so that the TipPaymentGatewaySpecified property gets set. --- ShopifySharp.Tests/Order_Tests.cs | 18 ++++++++++++++++++ ShopifySharp/Entities/LineItem.cs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ShopifySharp.Tests/Order_Tests.cs b/ShopifySharp.Tests/Order_Tests.cs index 5451cb2a..f0d56a21 100644 --- a/ShopifySharp.Tests/Order_Tests.cs +++ b/ShopifySharp.Tests/Order_Tests.cs @@ -205,6 +205,24 @@ public async Task Can_Be_Partially_Updated() // In previous versions of ShopifySharp, the updated JSON would have sent 'email=null', clearing out the email address. Assert.Equal(created.Email, updated.Email); } + + [Fact] + public void TipPaymentGatewaySpecified_GetDeserialized() + { + string orderJson = @"{ + ""id"": 123, + ""line_items"": [ + { + ""id"": 123, + ""tip_payment_gateway"": null + } + ] +} +"; + var order = Infrastructure.Serializer.Deserialize(orderJson); + Assert.Null(order.LineItems.First().TipPaymentGateway); + Assert.True(order.LineItems.First().TipPaymentGatewaySpecified); + } } public class Order_Tests_Fixture : IAsyncLifetime diff --git a/ShopifySharp/Entities/LineItem.cs b/ShopifySharp/Entities/LineItem.cs index 0f876053..7fcc6aaa 100644 --- a/ShopifySharp/Entities/LineItem.cs +++ b/ShopifySharp/Entities/LineItem.cs @@ -118,7 +118,7 @@ public class LineItem : ShopifyObject /// /// The payment gateway used to tender the tip, such as shopify_payments. Present only on tips. /// - [JsonProperty("tip_payment_gateway")] + [JsonProperty("tip_payment_gateway", NullValueHandling = NullValueHandling.Include)] public string TipPaymentGateway { get; set; } ///