<?php declare(strict_types=1);
namespace App\EventSubscriber\SmsGateway;
use App\DependencyInjection\Repository\Events\PaymentIntentEventRepositoryDI;
use App\DependencyInjection\Service\Data\Client\ClientServiceDI;
use App\Entity\Payment\PaymentIntent;
use App\Event\SmsGateway\SmsIntentValidatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class WhenSmsPaidProcessPaymentIntentSubscriber implements EventSubscriberInterface
{
use ClientServiceDI;
use PaymentIntentEventRepositoryDI;
public static function getSubscribedEvents(): array
{
return [
SmsIntentValidatedEvent::class => ['processPaymentIntent', 9],
];
}
public function processPaymentIntent(SmsIntentValidatedEvent $event): void
{
$paymentIntent = $event->getSmsIntent()
->getPaymentIntent();
if (! $paymentIntent instanceof PaymentIntent) {
return;
}
// Fetch the first created PaymentIntentEvent that was delivered to its webhook URL
$paymentIntentCreatedEvent = $this->paymentIntentEventRepository->findLatestPaymentIntentCreatedEvent(
$paymentIntent
);
if (! $paymentIntentCreatedEvent) {
return;
}
$this->clientService->createPaymentIntentSuccessEvent($paymentIntent);
}
}