1

任何人都可以在php中为我提供一个braintree webhook的工作示例。我使用下面提到的代码来验证我的链接,它工作正常:

require_once 'braintree-php-2.22.0/lib/Braintree.php';

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('jmvhd879pf68kfk8');
Braintree_Configuration::publicKey('cfywtwxy8bxmwtkn');
Braintree_Configuration::privateKey('ad3f3b6e9c8b8186c1204a0f533899da');

$bt_challenge_param = $_GET['bt_challenge'];
echo $response = Braintree_WebhookNotification::verify($bt_challenge_param);

但是当我在同一页面上编写下面提到的代码时,即使付款成功,它也不会写入文件(文本文件路径没有问题):

require_once 'braintree-php-2.22.0/lib/Braintree.php';

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('jmvhd879pf68kfk8');
Braintree_Configuration::publicKey('cfywtwxy8bxmwtkn');
Braintree_Configuration::privateKey('ad3f3b6e9c8b8186c1204a0f533899da');

/*$bt_challenge_param = $_GET['bt_challenge'];
echo $response = Braintree_WebhookNotification::verify($bt_challenge_param);*/
$notification = Braintree_WebhookNotification::parse(
$_POST['bt_signature'],
$_POST['bt_payload']
);
$notification->kind == Braintree_WebhookNotification::SUB_MERCHANT_ACCOUNT_APPROVED;
$date = date('Y-m-d h:i:s');
$file = fopen("log.txt","w");
fwrite($file,$date."\r\n");
fwrite($file,$notification->merchantAccount->status."\r\n");
fwrite($file,$notification->merchantAccount->id."\r\n");
fwrite($file,$notification->merchantAccount->masterMerchantAccount->id."\r\n");
fwrite($file,$notification->merchantAccount->masterMerchantAccount->status."\r\n");
fwrite($file,"\r\n\r\n\r\n\r\n\r\n\r\n");
fclose($file);
4

1 回答 1

2

我在布伦特里工作。如果您需要的信息多于您在 Stack Overflow 上无法轻松获取的信息,请联系我们的支持团队

我们为每个客户端库(包括 PHP)提供了 webhook 指南

简要地:

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 . " | "
        . "Subscription: " . $webhookNotification->subscription->id . "\n";

    file_put_contents("/tmp/webhook.log", $message, FILE_APPEND);
}
于 2013-08-19T16:19:49.293 回答