Skip to content
This repository
Browse code

camelcase properties on WebHook requests

  • Loading branch information...
commit a8371ba499409beded6f49660711a4a5009f5425 1 parent f5c2c85
Tim Iles authored
1  GoCardlessSdk.Tests/WebHooks/WebHooksTests.cs
@@ -20,6 +20,7 @@ public void TestValidSignature()
20 20 var request = File.ReadAllText("./Webhooks/Data/test valid signature.txt");
21 21 GoCardless.AccountDetails.AppSecret = "8ifu76Qi4HMJC1zSNf93WntQzJKpSmce0SwBNTA5HEqQY61aBTH7Nsx4w_HG1vUL";
22 22 Assert.DoesNotThrow(() => WebHooksClient.ParseRequest(request));
  23 + var payload = WebHooksClient.ParseRequest(request);
23 24 }
24 25
25 26 }
59 GoCardlessSdk/WebHooks/GoCardlessRequest.cs
@@ -2,40 +2,39 @@
2 2 {
3 3 public class GoCardlessRequest
4 4 {
5   - public Payload payload { get; set; }
  5 + public Payload Payload { get; set; }
  6 + }
  7 + public class Payload
  8 + {
  9 + public string ResourceType { get; set; }
  10 + public string Action { get; set; }
  11 + public Bill[] Bills { get; set; }
  12 + public PreAuthorization[] PreAuthorizations { get; set; }
  13 + public Subscription[] Subscriptions { get; set; }
  14 + public string Signature { get; set; }
6 15
7   - public class Payload
  16 + public class Bill
8 17 {
9   - public string resource_type { get; set; }
10   - public string action { get; set; }
11   - public Bill[] bills { get; set; }
12   - public PreAuthorization[] pre_authorizations { get; set; }
13   - public Subscription[] subscriptions { get; set; }
14   - public string signature { get; set; }
15   -
16   - public class Bill
17   - {
18   - public string id { get; set; }
19   - public string status { get; set; }
20   - public string source_type { get; set; }
21   - public string source_id { get; set; }
22   - public string paid_at { get; set; }
23   - public string uri { get; set; }
24   - }
  18 + public string Id { get; set; }
  19 + public string Status { get; set; }
  20 + public string SourceType { get; set; }
  21 + public string SourceId { get; set; }
  22 + public string PaidAt { get; set; }
  23 + public string Uri { get; set; }
  24 + }
25 25
26   - public class PreAuthorization
27   - {
28   - public string id { get; set; }
29   - public string status { get; set; }
30   - public string uri { get; set; }
31   - }
  26 + public class PreAuthorization
  27 + {
  28 + public string Id { get; set; }
  29 + public string Status { get; set; }
  30 + public string Uri { get; set; }
  31 + }
32 32
33   - public class Subscription
34   - {
35   - public string id { get; set; }
36   - public string status { get; set; }
37   - public string uri { get; set; }
38   - }
  33 + public class Subscription
  34 + {
  35 + public string Id { get; set; }
  36 + public string Status { get; set; }
  37 + public string Uri { get; set; }
39 38 }
40 39 }
41 40 }
16 GoCardlessSdk/WebHooks/WebHooksClient.cs
... ... @@ -1,4 +1,6 @@
1   -using Newtonsoft.Json;
  1 +using System.IO;
  2 +using GoCardlessSdk.Api.Json;
  3 +using Newtonsoft.Json;
2 4
3 5 namespace GoCardlessSdk.WebHooks
4 6 {
@@ -9,14 +11,18 @@ public class WebHooksClient
9 11 /// </summary>
10 12 /// <param name="content"></param>
11 13 /// <returns></returns>
12   - public static GoCardlessRequest.Payload ParseRequest(string content)
  14 + public static Payload ParseRequest(string content)
13 15 {
14 16 // deserialize request content. (ensure content type is set to JSON in GoCardless setup)
15   - var payload = JsonConvert.DeserializeObject<GoCardlessRequest>(content).payload;
  17 + var serializer = new JsonSerializer
  18 + {
  19 + ContractResolver = new UnderscoreToCamelCasePropertyResolver(),
  20 + };
  21 + var payload = serializer.Deserialize<GoCardlessRequest>(new JsonTextReader(new StringReader(content))).Payload;
16 22
17 23 // validate the HMAC digest by resigning the received parameters
18   - var signature = payload.signature;
19   - payload.signature = null;
  24 + var signature = payload.Signature;
  25 + payload.Signature = null;
20 26
21 27 if (signature != Utils.GetSignatureForParams(payload.ToHashParams(), GoCardless.AccountDetails.AppSecret))
22 28 {

0 comments on commit a8371ba

Please sign in to comment.
Something went wrong with that request. Please try again.