ockle / gocardless-webhook
Process webhooks from GoCardless
Installs: 1 059
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 2
Open Issues: 0
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-12-17 05:47:59 UTC
README
A PHP library to aid is the processing of webhooks from GoCardless (see API documentation for more information).
Installation
Install the library using Composer. Add the following to your composer.json:
{ "require": { "ockle/gocardless-webhook": "~1.0" } }
and then run:
composer update ockle/gocardless-webhook
Usage
Instantaiate a new webhook service:
// $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);
Then attach event listeners, e.g.:
$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(); });
Next, process the webhook, which will trigger your event listeners as necessary:
$webhook->process($webhookSignatureFromHeaders, $rawPostBody);
Finally, return the correct HTTP status code is your response, which can be got by calling:
$webhook->getResponseStatus();
License
MIT