src/EventSubscriber/PaymentEventSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\AdmissionUser;
  4. use App\Entity\Payment;
  5. use App\Event\PaymentEvent;
  6. use App\Services\AdmissionUserService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpKernel\Event\ExceptionEvent;
  9. class PaymentEventSubscriber implements EventSubscriberInterface
  10. {
  11.     protected AdmissionUserService $admissionUserService;
  12.     public function __construct(AdmissionUserService $admissionUserService)
  13.     {
  14.         $this->admissionUserService $admissionUserService;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             PaymentEvent::PAID => 'onPaid',
  20.         ];
  21.     }
  22.     public function onPaid(PaymentEvent $paymentEvent): void
  23.     {
  24.         $payment $paymentEvent->getPayment();
  25.         if (!$payment) {
  26.             return;
  27.         }
  28.         if ($payment->getPaymentType() === Payment::TYPE_ADMISSION_REGISTER) {
  29.             $this->admissionUserService->registerPaymentSuccess($payment);
  30.         } elseif ($payment->getPaymentType() === Payment::TYPE_ADMISSION_CREDIT) {
  31.             $this->admissionUserService->creditPaymentSuccess($payment);
  32.         }
  33.     }
  34. }