<?php
namespace LaunchPad\Bundle\LaunchPadBundle\Base\EventSubscriber\Transaction;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class TransactionEventSubscriber implements EventSubscriberInterface
{
const EVENT_TRANSACTIONS_PARSED = 'lp.event.transactions.parsed';
const EVENT_TRANSACTION_PROCESSED = 'lp.event.transaction.processed';
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public static function getSubscribedEvents()
{
return array(
self::EVENT_TRANSACTIONS_PARSED => 'transactionsParsed',
self::EVENT_TRANSACTION_PROCESSED => 'transactionsProcessed'
);
}
/**
* Transactions parsed
*
* @param GenericEvent $event
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function transactionsParsed(GenericEvent $event)
{
$subject = $event->getSubject();
$transactions = $subject['transactions'];
$isRealTime = @$subject['isRealTime'];
if($isRealTime) {
$this->container->get('lp.transaction')->sendNotifications($transactions);
}
}
/**
* Transactions processed
*
* @param GenericEvent $event
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function transactionsProcessed(GenericEvent $event)
{
$subject = $event->getSubject();
$transaction = $subject;
// Handle exchange for the transaction
$this->container->get('lp.transaction')->handleTransactionExchange($transaction);
}
/**
* Document requested
*
* @param GenericEvent $event
*/
public function onImportDone(GenericEvent $event)
{
}
}