From 68c610ac56c851de5d17998996ea6b99b1f5acce Mon Sep 17 00:00:00 2001 From: Adam Humpherys Date: Fri, 26 May 2023 10:24:36 -0600 Subject: [PATCH] fixing JSON parsing of webhook request --- PaymentGateway/Models/WebhookResponse.cs | 33 +++++++++++++++++++++++- PaymentGateway/PaymentGateway.csproj | 2 +- PaymentGateway/WebhookParser.cs | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/PaymentGateway/Models/WebhookResponse.cs b/PaymentGateway/Models/WebhookResponse.cs index e038880..0d0d628 100644 --- a/PaymentGateway/Models/WebhookResponse.cs +++ b/PaymentGateway/Models/WebhookResponse.cs @@ -11,6 +11,7 @@ public class Action /// /// /// + [JsonPropertyName("amount")] public string Amount { get; set; } /// @@ -22,11 +23,13 @@ public class Action /// /// /// + [JsonPropertyName("date")] public string Date { get; set; } /// /// /// + [JsonPropertyName("success")] public string Success { get; set; } /// @@ -38,6 +41,7 @@ public class Action /// /// /// + [JsonPropertyName("source")] public string Source { get; set; } /// @@ -49,6 +53,7 @@ public class Action /// /// /// + [JsonPropertyName("username")] public string Username { get; set; } /// @@ -126,16 +131,19 @@ public class Address /// /// /// + [JsonPropertyName("company")] public string Company { get; set; } /// /// /// + [JsonPropertyName("city")] public string City { get; set; } /// /// /// + [JsonPropertyName("state")] public string State { get; set; } /// @@ -153,11 +161,13 @@ public class Address /// /// /// + [JsonPropertyName("email")] public string Email { get; set; } /// /// /// + [JsonPropertyName("phone")] public string Phone { get; set; } /// @@ -169,6 +179,7 @@ public class Address /// /// /// + [JsonPropertyName("fax")] public string Fax { get; set; } } @@ -188,10 +199,11 @@ public class Card /// [JsonPropertyName("cc_exp")] public string CCExp { get; set; } - + /// /// /// + [JsonPropertyName("cavv")] public string CAVV { get; set; } /// @@ -203,11 +215,13 @@ public class Card /// /// /// + [JsonPropertyName("xid")] public string XID { get; set; } /// /// /// + [JsonPropertyName("eci")] public string ECI { get; set; } /// @@ -327,11 +341,13 @@ public class Event /// /// /// + [JsonPropertyName("merchant")] public Merchant Merchant { get; set; } /// /// /// + [JsonPropertyName("features")] public Features Features { get; set; } /// @@ -349,6 +365,7 @@ public class Event /// /// /// + [JsonPropertyName("condition")] public string Condition { get; set; } /// @@ -360,6 +377,7 @@ public class Event /// /// /// + [JsonPropertyName("ponumber")] public string PONumber { get; set; } /// @@ -377,36 +395,43 @@ public class Event /// /// /// + [JsonPropertyName("customerid")] public string CustomerId { get; set; } /// /// /// + [JsonPropertyName("customertaxid")] public string CustomerTaxId { get; set; } /// /// /// + [JsonPropertyName("website")] public string Website { get; set; } /// /// /// + [JsonPropertyName("shipping")] public string Shipping { get; set; } /// /// /// + [JsonPropertyName("currency")] public string Currency { get; set; } /// /// /// + [JsonPropertyName("tax")] public string Tax { get; set; } /// /// /// + [JsonPropertyName("surcharge")] public string Surcharge { get; set; } /// @@ -418,6 +443,7 @@ public class Event /// /// /// + [JsonPropertyName("tip")] public string Tip { get; set; } /// @@ -549,11 +575,13 @@ public class Event /// /// /// + [JsonPropertyName("check")] public Check Check { get; set; } /// /// /// + [JsonPropertyName("card")] public Card Card { get; set; } /// @@ -565,6 +593,7 @@ public class Event /// /// /// + [JsonPropertyName("action")] public Action Action { get; set; } } @@ -588,11 +617,13 @@ public class Merchant /// /// /// + [JsonPropertyName("id")] public string Id { get; set; } /// /// /// + [JsonPropertyName("name")] public string Name { get; set; } } diff --git a/PaymentGateway/PaymentGateway.csproj b/PaymentGateway/PaymentGateway.csproj index 96dbb52..a0944b8 100644 --- a/PaymentGateway/PaymentGateway.csproj +++ b/PaymentGateway/PaymentGateway.csproj @@ -10,7 +10,7 @@ MIT https://github.com/ahwm/payment-gateway-client https://github.com/ahwm/payment-gateway-client - 0.0.4 + 0.0.4.1 1.0.0.0 Webhook parsing README.md diff --git a/PaymentGateway/WebhookParser.cs b/PaymentGateway/WebhookParser.cs index 1259ad1..cfd70fd 100644 --- a/PaymentGateway/WebhookParser.cs +++ b/PaymentGateway/WebhookParser.cs @@ -30,7 +30,7 @@ static public WebhookResponse ParseWebhookData(string body, string signingKey, s HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(signingKey)); return new WebhookResponse { - Data = (WebhookData)JsonSerializer.Deserialize(body, typeof(WebhookData)), + Data = (WebhookData)JsonSerializer.Deserialize(body, typeof(WebhookData), new JsonSerializerOptions { IncludeFields = true }), IsValid = signature == ByteToString(hmac.ComputeHash(Encoding.UTF8.GetBytes(nonce + "." + body))) }; }