src/EventSubscriber/SendCodWithdrawalEmailEventSubscriber.php line 29
<?php
namespace App\EventSubscriber;
use App\Event\SendCodWithdrawalEmailEvent;
use App\Event\SendEmailEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class SendCodWithdrawalEmailEventSubscriber implements EventSubscriberInterface
{
public function __construct(private EventDispatcherInterface $eventDispatcher,
private string $fromEmail, private string $fromName,
private string $accountantEmail)
{
}
public static function getSubscribedEvents()
{
return [
SendCodWithdrawalEmailEvent::NAME => [
['handleCodWithdrawalEmail', 10]
]
];
}
public function handleCodWithdrawalEmail(SendCodWithdrawalEmailEvent $event)
{
$codWithdrawal = $event->getCashOnDeliveryWithdrawal();
$emailParameters = [
'from' => [
'email' => $this->fromEmail,
'name' => $this->fromName
],
'to' => [
'email' => $this->accountantEmail
],
'subject' => 'COD Withdrawal Request',
'template' => 'cash_on_delivery/cod_withdrawal_email.html.twig',
'parameters' => [
'codWithdrawal' => $codWithdrawal
]
];
$emailEvent = new SendEmailEvent($emailParameters);
$this->eventDispatcher->dispatch($emailEvent, SendEmailEvent::NAME);
}
}