我想使用BrainTree webhooks進行訂閱交易,但一直無法讓我的頁面進行驗證。如何處理BrainTree中的Webhooks
布倫特裏:https://www.braintreepayments.com/docs/php/webhooks/destination_verification
當您嘗試添加的目的地,我們的服務器將GET請求提供的網址與命名bt_challenge查詢參數。這個查詢參數應該被傳遞給驗證方法。調用此方法的結果應作爲響應的主體返回。
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支持,但沒有迴應。
謝謝,現在這個工作。 –