Braintree Webhook - 检查网址无效

时间:2016-05-07 10:50:29

标签: c# model-view-controller webhooks braintree

我已在我的Braintree帐户https://example.com/Webhook/Accept

中设置了一个webhook

我有网站设置来创建一个客户&通过购买链接订阅。

当我通过链接进行购买时,这些都在Braintree保险库中创建,webhook会触发,我会收到2个通知。

这一切似乎都很棒,一切正常,除了检查网址'在Braintree控制面板Webhook部分中,我收到HTTP错误500内部服务器错误。

我认为这是关于GET的一个bt_challenge问题,但尝试了一些变化,我只是无法让它发挥作用。

这是我的控制器:

public class WebhookController : Controller
{
    public IBraintreeConfiguration config = new BraintreeConfiguration();

public ActionResult Accept()
{
    CrmDB db = new CrmDB();
    Log log;

    var gateway = config.GetGateway();

    if (Request.HttpMethod == "POST")
    {
        WebhookNotification webhookNotification = gateway.WebhookNotification.Parse(
            Request.Params["bt_signature"],
            Request.Params["bt_payload"]
            );

        string message = string.Format(
            "[Webhook Received {0}] | Kind: {1} | Subscription: {2}",
            webhookNotification.Timestamp.Value,
            webhookNotification.Kind,
            webhookNotification.Subscription.Id
            );

        System.Console.WriteLine(message);

        // Save to Db
        log = new Log
        {
            Stamp = DateTime.Now,
            App = "api/Webhook/Accept",
            IsInsight = true,
            Insight = message
        };

        // Db
        db.Log.Add(log);
        db.SaveChanges();

        return new HttpStatusCodeResult(200);
    }
    else
    {
        string msg = gateway.WebhookNotification.Verify(Request.QueryString["bt_challenge"]);

        // Save to Db
        log = new Log
        {
            Stamp = DateTime.Now,
            App = "Webhook - bt_challenge",
            IsInsight = true,
            Insight = msg
        };

        // Db
        db.Log.Add(log);
        db.SaveChanges();
        return Content(msg);
    }
}
}

我认为问题出在其他部分(即HTTP GET),但我无法弄清楚它是什么。

为什么我从Webhook控制面板收到500内部错误?

0 个答案:

没有答案