0

我们使用 Go Cardless 在订阅的基础上收取我们组织成员的付款。每天 Go Cardless 每天都会收集 6 到 40 笔付款,我想在 webhook 中捕获这些付款,以便在会员付款时在我们的数据库上进行标记。

我的 webhook 正在工作,它正在捕获日常事件,但我在他们的文档中找不到如何获取特定客户以识别每笔付款。

有没有人这样做并且有任何示例 PHP 代码?绕圈子,所以任何帮助将不胜感激。


$webhook_endpoint_secret = "*****************************************@()";

$request_body = file_get_contents('php://input');

$headers = getallheaders();
$signature_header = $headers["Webhook-Signature"];

error_log("JQ0 Printing request_body =" . $request_body . "\n");

try {
    $events = \GoCardlessPro\Webhook::parse($request_body,
                                            $signature_header,
                                            $webhook_endpoint_secret);

    foreach ($events as $event) {
        error_log("JQ1 Processing event id =" . $event->id . "\n");

        switch ($event->resource_type) {
            case "mandates":
                error_log("JQ Mandate =" . $event->links->mandate);
                break;
            default:
                error_log("JQ2 Other 'cases' =" . $event->resource_type);
                error_log("JQ2 Processing event id =" . $event->id . "\n");
//              error_log("JQ2 Processing event amount =" . $event->amount . "\n");
                break;
        }
    }

    error_log("JQ - HTTP/1.1 200 OK");
} catch(\GoCardlessPro\Core\Exception\InvalidSignatureException $e) {
    error_log("JQ - HTTP/1.1 498 Invalid Token");
}

样本输出

[16-Dec-2021 11:27:03 Europe/Dublin] @@@@@@@@@ rpsagcwebhook.php - Go Cardless Hook Started
[16-Dec-2021 11:27:03 Europe/Dublin] JQ1 Processing event id =EV027VX8W3WZ1R

[16-Dec-2021 11:27:03 Europe/Dublin] JQ2 Other 'cases' =payments
[16-Dec-2021 11:27:03 Europe/Dublin] JQ2 Processing event id =EV027VX8W3WZ1R

[16-Dec-2021 11:27:03 Europe/Dublin] JQ1 Processing event id =EV027VX8WPHVSN

[16-Dec-2021 11:27:03 Europe/Dublin] JQ - HTTP/1.1 200 OK
[16-Dec-2021 11:27:03 Europe/Dublin] @@@@@@@@@ rpsagcwebhook.php - Go Cardless Hook Finished
4

0 回答 0