<?php
/**
* This file is part of the CosaVostra, TrackPay package.
*
* (c) Mohamed Radhi GUENNICHI <rg@mate.tn> <+216 50 711 816>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\EventSubscriber;
use App\Entity\PaymentRequestEvent;
use App\Event\InvoicePaymentEvent;
use App\Repository\PaymentRequestEventRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class InvoicePaymentSubscriber implements EventSubscriberInterface
{
/**
* @var PaymentRequestEventRepository
*/
protected $paymentRequestEventRepository;
public function __construct(PaymentRequestEventRepository $paymentRequestEventRepository)
{
$this->paymentRequestEventRepository = $paymentRequestEventRepository;
}
public function onPayment(InvoicePaymentEvent $event): void
{
$this->paymentRequestEventRepository->save(
(new PaymentRequestEvent())
->setProcedure($event->getProcedure())
->setMethod($event->getPaymentMethod())
);
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return [
InvoicePaymentEvent::class => 'onPayment'
];
}
}