src/EventSubscriber/ProcedureInvoicePaidSubscriber.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\EventSubscriber;
  4. use App\Event\ProcedureInvoicePaidEvent;
  5. use App\Events;
  6. use App\Service\EmailParametersGenerator;
  7. use App\Service\Sendinblue\SMTPApi;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class ProcedureInvoicePaidSubscriber implements EventSubscriberInterface
  10. {
  11.     public const EMAIL_TEMPLATE_ID '25'// TODO: change this to the correct paid template - NOT READY YET
  12.     /**
  13.      * @var EmailParametersGenerator
  14.      */
  15.     protected $parametersGenerator;
  16.     /**
  17.      * @var SMTPApi
  18.      */
  19.     protected $smtp;
  20.     public function __construct(EmailParametersGenerator $parametersGeneratorSMTPApi $smtp)
  21.     {
  22.         $this->parametersGenerator $parametersGenerator;
  23.         $this->smtp                $smtp;
  24.     }
  25.     /**
  26.      * @param ProcedureInvoicePaidEvent $event
  27.      */
  28.     public function onInvoicePaid(ProcedureInvoicePaidEvent $event): void
  29.     {
  30.         $procedure $event->getProcedure();
  31.         $invoice   $procedure->getInvoice();
  32.         $parameters $this->parametersGenerator->generateForProcedureStep($procedure->getDispatchedStep(), $invoice->getAccountLocale());
  33.         $contacts $invoice->getActiveAccountContacts();
  34.         if ($contacts->isEmpty()) {
  35.             $this->smtp->send(
  36.                 $invoice->getCreditorName(),
  37.                 $invoice->getCreditorEmail(),
  38.                 self::EMAIL_TEMPLATE_ID,
  39.                 $parameters,
  40.                 []
  41.             );
  42.         } else {
  43.             $this->smtp->sendToContacts(
  44.                 $contacts,
  45.                 self::EMAIL_TEMPLATE_ID,
  46.                 $parameters,
  47.                 []
  48.             );
  49.         }
  50.     }
  51.     /**
  52.      * @inheritDoc
  53.      */
  54.     public static function getSubscribedEvents()
  55.     {
  56.         return [
  57.             Events::PROCEDURE_INVOICE_PAID => 'onInvoicePaid'
  58.         ];
  59.     }
  60. }