src/EventListener/IdentificationListener.php line 74

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Domain\Event\Identification;
  4. use App\Entity\BankUser;
  5. use App\Repository\BankUserRepository;
  6. use App\Services\Clients\ClientSystemState\ClientSystemStateService;
  7. use App\Services\Clients\Identification\Idenfy\ClientDocumentService;
  8. use App\Services\Clients\Shareholder\ShareholderService;
  9. use App\Services\CommunicationService;
  10. use App\Utils\KafkaNotifier;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class IdentificationListener implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var LoggerInterface
  17.      */
  18.     private $logger;
  19.     /**
  20.      * @var CommunicationService
  21.      */
  22.     private $communicationService;
  23.     /**
  24.      * @var KafkaNotifier
  25.      */
  26.     private $kafkaNotifier;
  27.     /**
  28.      * @var BankUserRepository
  29.      */
  30.     private $bankUserRepository;
  31.     /**
  32.      * @var ClientSystemStateService
  33.      */
  34.     private $systemStateService;
  35.     /**
  36.      * @var ShareholderService
  37.      */
  38.     private $shareholderService;
  39.     public function __construct(
  40.         CommunicationService $communicationService,
  41.         LoggerInterface $logger,
  42.         KafkaNotifier $kafkaNotifier,
  43.         BankUserRepository $bankUserRepository,
  44.         ClientSystemStateService $systemStateService,
  45.         ShareholderService $shareholderService
  46.     ) {
  47.         $this->communicationService $communicationService;
  48.         $this->logger $logger;
  49.         $this->kafkaNotifier $kafkaNotifier;
  50.         $this->bankUserRepository $bankUserRepository;
  51.         $this->systemStateService $systemStateService;
  52.         $this->shareholderService $shareholderService;
  53.     }
  54.     public function processClientSystemState(Identification $event)
  55.     {
  56.         $client $event->getClient();
  57.         $this->systemStateService->processClientSystemState($client);
  58.         $verificationStatus $event->getVerificationStatus();
  59.         if ($client->isPerson()) {
  60.             $this->shareholderService->setShareholderState($client->getPerson(), $verificationStatus);
  61.         }
  62.     }
  63.     public function sendSMS(Identification $event)
  64.     {
  65.         if ($event->getVerificationStatus() == ClientDocumentService::STATUS_APPROVED) {
  66.             $client $event->getClient();
  67.             $this->communicationService->sendSmsIfConfirmedIdentifyMessage($client);
  68.         }
  69.     }
  70.     public function sendClientRecheck(Identification $event)
  71.     {
  72.         $client $event->getClient();
  73.         $systemUser $this->bankUserRepository->findByUsername(BankUser::SYSTEM_USER);
  74.         $requestingUserId $systemUser $systemUser->getId() : null;
  75.         $this->kafkaNotifier->sendClientRecheck($client->getId(), $requestingUserId);
  76.     }
  77.     public static function getSubscribedEvents()
  78.     {
  79.         return [
  80.             Identification::IDENTIFICATION_EVENT => [['processClientSystemState'], ['sendSMS'], ['sendClientRecheck']],
  81.         ];
  82.     }
  83. }