<?php declare(strict_types=1);
namespace App\EventSubscriber\SmsGateway;
use App\DependencyInjection\Service\Data\Client\ClientServiceDI;
use App\Entity\Payment\PaymentIntent;
use App\Event\SmsGateway\SmsIntentErroredEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
final class WhenSmsValidationFailCancelPaymentIntentSubscriber implements EventSubscriberInterface
{
use ClientServiceDI;
public static function getSubscribedEvents(): array
{
return [
SmsIntentErroredEvent::class => ['failedPaymentIntent', 9],
];
}
public function failedPaymentIntent(SmsIntentErroredEvent $event): void
{
$paymentIntent = $event->getSmsIntent()
->getPaymentIntent();
if (! $paymentIntent instanceof PaymentIntent) {
return;
}
$this->clientService->createPaymentIntentFailedEvent($paymentIntent);
}
}