src/EventSubscriber/Payment/StripePaymentSubscriber.php line 37
<?php/** This file is part of the Pellipop project.** (c) Mobizel** For the full copyright and license information, please view the LICENSE* file that was distributed with this source code.*/declare(strict_types=1);namespace App\EventSubscriber\Payment;use App\Entity\Payment\Payment;use App\PaymentStates;use App\Repository\Payment\PaymentRepository;use FluxSE\PayumStripe\Action\NotifyAction;use Payum\Core\Bridge\Symfony\Event\ExecuteEvent;use Payum\Core\Bridge\Symfony\PayumEvents;use Payum\Core\Request\GetHumanStatus;use Payum\Core\Request\Notify;use Psr\Log\LoggerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\Workflow\WorkflowInterface;class StripePaymentSubscriber implements EventSubscriberInterface{public function __construct(private LoggerInterface $logger,private PaymentRepository $paymentRepository,private WorkflowInterface $paymentStateMachine,) {}public function onPostExecute(ExecuteEvent $event){$context = $event->getContext();$action = $context->getAction();$request = $context->getRequest();if ($action instanceof NotifyAction && $request instanceof Notify) {$payment = $request->getFirstModel();if (!$payment instanceof Payment) {return;}$context->getGateway()->execute($status = new GetHumanStatus($payment));$this->logger->debug(sprintf("Stripe payment status is '%s'.", $status->getValue()));/** @var Payment $payment */$payment = $status->getFirstModel();if ($status->isCaptured() && $this->paymentStateMachine->can($payment, PaymentStates::TRANSITION_COMPLETE)) {$this->paymentStateMachine->apply($payment, PaymentStates::TRANSITION_COMPLETE);$this->paymentRepository->add($payment);} elseif ($status->isCanceled() && $this->paymentStateMachine->can($payment, PaymentStates::TRANSITION_CANCEL)) {$this->paymentStateMachine->apply($payment, PaymentStates::TRANSITION_CANCEL);$this->paymentRepository->add($payment);}}}public static function getSubscribedEvents(){return [PayumEvents::GATEWAY_POST_EXECUTE => 'onPostExecute',];}}