<?php
/**
* Author: Vladimir Bykovsky
* Date: 26.11.2021
* Time: 18:00
*/
namespace FMT\Domain\Listener;
use FMT\Data\Entity\Transaction;
use FMT\Data\Entity\UserTransaction;
use FMT\Domain\Event\TransactionEvent;
use FMT\Infrastructure\Helper\NotificationHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Twig\Environment;
/**
* Class CheckoutReceived
*/
class CheckoutReceived implements EventSubscriberInterface
{
/** @var Environment */
private $parser;
/**
* CheckoutReceived constructor.
* @param Environment $parser
*/
public function __construct(Environment $parser)
{
$this->parser = $parser;
}
/**
* @param TransactionEvent $event
* @return void
*/
public function onCheckoutReceived(TransactionEvent $event)
{
if ($event->getTransaction()->getSubType() !== Transaction::TXN_DIRECT_PURCHASE) {
return;
}
$message = $this->parser->render("@Public/payment/checkout_received.html.twig", [
"transaction" => $event->getTransaction()
]);
$recipient = $event->getTransaction()->getRecipient()->getProfile()->getEmail();
NotificationHelper::submitFromTemplate($message, $recipient);
}
/**
* Returns an array of event names this subscriber wants to listen to.
*
* The array keys are event names and the value can be:
*
* * The method name to call (priority defaults to 0)
* * An array composed of the method name to call and the priority
* * An array of arrays composed of the method names to call and respective
* priorities, or 0 if unset
*
* For instance:
*
* * array('eventName' => 'methodName')
* * array('eventName' => array('methodName', $priority))
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
*
* @return array The event names to listen to
*/
public static function getSubscribedEvents()
{
return [
TransactionEvent::TRANSACTION_COMPLETED => "onCheckoutReceived"
];
}
}