src/EventSubscriber/SendCodWithdrawalEmailEventSubscriber.php line 29

  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\SendCodWithdrawalEmailEvent;
  4. use App\Event\SendEmailEvent;
  5. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class SendCodWithdrawalEmailEventSubscriber implements EventSubscriberInterface
  8. {
  9.     public function __construct(private  EventDispatcherInterface $eventDispatcher,
  10.                                 private string $fromEmail, private string $fromName,
  11.                                 private string $accountantEmail)
  12.     {
  13.     }
  14.     public static function getSubscribedEvents()
  15.     {
  16.         return [
  17.             SendCodWithdrawalEmailEvent::NAME => [
  18.                 ['handleCodWithdrawalEmail'10]
  19.             ]
  20.         ];
  21.     }
  22.     public function handleCodWithdrawalEmail(SendCodWithdrawalEmailEvent $event)
  23.     {
  24.         $codWithdrawal $event->getCashOnDeliveryWithdrawal();
  25.         $emailParameters = [
  26.             'from' => [
  27.                 'email' => $this->fromEmail,
  28.                 'name' => $this->fromName
  29.             ],
  30.             'to' => [
  31.                 'email' => $this->accountantEmail
  32.             ],
  33.             'subject' => 'COD Withdrawal Request',
  34.             'template' => 'cash_on_delivery/cod_withdrawal_email.html.twig',
  35.             'parameters' => [
  36.                 'codWithdrawal' => $codWithdrawal
  37.             ]
  38.         ];
  39.         $emailEvent =  new SendEmailEvent($emailParameters);
  40.         $this->eventDispatcher->dispatch($emailEventSendEmailEvent::NAME);
  41.     }
  42. }