Skip to content

Commit

Permalink
Merge pull request #42 from ahwm/webhook-fix
Browse files Browse the repository at this point in the history
fixing JSON parsing of webhook request
  • Loading branch information
ahwm authored May 26, 2023
2 parents fe71dfe + 68c610a commit 26400f9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
33 changes: 32 additions & 1 deletion PaymentGateway/Models/WebhookResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Action
/// <summary>
///
/// </summary>
[JsonPropertyName("amount")]
public string Amount { get; set; }

/// <summary>
Expand All @@ -22,11 +23,13 @@ public class Action
/// <summary>
///
/// </summary>
[JsonPropertyName("date")]
public string Date { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("success")]
public string Success { get; set; }

/// <summary>
Expand All @@ -38,6 +41,7 @@ public class Action
/// <summary>
///
/// </summary>
[JsonPropertyName("source")]
public string Source { get; set; }

/// <summary>
Expand All @@ -49,6 +53,7 @@ public class Action
/// <summary>
///
/// </summary>
[JsonPropertyName("username")]
public string Username { get; set; }

/// <summary>
Expand Down Expand Up @@ -126,16 +131,19 @@ public class Address
/// <summary>
///
/// </summary>
[JsonPropertyName("company")]
public string Company { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("city")]
public string City { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("state")]
public string State { get; set; }

/// <summary>
Expand All @@ -153,11 +161,13 @@ public class Address
/// <summary>
///
/// </summary>
[JsonPropertyName("email")]
public string Email { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("phone")]
public string Phone { get; set; }

/// <summary>
Expand All @@ -169,6 +179,7 @@ public class Address
/// <summary>
///
/// </summary>
[JsonPropertyName("fax")]
public string Fax { get; set; }
}

Expand All @@ -188,10 +199,11 @@ public class Card
/// </summary>
[JsonPropertyName("cc_exp")]
public string CCExp { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("cavv")]
public string CAVV { get; set; }

/// <summary>
Expand All @@ -203,11 +215,13 @@ public class Card
/// <summary>
///
/// </summary>
[JsonPropertyName("xid")]
public string XID { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("eci")]
public string ECI { get; set; }

/// <summary>
Expand Down Expand Up @@ -327,11 +341,13 @@ public class Event
/// <summary>
///
/// </summary>
[JsonPropertyName("merchant")]
public Merchant Merchant { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("features")]
public Features Features { get; set; }

/// <summary>
Expand All @@ -349,6 +365,7 @@ public class Event
/// <summary>
///
/// </summary>
[JsonPropertyName("condition")]
public string Condition { get; set; }

/// <summary>
Expand All @@ -360,6 +377,7 @@ public class Event
/// <summary>
///
/// </summary>
[JsonPropertyName("ponumber")]
public string PONumber { get; set; }

/// <summary>
Expand All @@ -377,36 +395,43 @@ public class Event
/// <summary>
///
/// </summary>
[JsonPropertyName("customerid")]
public string CustomerId { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("customertaxid")]
public string CustomerTaxId { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("website")]
public string Website { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("shipping")]
public string Shipping { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("currency")]
public string Currency { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("tax")]
public string Tax { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("surcharge")]
public string Surcharge { get; set; }

/// <summary>
Expand All @@ -418,6 +443,7 @@ public class Event
/// <summary>
///
/// </summary>
[JsonPropertyName("tip")]
public string Tip { get; set; }

/// <summary>
Expand Down Expand Up @@ -549,11 +575,13 @@ public class Event
/// <summary>
///
/// </summary>
[JsonPropertyName("check")]
public Check Check { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("card")]
public Card Card { get; set; }

/// <summary>
Expand All @@ -565,6 +593,7 @@ public class Event
/// <summary>
///
/// </summary>
[JsonPropertyName("action")]
public Action Action { get; set; }
}

Expand All @@ -588,11 +617,13 @@ public class Merchant
/// <summary>
///
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>
///
/// </summary>
[JsonPropertyName("name")]
public string Name { get; set; }
}

Expand Down
2 changes: 1 addition & 1 deletion PaymentGateway/PaymentGateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/ahwm/payment-gateway-client</PackageProjectUrl>
<RepositoryUrl>https://github.com/ahwm/payment-gateway-client</RepositoryUrl>
<Version>0.0.4</Version>
<Version>0.0.4.1</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<PackageReleaseNotes>Webhook parsing</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
2 changes: 1 addition & 1 deletion PaymentGateway/WebhookParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
};
}
Expand Down

0 comments on commit 26400f9

Please sign in to comment.