src/EventSubscriber/SmsGateway/WhenSmsPaidProcessPaymentIntentSubscriber.php line 23

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\EventSubscriber\SmsGateway;
  3. use App\DependencyInjection\Repository\Events\PaymentIntentEventRepositoryDI;
  4. use App\DependencyInjection\Service\Data\Client\ClientServiceDI;
  5. use App\Entity\Payment\PaymentIntent;
  6. use App\Event\SmsGateway\SmsIntentValidatedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. final class WhenSmsPaidProcessPaymentIntentSubscriber implements EventSubscriberInterface
  9. {
  10.     use ClientServiceDI;
  11.     use PaymentIntentEventRepositoryDI;
  12.     public static function getSubscribedEvents(): array
  13.     {
  14.         return [
  15.             SmsIntentValidatedEvent::class => ['processPaymentIntent', 9],
  16.         ];
  17.     }
  18.     public function processPaymentIntent(SmsIntentValidatedEvent $event): void
  19.     {
  20.         $paymentIntent = $event->getSmsIntent()
  21.             ->getPaymentIntent();
  22.         if (! $paymentIntent instanceof PaymentIntent) {
  23.             return;
  24.         }
  25.         // Fetch the first created PaymentIntentEvent that was delivered to its webhook URL
  26.         $paymentIntentCreatedEvent = $this->paymentIntentEventRepository->findLatestPaymentIntentCreatedEvent(
  27.             $paymentIntent
  28.         );
  29.         if (! $paymentIntentCreatedEvent) {
  30.             return;
  31.         }
  32.         $this->clientService->createPaymentIntentSuccessEvent($paymentIntent);
  33.     }
  34. }