【问题标题】:How does one handle Webhooks in BrainTree如何处理 BrainTree 中的 Webhook
【发布时间】:2012-09-17 14:09:51
【问题描述】:

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

来自 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 支持,但没有回复。

【问题讨论】:

    标签: php webhooks braintree


    【解决方案1】:

    你需要返回

    的结果
    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 工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 2020-08-09
      • 2018-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-07
      相关资源
      最近更新 更多