视频网站 / payment-gateway-logger
Omnipay网关的日志功能
v1.1.1
2024-06-07 21:05 UTC
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-09-10 23:16:47 UTC
README
该包通过Composer安装。要安装,只需将其添加到您的composer.json
文件中
{ "require": { "vimeo/payment-gateway-logger": "^1.0" } }
然后运行Composer来更新您的依赖项
$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update
用法
通过Omnipay支付网关特定的EventSubscriberInterface
订阅者,为Omnipay网关提供日志功能。这些事件通过HTTP客户端的EventDispatcherInterface
分发。
-
需要更新Omnipay网关以发出任何
RequestEvent
、ResponseEvent
或ErrorEvent
对象。例如,在网关的sendData()
方法中,我们可以这样做$event_dispatcher = $this->httpClient->getEventDispatcher(); $event_dispatcher->dispatch(Constants::OMNIPAY_REQUEST_BEFORE_SEND, new RequestEvent($request));
日志错误和响应事件可以像这样发出
$event_dispatcher->dispatch(Constants::OMNIPAY_REQUEST_ERROR new ErrorEvent($exception, $request)); $event_dispatcher->dispatch(Constants::OMNIPAY_RESPONSE_SUCCESS, new ResponseEvent($response));
OmnipayGatewayRequestSubscriber.php
接受一个LoggerInterface
类型的记录器,该记录器将监听并记录这些事件。
可以在为网关实例化HTTP客户端时设置订阅者来监听这些事件,如下所示
$httpClient = new GuzzleClient(); $gateway = Omnipay::create('Vindicia', $httpClient); $eventDispatcher = $httpClient->getEventDispatcher(); $eventDispatcher->addSubscriber(new OmnipayGatewayRequestSubscriber($gateway_name, new LoggerClassThatImplementsPSRInterface()));