vimeo / payment-gateway-logger
Logging capabilities for Omnipay gateways
Installs: 143 083
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 17
Forks: 5
Open Issues: 1
Requires
- guzzlehttp/guzzle: ^6.5|^7.8
- omnipay/common: ^3.0
- psr/log: ^1.0
Requires (Dev)
- omnipay/tests: 3.0
This package is auto-updated.
Last update: 2024-12-10 23:49:01 UTC
README
Package is installed via Composer. To install, simply add it to your composer.json
file:
{ "require": { "vimeo/payment-gateway-logger": "^1.0" } }
And run composer to update your dependencies:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update
Usage
Logging capabilities for Omnipay gateways via an EventSubscriberInterface
subscriber for Omnipay payment gateway-specific events.
These events are dispatched via the HTTP client's EventDispatcherInterface
.
-
The omnipay gateway needs to be updated to emit any of the
RequestEvent
,ResponseEvent
orErrorEvent
objects. For example in the gateway'ssendData()
methods we can do:$event_dispatcher = $this->httpClient->getEventDispatcher(); $event_dispatcher->dispatch(Constants::OMNIPAY_REQUEST_BEFORE_SEND, new RequestEvent($request));
Logging Errors and Responses events can be emitted like so
$event_dispatcher->dispatch(Constants::OMNIPAY_REQUEST_ERROR new ErrorEvent($exception, $request)); $event_dispatcher->dispatch(Constants::OMNIPAY_RESPONSE_SUCCESS, new ResponseEvent($response));
OmnipayGatewayRequestSubscriber.php
takes in a logger of type LoggerInterface
which will listen to and log these events.
The subscriber can be set up to listen to these events when instantiating the HTTP client for the gateway like so:
$httpClient = new GuzzleClient(); $gateway = Omnipay::create('Vindicia', $httpClient); $eventDispatcher = $httpClient->getEventDispatcher(); $eventDispatcher->addSubscriber(new OmnipayGatewayRequestSubscriber($gateway_name, new LoggerClassThatImplementsPSRInterface()));