Skip to content

Commit

Permalink
Merge pull request #142 from Adyen/PW-4149
Browse files Browse the repository at this point in the history
[PW-4149] add processing time to notifications
  • Loading branch information
peterojo authored Mar 1, 2021
2 parents 777a96a + 94061d3 commit 0e509ba
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Components/Builder/NotificationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions Components/NotificationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
24 changes: 24 additions & 0 deletions Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 0e509ba

Please sign in to comment.