diff --git a/Components/Builder/NotificationBuilder.php b/Components/Builder/NotificationBuilder.php index 7c9fd88a..9f3108be 100644 --- a/Components/Builder/NotificationBuilder.php +++ b/Components/Builder/NotificationBuilder.php @@ -94,6 +94,35 @@ public function fromParams($params) $notification->setErrorDetails($params['reason']); } + if (isset($params['eventCode']) && isset($params['success'])) { + $notification->setScheduledProcessingTime($this->getProcessingTime($notification)); + } + return $notification; } + + /** + * Set delay in processing time for certain notifications. + * + * @param Notification $notification + * @return \DateTime + */ + private function getProcessingTime(Notification $notification): \DateTime + { + $processingTime = new \DateTime(); + switch ($notification->getEventCode()) { + case 'AUTHORISATION': + if (!$notification->isSuccess()) { + $processingTime = $processingTime->add(new \DateInterval('PT30M')); + } + break; + case 'OFFER_CLOSED': + $processingTime = $processingTime->add(new \DateInterval('PT30M')); + break; + default: + break; + } + + return $processingTime; + } } diff --git a/Components/NotificationManager.php b/Components/NotificationManager.php index 678078e4..73d28019 100644 --- a/Components/NotificationManager.php +++ b/Components/NotificationManager.php @@ -49,9 +49,11 @@ public function getNextNotificationToHandle() { $builder = $this->notificationRepository->createQueryBuilder('n'); $builder->where("n.status = :statusReceived OR n.status = :statusRetry") + ->where('(n.scheduledProcessingTime <= :processingTime OR n.scheduledProcessingTime IS NULL)') ->orderBy('n.updatedAt', 'ASC') ->setParameter('statusReceived', NotificationStatus::STATUS_RECEIVED) ->setParameter('statusRetry', NotificationStatus::STATUS_RETRY) + ->setParameter('processingTime', new \DateTime()) ->setMaxResults(1); return $builder->getQuery()->getSingleResult(); diff --git a/Models/Notification.php b/Models/Notification.php index 042555bc..cb9ed1ee 100644 --- a/Models/Notification.php +++ b/Models/Notification.php @@ -52,6 +52,12 @@ class Notification extends ModelEntity implements \JsonSerializable */ private $updatedAt; + /** + * @var \DateTime + * @ORM\Column(name="scheduled_processing_time", type="datetime", nullable=true) + */ + private $scheduledProcessingTime; + /** * @var string * @ORM\Column(name="status", type="text") @@ -217,6 +223,24 @@ public function setUpdatedAt(\DateTime $updatedAt): Notification return $this; } + /** + * @return \DateTime + */ + public function getScheduledProcessingTime(): \DateTime + { + return $this->scheduledProcessingTime; + } + + /** + * @param \DateTime $scheduledProcessingTime + * @return Notification + */ + public function setScheduledProcessingTime(\DateTime $scheduledProcessingTime): Notification + { + $this->scheduledProcessingTime = $scheduledProcessingTime; + return $this; + } + /** * @return string */