From 2d54fbdf887b52d689171abcc4602ab22272ff41 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Tue, 28 Jan 2025 14:48:15 +0100 Subject: [PATCH] NTR: too early debug message instead of warning --- CHANGELOG.md | 2 +- .../Api/Webhook/WebhookControllerBase.php | 13 +++++++++++++ .../Storefront/Webhook/NotificationFacade.php | 1 + .../Storefront/Webhook/WebhookControllerBase.php | 10 ++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b394153e..cf3e2c569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added - - Returns for Shopware Commercial plugins are now transferred to Mollie when the return status is set to "Done" and can be canceled with the "Cancelled" status. Please note that refunds cannot be canceled after two hours. - MB Way payment method is now available for Mollie Payments. - Multibanco payment method is now available for Mollie Payments. @@ -17,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - The minimum supported Shopware version is now 6.4.5.0. - Added a new Monolog channel "mollie." You can now add custom handlers and assign them to the Mollie channel. +- When a webhook from mollie is sent too early to the shop, a debug message is logged instead of a warning. ### Fixed diff --git a/src/Controller/Api/Webhook/WebhookControllerBase.php b/src/Controller/Api/Webhook/WebhookControllerBase.php index 273525a38..2b733ab56 100644 --- a/src/Controller/Api/Webhook/WebhookControllerBase.php +++ b/src/Controller/Api/Webhook/WebhookControllerBase.php @@ -5,6 +5,7 @@ use Kiener\MolliePayments\Components\Subscription\Exception\SubscriptionSkippedException; use Kiener\MolliePayments\Components\Subscription\SubscriptionManager; use Kiener\MolliePayments\Controller\Storefront\Webhook\NotificationFacade; +use Kiener\MolliePayments\Exception\WebhookIsTooEarlyException; use Kiener\MolliePayments\Repository\OrderRepository; use Kiener\MolliePayments\Repository\OrderTransactionRepository; use Psr\Log\LoggerInterface; @@ -13,6 +14,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; class WebhookControllerBase extends AbstractController { @@ -74,6 +76,17 @@ public function webhookAction(string $swTransactionId, Request $request, Context return new JsonResponse([ 'success' => true ]); + } catch (WebhookIsTooEarlyException $exception) { + $this->logger->debug('Webhook too early', [ + ['message' => $exception->getMessage()] + ]); + return new JsonResponse( + [ + 'success' => false, + 'error' => $exception->getMessage() + ], + Response::HTTP_TOO_EARLY + ); } catch (\Throwable $ex) { $this->logger->error( 'Error in Mollie Webhook for Transaction ' . $swTransactionId, diff --git a/src/Controller/Storefront/Webhook/NotificationFacade.php b/src/Controller/Storefront/Webhook/NotificationFacade.php index ffba4371a..2b6fd90fa 100644 --- a/src/Controller/Storefront/Webhook/NotificationFacade.php +++ b/src/Controller/Storefront/Webhook/NotificationFacade.php @@ -132,6 +132,7 @@ public function __construct(MollieGatewayInterface $gatewayMollie, OrderStatusCo /** * @param string $swTransactionId * @param Context $context + * @throws WebhookIsTooEarlyException * @throws CustomerCouldNotBeFoundException * @return void */ diff --git a/src/Controller/Storefront/Webhook/WebhookControllerBase.php b/src/Controller/Storefront/Webhook/WebhookControllerBase.php index ac638fb4b..9556b1412 100644 --- a/src/Controller/Storefront/Webhook/WebhookControllerBase.php +++ b/src/Controller/Storefront/Webhook/WebhookControllerBase.php @@ -5,6 +5,7 @@ use Kiener\MolliePayments\Components\Subscription\Exception\SubscriptionSkippedException; use Kiener\MolliePayments\Components\Subscription\SubscriptionManager; use Kiener\MolliePayments\Controller\Storefront\AbstractStoreFrontController; +use Kiener\MolliePayments\Exception\WebhookIsTooEarlyException; use Kiener\MolliePayments\Repository\OrderRepository; use Kiener\MolliePayments\Repository\OrderTransactionRepository; use Psr\Log\LoggerInterface; @@ -70,6 +71,15 @@ public function onWebhookReceived(SalesChannelContext $context, string $swTransa $this->notificationFacade->onNotify($swTransactionId, $context->getContext()); return new JsonResponse(['success' => true]); + } catch (WebhookIsTooEarlyException $exception) { + $this->logger->debug( + 'Webhook too early', + [ + 'error' => $exception->getMessage() + ] + ); + + return new JsonResponse(['success' => false, 'error' => $exception->getMessage()], $exception->getStatusCode()); } catch (ShopwareHttpException $exception) { $this->logger->warning( 'Warning in Webhook for Transaction ' . $swTransactionId,