GoCardless Webhooks

问题描述

这是我第一个使用GoCardless文档实施的webhook项目,请耐心等待。

我创建了一个.Net Web应用程序,并使用ngrok成功创建了到本地主机的隧道。 我已经从GoCardless发送了一个文本webhook,得到了200OK的响应代码,但是响应的正文实际上是标准的ASP.Net页面,而不是数据。

The html version of this image

如果我尝试链接到Controller localhost:XXXXX / Test,则会在“ /”应用程序中收到服务器错误。找不到资源。

public class TestController : Controller
    {
        [HttpPost]
        public ActionResult HandleWebhook()
        {
            var requestBody = Request.InputStream;
            requestBody.Seek(0,System.IO.SeekOrigin.Begin);
            var requestJson = new StreamReader(requestBody).ReadToEnd();

            // We recommend storing your webhook endpoint secret in an environment variable
            // for security
            var secret = ConfigurationManager.AppSettings["GoCardlessWebhookSecret"];
            var signature = Request.Headers["Webhook-Signature"];

            try
            {
                foreach (GoCardless.Resources.Event WebhookEvent in WebhookParser.Parse(requestJson,secret,signature))
                {
                    // To keep this example simple,we're only handling Mandate events
                    if (WebhookEvent.ResourceType == GoCardless.Resources.EventResourceType.Mandates)
                    {
                        switch (WebhookEvent.Action)
                        {
                            case "created":
                                Console.WriteLine($"Mandate {WebhookEvent.Links.Mandate} has been created,yay!");
                                break;
                            case "cancelled":
                                Console.WriteLine($"Oh no,mandate {WebhookEvent.Links.Mandate} was cancelled!");
                                break;
                            default:
                                Console.WriteLine($"{WebhookEvent.Links.Mandate} has been {WebhookEvent.Action}");
                                break;
                        }
                    }
                    else
                    {
                        Console.WriteLine($"No method to handle {WebhookEvent.ResourceType} events yet");
                    }
                }
                Console.WriteLine($"Mandate  has been created,yay!");
                return new HttpStatusCodeResult(HttpStatusCode.OK);
            }
            catch (InvalidSignatureException)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

        }
    } 

HomeController类似于:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }   

    }

认情况下,页面会加载HomeController,但是调试时如何加载TestController。

任何帮助将不胜感激。在沙盒环境中对此进行了测试。 很高兴提供进一步的信息等。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)