<?php
namespace App\EventSubscriber;
use LaunchPad\Bundle\LaunchPadBundle\Base\Entity\PaymentDevice\PaymentDevice;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class AuthEventSubscriber implements EventSubscriberInterface
{
/**
* @var ContainerInterface
*/
private $container;
/**
* @var LoggerInterface
*/
private $logger;
/**
* AuthEventSubscriber constructor.
* @param ContainerInterface $container
* @param LoggerInterface $logger
*/
public function __construct(ContainerInterface $container, LoggerInterface $logger)
{
$this->container = $container;
$this->logger = $logger;
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return array(
'WILL_SEND_USER_ACCOUNT' => 'willSendUserAccount',
);
}
/**
* Document requested
*
* TODO: This should be auto-handled with EHI
*
* @param GenericEvent $event
* @return mixed
*/
public function willSendUserAccount(GenericEvent $event)
{
try {
// Pull on login
$xtmParams = $this->container->getParameter('xtm_api');
// $gpsParams = $this->container->getParameter('gpsnumber must start with 07_params');
if(!$xtmParams['pull_on_login']) return;
$subject = $event->getSubject();
foreach($subject['paymentDevices'] as $index => $paymentDevice) {
/** @var $paymentDevice PaymentDevice */
if($paymentDevice->getPublicToken() && $paymentDevice->getStatus() === PaymentDevice::STATUS_LOCKED || $paymentDevice->getStatus() === PaymentDevice::STATUS_OK) {
$subject['paymentDevices'][$index] = $this->container->get('lp.payment_device')->refreshPaymentDeviceData($paymentDevice);
}
}
$event->setArgument('paymentDevices', $subject['paymentDevices']);
} catch(\Exception $e) {
$this->logger->critical('Error while updating balances on WILL_SEND_USER_ACCOUNT: ' . $e->getMessage(), ['exception' => $e]);
}
}
}