php - 如何处理 BrainTree 中的 Webhooks

标签 php webhooks braintree

我正在尝试使用 BrainTree webhooks 进行订阅交易,但无法验证我的页面。

来自 BrainTree:https://www.braintreepayments.com/docs/php/webhooks/destination_verification

当您尝试添加目的地时,我们的服务器将使用名为 bt_challenge 的查询参数向提供的 URL 发出 GET 请求。该查询参数应传递给验证方法。调用此方法的结果应作为响应正文返回。

Braintree_WebhookNotification::verify(bt_challenge_param);

首先,我在 NodeJS 中进行了尝试(因为我们的事务已通过这种方式成功完成):

//WEBHOOK GET PROCESS FOR BRAINTREE SUBSCRIPTION
app.get('/getwebhook', function(req, res){

    var bt_challenge_param = req.param('bt_challenge_param', null);
    var jsObj = new Object();

    jsObj.response = gateway.webhookNotification.verify(bt_challenge_param);

    res.json(JSON.stringify(jsObj));
});

我的 PHP 页面与 NodeJS 进程通信并将结果放入正文中。一旦验证失败,我就直接用PHP写了一个测试页面:

<?php
require_once 'lib/Braintree.php';

Braintree_Configuration::environment('production');
Braintree_Configuration::merchantId('mymid');
Braintree_Configuration::publicKey('mypubkey');
Braintree_Configuration::privateKey('myprodkey');

$bt_challenge = "";
if(isset($_GET['bt_challenge']))
{
    $bt_challenge = $_GET['bt_challenge'];
}


?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <title>Webhooks</title>
  <meta name="viewport" content="width=device-width; initial-scale=1.0" />
</head>
<body>
<?php
if(isset($bt_challenge) && $bt_challenge != ""){
    echo Braintree_WebhookNotification::verify($bt_challenge);
}
?>
</body>
</html>

但是,这也未能通过验证。不确定出了什么问题,因为没有测试来验证或没有任何迹象表明出了什么问题。我尝试联系 BrainTree 支持人员,但没有得到回复。

最佳答案

需要返回结果

Braintree_WebhookNotification::verify($bt_challenge);

作为body of the response ,而不是 HTML 文档的正文,而 HTML 文档的正文又是响应的正文。换句话说,您的整个文件应该类似于:

<?php
require_once 'lib/Braintree.php';

Braintree_Configuration::environment('production');
Braintree_Configuration::merchantId('mymid');
Braintree_Configuration::publicKey('mypubkey');
Braintree_Configuration::privateKey('myprodkey');

$bt_challenge = "";
if(isset($_GET['bt_challenge']))
{
    $bt_challenge = $_GET['bt_challenge'];
}
if(isset($bt_challenge) && $bt_challenge != ""){
    echo Braintree_WebhookNotification::verify($bt_challenge);
}
?>

如果您还有任何疑问,请随时联系Braintree Support .

披露:我在 Braintree 工作。

关于php - 如何处理 BrainTree 中的 Webhooks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12461094/

相关文章:

json - 如何在 Ubuntu webhook 命令上设置 webhook 密码?

node.js - 处理ExpressJS中混合的同步和异步错误的最佳方法

php - 执行 PDO 删除语句时遇到问题

php - 数据表:根据单元格更改行颜色

javascript - 如何将低分辨率图像转换为 CSS 中的背景渐变?

php - 如何获取 Instagram 评论父 ID 并确定它是顶级还是回复

php - QuickBooks webhooks 在本地与 ngrok 一起工作,但不能在生产中工作

android - 之前添加的卡如何进行多次支付?

javascript - 尝试将 Braintree 嵌套回调转换为 NodeJS 异步/等待语法

php - 如何在服务器端执行 future 付款