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.

Webhooks PHP的更多相关文章

  1. 第四十一章 微服务CICD(3)- jenkins + gitlab + webhooks + publish-over-ssh(1)

    一.作用 使用webhooks来实现当git客户端push代码到gitlab后,jenkins会立即去gitlab拉取代码并构建. 二.步骤 1.安装插件 ruby_runtime(Hook插件依赖于 ...

  2. ASP.NET的新成员ASP.NET WebHooks

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:前几天微软除了发布了ASP.NET 5的Beta7之外,还有一个值得关注的东西,就是A ...

  3. 使用 GitHub / GitLab 的 Webhooks 进行网站自动化部署

    老早就想写这个话题了,今天正好有机会研究了一下 git 的自动化部署.最终做到的效果就是,每当有新的 commit push 到 master 分支的时候,就自动在测试/生产服务器上进行 git pu ...

  4. 微软发布了ASP.NET WebHooks预览版

    微软 近期发布了ASP.NET WebHooks的预览版 ,这是一个可用于创建及使用Webhook功能的库.WebHooks支持MVC 5及WebApi 2. Webhook是一种通过HTTP实现用户 ...

  5. WebHooks

    WebHooks ASP.NET 5 Beta 7 版本   在 VS2015 发布的同时,微软也发布了 ASP.NET 5 的路线图(详见ASP.NET 5 Schedule and Roadmap ...

  6. springboot+cloud 学习(五)统一配置中心 spring cloud config + cloud bus + WebHooks +RibbitMQ

    前言 微服务要实现集中管理微服务配置.不同环境不同配置.运行期间也可动态调整.配置修改后可以自动更新的需求,Spring Cloud Config同时满足了以上要求.Spring Cloud Conf ...

  7. 基于 Webhooks gitlab 自动化构建

    基于gitlab webhooks 自动构建流程 1.服务器安装 git 服务 安装成功 配置 PHP 脚本: <?php // 接受头部信息 if (!isset($_GET['youpara ...

  8. jenkins+gitlab webhooks 实现自动触发打包

    说明:实现代码在gitlab上的提交后立马自动进行jenkins的job构建 安装插件: Gitlab Hook Plugin  Build Authorization Token Root Plug ...

  9. Gitlab Webhooks, External Services, and API(二)

    一. 使用webhooks webhook 是一个API的概念,并且变得越来越流行.我们能用事件描述的事物越多,webhook的作用范围也就越大.webhook作为 个轻量的事件处理应用,正变得越来越 ...

随机推荐

  1. Android下海康实时视频解码

    折腾了一个多月,终于调出来了.....首先吐槽一下海康SDK,同时也感谢之... 手头有个项目,需要实时抓取海康摄像头,我是在Android下实现的,海康官网上没有Android SDK,这里友情提醒 ...

  2. jquery重写一个对话框

    (原文来自博客园 wuchao.cnblogs.com) 写一个简单的基于jquery的对话框 css: #dialog { border:solid 1px #CCC; width:300px; h ...

  3. (转)Unity3D研究院之异步加载游戏场景与异步加载游戏资源进度条(三十一)

      异步任务相信大家应该不会陌生,那么本章内容MOMO将带领大家学习Unity中的一些异步任务.在同步加载游戏场景的时候通常会使用方法 Application.LoadLevel(“yourScene ...

  4. shell来start、stop、restart应用程序模板

    这里使用shell中的case语法: case分支语句格式如下: case $变量名 in 模式1) 命令列表 ;; 模式2) 命令列表 ;; *) ;; esac case行尾必须为单词“in”,每 ...

  5. 十八、【开源】EnterpriseFrameWork框架核心类库之Winform控制器

    回<[开源]EnterpriseFrameWork框架系列文章索引> EFW框架源代码下载:http://pan.baidu.com/s/1qWJjo3U EFW框架中的WinContro ...

  6. 十、EnterpriseFrameWork框架的分层架构及意义(控制器、业务对象、实体、Dao之间关系)

    本章内容主要包括两个方面,一.是框架分层(控制器.业务对象.实体.Dao)的详细说明,二.是对比常用三层结构的区别和优势: 本文要点: 1.框架中的各个分层详细说明 2.对比常用三层结构的区别和优势 ...

  7. Netty5 + Protobuf 使用

    1. 安装开发环境 1.1 Netty环境 这里我使用Netty5.0.0版本 到这里下载即可http://netty.io/ 下载netty-all-5.0.0.Alpha2.jar 这个jar包简 ...

  8. 白话Redis与Memcached区别

    如果简单地比较Redis与Memcached的区别,外在的区别是: 1  Redis不仅仅支持简单的k/v类型的数据,同时还提供list,set,zset,hash等数据结构的存储. 2  Redis ...

  9. label标签跳出循环

    出场: 首先我们来说说为什么需要label标签,虽然我们已经知道有break,continue跳出循环,但如果是多重循环那么它们就显的无能为力了,所以就出现了label这个标签来为我们服务. 我们先来 ...

  10. Transactional replication 的Snapshot 文件在什么情况下会被清除

    Snapshot agent负责收集publication database的信息,将article的内容存储在snapshot文件中.而distribuiton cleanup job(后文简称清除 ...