<?php
namespace LaunchPad\Bundle\LaunchPadBundle\Base\EventSubscriber\Kyc;
use LaunchPad\Bundle\LaunchPadBundle\Admin\Service\UserAdminService;
use LaunchPad\Bundle\LaunchPadBundle\Base\Entity\KYC\KycProcess;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\Notifications\NotificationTypes\KYC\KycSuccessfulNotification;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class KycEventSubscriber implements EventSubscriberInterface
{
/** @var ContainerInterface */
private $container;
/**
* KycEventSubscriber constructor.
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
const KYC_DOCUMENT_REQUESTED = 'kyc.document.requested';
const KYC_ACCEPTED = 'kyc.accepted';
const KYC_REJECTED = 'kyc.rejected';
/**
* Get subscribed events
*
* @return array
*/
public static function getSubscribedEvents()
{
return array(
UserAdminService::EVENT_USER_CREATED => 'userCreated',
self::KYC_DOCUMENT_REQUESTED => 'documentRequested',
self::KYC_ACCEPTED => 'kycAccepted',
self::KYC_REJECTED => 'kycRejected',
);
}
/**
* Document requested
*
* @param GenericEvent $event
*/
public function documentRequested(GenericEvent $event)
{
}
/**
* Called when new user is created
*
* @param GenericEvent $event
*/
public function userCreated(GenericEvent $event)
{
$this->container->get('lp.kyc')->handleNewUser($event->getSubject());
}
/**
* KYC accepted
*
* @param GenericEvent $event
* @throws \Exception
*/
public function kycAccepted(GenericEvent $event)
{
/** @var KycProcess $process */
$process = $event->getSubject();
if($process->getOrigin() == KycProcess::KYC_ORIGIN_REGISTRATION) {
$this->container->get('lp.account')->userKYCed($process->getUser());
$this->container->get('lp.notifications')->push($process->getUser(), new KycSuccessfulNotification($process));
}
}
/**
* KYC rejected
*
* @param GenericEvent $event
*/
public function kycRejected(GenericEvent $event)
{
}
}