Skip to content

Commit

Permalink
NTR: fix webhook too early
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalij Mik committed Dec 16, 2024
1 parent 3f36a44 commit e15eb8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Controller/Storefront/Webhook/NotificationFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,16 @@ public function onNotify(string $swTransactionId, Context $context): void
}

$now = new \DateTime('now', new DateTimeZone('UTC'));

/** @var ?\DateTimeImmutable $orderCreatedAt */
$orderCreatedAt = $swOrder->getCreatedAt();

if ($orderCreatedAt !== null) {
$createdAt = \DateTime::createFromImmutable($orderCreatedAt);
$createdAt->modify('+2 minutes');
if ($now < $orderCreatedAt) {
throw new WebhookIsTooEarlyException((string)$swOrder->getOrderNumber(), $now, $orderCreatedAt);

if ($now < $createdAt) {
throw new WebhookIsTooEarlyException((string)$swOrder->getOrderNumber(), $now, $createdAt);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/WebhookIsTooEarlyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class WebhookIsTooEarlyException extends ShopwareHttpException
public const MOLLIE_PAYMENTS__WEBHOOK_TOO_EARLY = 'MOLLIE_PAYMENTS__WEBHOOK_TOO_EARLY';
public function __construct(string $oderNumber, \DateTimeInterface $now, \DateTimeInterface $updatedTime)
{
$message = 'Webhook is too early for order: {{orderNumber}}. Request will be accepted after: {{lastUpdateTime}}';
$message = 'Webhook is too early for order: {{orderNumber}}. Request will be accepted after: {{lastUpdateTime}}. Current Time is :{{now}}';
$parameters =[
'orderNumber' => $oderNumber,
'lastUpdateTime' => $updatedTime->format('Y-m-d H:i:s'),
Expand Down

0 comments on commit e15eb8f

Please sign in to comment.