mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 21:52:55 +08:00
add general log information for handled webhook
This commit is contained in:
parent
423c4bbfd4
commit
c60b225c3b
2 changed files with 20 additions and 3 deletions
|
@ -21,7 +21,9 @@ return [
|
|||
},
|
||||
'webhook.endpoint.controller' => function(ContainerInterface $container) : IncomingWebhookEndpoint {
|
||||
$handler = $container->get('webhook.endpoint.handler');
|
||||
return new IncomingWebhookEndpoint(... $handler);
|
||||
$logger = $container->get('woocommerce.logger.woocommerce');
|
||||
|
||||
return new IncomingWebhookEndpoint($logger, ... $handler);
|
||||
},
|
||||
'webhook.endpoint.handler' => function(ContainerInterface $container) : array {
|
||||
$logger = $container->get('woocommerce.logger.woocommerce');
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Inpsyde\PayPalCommerce\Webhooks;
|
|||
|
||||
|
||||
use Inpsyde\PayPalCommerce\Webhooks\Handler\RequestHandler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class IncomingWebhookEndpoint
|
||||
{
|
||||
|
@ -12,9 +13,11 @@ class IncomingWebhookEndpoint
|
|||
public const NAMESPACE = 'paypal/v1';
|
||||
public const ROUTE = 'incoming';
|
||||
private $handlers;
|
||||
public function __construct(RequestHandler ...$handlers)
|
||||
private $logger;
|
||||
public function __construct(LoggerInterface $logger, RequestHandler ...$handlers)
|
||||
{
|
||||
$this->handlers = $handlers;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function register() : bool
|
||||
|
@ -41,7 +44,19 @@ class IncomingWebhookEndpoint
|
|||
*/
|
||||
foreach ($this->handlers as $handler) {
|
||||
if ($handler->responsibleForRequest($request)) {
|
||||
return $handler->handleRequest($request);
|
||||
$response = $handler->handleRequest($request);
|
||||
$this->logger->log(
|
||||
'info',
|
||||
sprintf(
|
||||
__('Webhook has been handled by %s', 'woocommerce-paypal-commerce-gateway'),
|
||||
$handler->eventType()
|
||||
),
|
||||
[
|
||||
'request' => $request,
|
||||
'response' => $response,
|
||||
]
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue