Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // start ngrok like follows
            // ngrok http --host-header=rewrite localhost:12193
            var requestBody = Request.InputStream;
            var requestJson = new StreamReader(requestBody).ReadToEnd();
            var secret      = ConfigurationManager.AppSettings["GoCardlessWebhookSecret"];
            var signature   = Request.Headers["Webhook-Signature"] ?? "";

            foreach (Event evt in WebhookParser.Parse(requestJson, secret, signature))
            {
                switch (evt.Action)
                {
                case "created":
                    System.Diagnostics.Debug.WriteLine("Mandate " + evt.Links.Mandate + " has been created, yay!");
                    break;

                case "cancelled":
                    System.Diagnostics.Debug.WriteLine("Mandate " + evt.Links.Mandate + " has been cancelled");
                    break;
                }
            }
        }
Пример #2
0
 public void ShouldThrowWithInvalidSignature()
 {
     Assert.Throws <InvalidSignatureException>(
         () => WebhookParser.Parse(body, key, "notatallcorrect"));
 }
Пример #3
0
        private void ProcessMessage(BrokeredMessage bmess)
        {
            try {
                using ( bmess ) {
                    var message    = bmess.GetBody <WebhookQueueMessage>();
                    var endmessage = WebhookParser.Parse(message);
                    var parsed     = true;
                    if (endmessage == null)
                    {
                        var parser = WebhookParser.Get(message);
                        if (parser == null)
                        {
                            Log.Error("Could not find parser for message\n" + message.Body);
                            endmessage = "Could not find parser for message";
                        }
                        else
                        {
                            Log.Error(parser.GetType().Name + " failed to parse\n" + message.Body);
                            if (parser.GetType() == typeof(GithubWebhookParser))
                            {
                                endmessage = parser.GetType().Name + " failed to parse message of event type: " +
                                             message.Headers["X-GitHub-Event"].First();
                            }
                            else
                            {
                                endmessage = parser.GetType().Name + " failed to parse message";
                            }
                        }
                        parsed = false;
                    }
                    if (endmessage != "IGNORE")
                    {
                        var messageItem = new MessageItem("gap", endmessage);
                        switch (message.Endpoint)
                        {
                        case WebhookEndpoint.Octgn:
                            Inputs["WebhookOctgn"].Push(this, messageItem);
                            break;

                        case WebhookEndpoint.OctgnDev:
                            Inputs["WebhookOctgnDev"].Push(this, messageItem);
                            break;

                        case WebhookEndpoint.OctgnLobby:
                            Inputs["WebhookOctgnLobby"].Push(this, messageItem);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(message.Endpoint.ToString());
                        }
                    }

                    if (parsed)
                    {
                        bmess.Complete();
                    }
                }
            } catch (Exception e) {
                Log.Error("ProcessHooksTimerOnElapsed", e);
            }
        }
Пример #4
0
        public void ShouldCorrectlyBuildEvents()
        {
            var result = WebhookParser.Parse(body, key, signature);

            Assert.AreEqual(2, result.Count());
        }