diff --git a/src/DependencyInjection/webhooks.xml b/src/DependencyInjection/webhooks.xml index 72fd3ba10..8fc2bcb32 100644 --- a/src/DependencyInjection/webhooks.xml +++ b/src/DependencyInjection/webhooks.xml @@ -30,7 +30,8 @@ - + + diff --git a/src/Payone/Webhook/MessageBus/MessageHandler/NotificationForwardHandler.php b/src/Payone/Webhook/MessageBus/MessageHandler/NotificationForwardHandler.php index 6813952e9..3523f8cc1 100644 --- a/src/Payone/Webhook/MessageBus/MessageHandler/NotificationForwardHandler.php +++ b/src/Payone/Webhook/MessageBus/MessageHandler/NotificationForwardHandler.php @@ -4,21 +4,23 @@ namespace PayonePayment\Payone\Webhook\MessageBus\MessageHandler; +use Monolog\Level; +use Monolog\Logger; use PayonePayment\DataAbstractionLayer\Entity\NotificationForward\PayonePaymentNotificationForwardEntity; use PayonePayment\DataAbstractionLayer\Entity\NotificationTarget\PayonePaymentNotificationTargetEntity; use PayonePayment\Payone\Webhook\MessageBus\Command\NotificationForwardCommand; -use Psr\Log\LoggerInterface; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Messenger\Handler\MessageSubscriberInterface; class NotificationForwardHandler implements MessageSubscriberInterface { public function __construct( private readonly EntityRepository $notificationForwardRepository, - private readonly LoggerInterface $logger + private readonly Logger $logger ) { } @@ -52,6 +54,14 @@ public function handle(NotificationForwardCommand $message): void $this->updateResponses($multiHandle, $notificationForwards, $forwardRequests, $message->getContext()); + foreach ($forwardRequests as $id => $handle) { + $responseInfo = curl_getinfo($handle); + $responseContent = curl_multi_getcontent($handle); + $this->statusLogger($responseInfo, $responseContent, $id); + curl_multi_remove_handle($multiHandle, $handle); + curl_close($handle); + } + curl_multi_close($multiHandle); } @@ -149,4 +159,23 @@ private function buildHeaders( return $headers; } + + private function statusLogger(array $responseInfo, ?string $responseContent, string $id): void + { + $statusCode = $responseInfo['http_code']; + + $response = new Response($responseContent, $statusCode, $responseInfo); + $logLevel = $response->isSuccessful() ? 'info' : 'error'; + $statusText = Response::$statusTexts[$statusCode] ?? 'Unknown Status Code'; + + $this->logger->addRecord( + Level::fromName($logLevel), + 'Forwarding notification - ' . $statusText, + [ + 'id' => $id, + 'information' => $responseInfo, + 'content' => $response->getContent(), + ] + ); + } } diff --git a/src/PayonePayment.php b/src/PayonePayment.php index 758e6e9ba..82357a91c 100644 --- a/src/PayonePayment.php +++ b/src/PayonePayment.php @@ -19,9 +19,14 @@ use Shopware\Core\Framework\Plugin\Util\PluginIdProvider; use Shopware\Core\System\SystemConfig\SystemConfigService; use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Loader\DelegatingLoader; +use Symfony\Component\Config\Loader\LoaderResolver; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; +use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; class PayonePayment extends Plugin { @@ -33,6 +38,19 @@ public function build(ContainerBuilder $container): void $loader->load('services.xml'); parent::build($container); + + $locator = new FileLocator('Resources/config'); + + $resolver = new LoaderResolver([ + new YamlFileLoader($container, $locator), + new GlobFileLoader($container, $locator), + new DirectoryLoader($container, $locator), + ]); + + $configLoader = new DelegatingLoader($resolver); + + $confDir = \rtrim($this->getPath(), '/') . '/Resources/config'; + $configLoader->load($confDir . '/{packages}/*.yaml', 'glob'); } public function install(InstallContext $installContext): void diff --git a/src/Resources/config/packages/monolog.yaml b/src/Resources/config/packages/monolog.yaml new file mode 100644 index 000000000..ccb17e145 --- /dev/null +++ b/src/Resources/config/packages/monolog.yaml @@ -0,0 +1,9 @@ +monolog: + channels: [ "payone_transaction_forward" ] + + handlers: + payoneTransactionForwardLogger: + type: rotating_file + path: "%kernel.logs_dir%/payone_transaction_forward.log" + level: info + channels: [ "payone_transaction_forward" ]