ockle / gocardless-webhook
处理GoCardless的webhook
v1.0.3
2017-01-27 22:32 UTC
Requires
- php: >=5.6
- symfony/event-dispatcher: ^2.7||^3.0
Requires (Dev)
- mockery/mockery: ^0.9
- phpunit/phpunit: ^5.7
- satooshi/php-coveralls: ^1.0
This package is not auto-updated.
Last update: 2024-09-24 04:28:19 UTC
README
一个PHP库,用于辅助处理GoCardless的webhook(更多信息请参阅API文档)。
安装
使用Composer安装库。将以下内容添加到您的composer.json文件中
{ "require": { "ockle/gocardless-webhook": "~1.0" } }
然后运行
composer update ockle/gocardless-webhook
使用
实例化一个新的webhook服务
// $secret is the string entered in the GoCardless admin when setting up a webhook endpoint $webhook = new \Ockle\GoCardlessWebhook\Service($secret, new \Symfony\Component\EventDispatcher\EventDispatcher);
然后附加事件监听器,例如
$webhook->onMandate(function (\Ockle\GoCardlessWebhook\Events\MandateEvent $event) use ($client) { // Do stuff when a mandate event occurs // You can check what the action is: if ($event->actionIs(\Ockle\GoCardlessWebhook\Events\MandateEvent::ACTION_CREATED)) { // Mandate has been created } // However, it is advised that you don't do any important business logic based off this, but // rather do an API call to get the current status of the mandate and act on that as the accurate // source of mandate information. This is due to the fact that events may be received in any order. // There are methods to get information about the event, e.g.: $mandateId = $event->getMandateId(); });
接下来,处理webhook,这将根据需要触发事件监听器
$webhook->process($webhookSignatureFromHeaders, $rawPostBody);
最后,通过调用以返回正确的HTTP状态码作为响应
$webhook->getResponseStatus();
许可证
MIT