zoukankan      html  css  js  c++  java
  • Webhooks PHP

    Webhooks/Parse


    When webhooks are triggered in the gateway, a notification is sent as a POST request to the specified destination URL. The post body contains two x-www-form-urlencoded parameters:

    • bt_signature
    • bt_payload

    This payload is signed to ensure that the message originated from Braintree and was not modified in transit. The message is identical to standard API responses and contains a snapshot of the related entity at the time the webhook was triggered.

    These parameters should be passed to the Braintree_WebhookNotification::parse. The result will be a WebhookNotification object consisting of:

    • A timestamp (in UTC)
      • Tip: Notifications may not be delivered sequentially, so be sure to look at the timestamp of the event.
    • A kind (directly mapped to triggers)
    • A standard Braintree object, depending on the type of notification (e.g. a subscription object for recurring billing webhooks)
      • Tip: Save webhook data to your database for reporting purposes or use it to trigger other actions in your app

    PHP

    if(
        isset($_POST["bt_signature"]) &&
        isset($_POST["bt_payload"])
    ) {
        $webhookNotification = Braintree_WebhookNotification::parse(
            $_POST["bt_signature"], $_POST["bt_payload"]
        );
    
        $message =
            "[Webhook Received " . $webhookNotification->timestamp->format('Y-m-d H:i:s') . "] "
            . "Kind: " . $webhookNotification->kind . " | ";
    
        file_put_contents("/tmp/webhook.log", $message, FILE_APPEND);
    }

    Notice how we are using file_put_contents to store the result of the received Webhooks to /tmp/webhooks.log.

    PHP

    $webhookNotification = Braintree_WebhookNotification::parse(
      $_POST["bt_signature"], $_POST["bt_payload"]
    );
    
    $webhookNotification->kind;
    # => "subscription_went_past_due"
    
    $webhookNotification->timestamp;
    # => Sun Jan 1 00:00:00 UTC 2012
    Exceptions

    An exception may be raised while attempting to parse a Webhook signature.

    Next: Testing and Go Live →

    Still Have Questions?

    If you can’t find an answer, give us a call at 877.434.2894 or email our Support team.

    我生活的地方,我为何要生活。
  • 相关阅读:
    数组逆序输出与简单的数据匹配
    冒泡排序及其优化
    类型转换
    Spring学习【Spring】
    logistic回归模型
    决策树算法(3)
    决策树算法(2)
    决策树算法(1)
    朴素贝叶斯算法
    k近邻算法
  • 原文地址:https://www.cnblogs.com/hsd1727728211/p/5868604.html
Copyright © 2011-2022 走看看