<?php
namespace App\EventSubscriber;
use App\Entity\AdmissionUser;
use App\Entity\Payment;
use App\Event\PaymentEvent;
use App\Services\AdmissionUserService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
class PaymentEventSubscriber implements EventSubscriberInterface
{
protected AdmissionUserService $admissionUserService;
public function __construct(AdmissionUserService $admissionUserService)
{
$this->admissionUserService = $admissionUserService;
}
public static function getSubscribedEvents()
{
return [
PaymentEvent::PAID => 'onPaid',
];
}
public function onPaid(PaymentEvent $paymentEvent): void
{
$payment = $paymentEvent->getPayment();
if (!$payment) {
return;
}
if ($payment->getPaymentType() === Payment::TYPE_ADMISSION_REGISTER) {
$this->admissionUserService->registerPaymentSuccess($payment);
} elseif ($payment->getPaymentType() === Payment::TYPE_ADMISSION_CREDIT) {
$this->admissionUserService->creditPaymentSuccess($payment);
}
}
}