src/FMT/Domain/Listener/CheckoutReceived.php line 38

Open in your IDE?
  1. <?php
  2. /**
  3.  * Author: Vladimir Bykovsky
  4.  * Date: 26.11.2021
  5.  * Time: 18:00
  6.  */
  7. namespace FMT\Domain\Listener;
  8. use FMT\Data\Entity\Transaction;
  9. use FMT\Data\Entity\UserTransaction;
  10. use FMT\Domain\Event\TransactionEvent;
  11. use FMT\Infrastructure\Helper\NotificationHelper;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Twig\Environment;
  14. /**
  15.  * Class CheckoutReceived
  16.  */
  17. class CheckoutReceived implements EventSubscriberInterface
  18. {
  19.     /** @var Environment */
  20.     private $parser;
  21.     /**
  22.      * CheckoutReceived constructor.
  23.      * @param Environment $parser
  24.      */
  25.     public function __construct(Environment $parser)
  26.     {
  27.         $this->parser $parser;
  28.     }
  29.     
  30.     /**
  31.      * @param  TransactionEvent $event
  32.      * @return void
  33.      */
  34.     public function onCheckoutReceived(TransactionEvent $event)
  35.     {
  36.         if ($event->getTransaction()->getSubType() !== Transaction::TXN_DIRECT_PURCHASE) {
  37.             return;
  38.         }
  39.         $message $this->parser->render("@Public/payment/checkout_received.html.twig", [
  40.             "transaction" => $event->getTransaction()
  41.         ]);
  42.         $recipient $event->getTransaction()->getRecipient()->getProfile()->getEmail();
  43.         NotificationHelper::submitFromTemplate($message$recipient);
  44.     }
  45.     /**
  46.      * Returns an array of event names this subscriber wants to listen to.
  47.      *
  48.      * The array keys are event names and the value can be:
  49.      *
  50.      *  * The method name to call (priority defaults to 0)
  51.      *  * An array composed of the method name to call and the priority
  52.      *  * An array of arrays composed of the method names to call and respective
  53.      *    priorities, or 0 if unset
  54.      *
  55.      * For instance:
  56.      *
  57.      *  * array('eventName' => 'methodName')
  58.      *  * array('eventName' => array('methodName', $priority))
  59.      *  * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
  60.      *
  61.      * @return array The event names to listen to
  62.      */
  63.     public static function getSubscribedEvents()
  64.     {
  65.         return [
  66.             TransactionEvent::TRANSACTION_COMPLETED => "onCheckoutReceived"
  67.         ];
  68.     }
  69. }