src/Invoice/EventSubscriber/SendPaymentNotificationSubscriber.php line 55
<?phpdeclare(strict_types=1);/*** Copyright (c) 2022 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2022 TECLA Consulting Group oü*/namespace App\Invoice\EventSubscriber;use App\Invoice\Event\InvoicePayment\CreatedEvent;use App\Invoice\Query\InvoicePaymentNotification\FindAllSuitableRecipientsQueryInterface;use App\Invoice\Util\InvoicePaymentNotificationMailerInterface;use JetBrains\PhpStorm\ArrayShape;use Psr\Log\LoggerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Throwable;final class SendPaymentNotificationSubscriber implements EventSubscriberInterface{private FindAllSuitableRecipientsQueryInterface $findAllSuitableRecipientsQuery;private InvoicePaymentNotificationMailerInterface $invoicePaymentNotificationMailer;private LoggerInterface $logger;public function __construct(FindAllSuitableRecipientsQueryInterface $findAllSuitableRecipientsQuery,InvoicePaymentNotificationMailerInterface $invoicePaymentNotificationMailer,LoggerInterface $logger) {$this->findAllSuitableRecipientsQuery = $findAllSuitableRecipientsQuery;$this->invoicePaymentNotificationMailer = $invoicePaymentNotificationMailer;$this->logger = $logger;}#[ArrayShape([CreatedEvent::class => 'string'])]public static function getSubscribedEvents(): array{return [CreatedEvent::class => 'onCreated',];}public function onCreated(CreatedEvent $event): void{$invoicePayment = $event->getInvoicePayment();$invoice = $invoicePayment->getInvoice();$supplier = $invoice->getSupplier();$customer = $invoice->getCustomer();$invoicePaymentNotifications = $this->findAllSuitableRecipientsQuery->execute($supplier, $customer);foreach ($invoicePaymentNotifications as $invoicePaymentNotification) {try {$this->invoicePaymentNotificationMailer->send($invoicePaymentNotification->getSubscriber(),$invoicePayment);} catch (Throwable $e) {$this->logger->error('Failed to send invoice payment notification', ['subscriber' => $invoicePaymentNotification->getSubscriber()->getId()->toRfc4122(),'invoicePayment' => $invoicePayment->getId()->toRfc4122(),'exception' => $e,]);}}}}