如何在BrainTree中处理Webhooks [英] How does one handle Webhooks in BrainTree

查看:63
本文介绍了如何在BrainTree中处理Webhooks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use the BrainTree webhooks for subscription transactions but have been unable to get my page to verify.

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

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

当您尝试添加目标时,我们的服务器将使用名为bt_challenge的查询参数对提供的URL进行GET请求.该查询参数应传递给verify方法.调用此方法的结果应作为响应的正文返回.

When you attempt to add the destination, our servers will make a GET request to the provided URL with a query param named bt_challenge. This query param should be passed to the verify method. The result of calling this method should be returned as the body of the response.

Braintree_WebhookNotification::verify(bt_challenge_param);

首先,我在NodeJS中尝试过(因为我们的交易已成功完成):

First, I tried in NodeJS (as our transactions are successfully done this way):

//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中编写一个测试页:

where my PHP page communicated with the NodeJS process and puts the result in the body. Once this failed verification, I wrote a test page directly in 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支持人员,但没有回复.

However, this too failed verification. Not sure what is wrong as there is no test for verification or any indication of what is wrong. I tried contacting BrainTree support but with no response back.

推荐答案

您需要返回

Braintree_WebhookNotification::verify($bt_challenge);

作为响应正文,而不是HTML文档的正文反过来又是响应的主体.换句话说,您的整个文件应类似于:

as the body of the response, not the body of an HTML document that is in turn the body of the response. In other words, your entire file should be something like:

<?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支持联系.

If you have any more questions, please feel free to reach out to Braintree Support.

披露:我在Braintree工作.

Disclosure: I work at Braintree.

这篇关于如何在BrainTree中处理Webhooks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆