Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

camelcase properties on WebHook requests

  • Loading branch information...
commit a8371ba499409beded6f49660711a4a5009f5425 1 parent f5c2c85
Tim Iles authored
View
1  GoCardlessSdk.Tests/WebHooks/WebHooksTests.cs
@@ -20,6 +20,7 @@ public void TestValidSignature()
var request = File.ReadAllText("./Webhooks/Data/test valid signature.txt");
GoCardless.AccountDetails.AppSecret = "8ifu76Qi4HMJC1zSNf93WntQzJKpSmce0SwBNTA5HEqQY61aBTH7Nsx4w_HG1vUL";
Assert.DoesNotThrow(() => WebHooksClient.ParseRequest(request));
+ var payload = WebHooksClient.ParseRequest(request);
}
}
View
59 GoCardlessSdk/WebHooks/GoCardlessRequest.cs
@@ -2,40 +2,39 @@
{
public class GoCardlessRequest
{
- public Payload payload { get; set; }
+ public Payload Payload { get; set; }
+ }
+ public class Payload
+ {
+ public string ResourceType { get; set; }
+ public string Action { get; set; }
+ public Bill[] Bills { get; set; }
+ public PreAuthorization[] PreAuthorizations { get; set; }
+ public Subscription[] Subscriptions { get; set; }
+ public string Signature { get; set; }
- public class Payload
+ public class Bill
{
- public string resource_type { get; set; }
- public string action { get; set; }
- public Bill[] bills { get; set; }
- public PreAuthorization[] pre_authorizations { get; set; }
- public Subscription[] subscriptions { get; set; }
- public string signature { get; set; }
-
- public class Bill
- {
- public string id { get; set; }
- public string status { get; set; }
- public string source_type { get; set; }
- public string source_id { get; set; }
- public string paid_at { get; set; }
- public string uri { get; set; }
- }
+ public string Id { get; set; }
+ public string Status { get; set; }
+ public string SourceType { get; set; }
+ public string SourceId { get; set; }
+ public string PaidAt { get; set; }
+ public string Uri { get; set; }
+ }
- public class PreAuthorization
- {
- public string id { get; set; }
- public string status { get; set; }
- public string uri { get; set; }
- }
+ public class PreAuthorization
+ {
+ public string Id { get; set; }
+ public string Status { get; set; }
+ public string Uri { get; set; }
+ }
- public class Subscription
- {
- public string id { get; set; }
- public string status { get; set; }
- public string uri { get; set; }
- }
+ public class Subscription
+ {
+ public string Id { get; set; }
+ public string Status { get; set; }
+ public string Uri { get; set; }
}
}
}
View
16 GoCardlessSdk/WebHooks/WebHooksClient.cs
@@ -1,4 +1,6 @@
-using Newtonsoft.Json;
+using System.IO;
+using GoCardlessSdk.Api.Json;
+using Newtonsoft.Json;
namespace GoCardlessSdk.WebHooks
{
@@ -9,14 +11,18 @@ public class WebHooksClient
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
- public static GoCardlessRequest.Payload ParseRequest(string content)
+ public static Payload ParseRequest(string content)
{
// deserialize request content. (ensure content type is set to JSON in GoCardless setup)
- var payload = JsonConvert.DeserializeObject<GoCardlessRequest>(content).payload;
+ var serializer = new JsonSerializer
+ {
+ ContractResolver = new UnderscoreToCamelCasePropertyResolver(),
+ };
+ var payload = serializer.Deserialize<GoCardlessRequest>(new JsonTextReader(new StringReader(content))).Payload;
// validate the HMAC digest by resigning the received parameters
- var signature = payload.signature;
- payload.signature = null;
+ var signature = payload.Signature;
+ payload.Signature = null;
if (signature != Utils.GetSignatureForParams(payload.ToHashParams(), GoCardless.AccountDetails.AppSecret))
{
Please sign in to comment.
Something went wrong with that request. Please try again.