vendor/boldr/mollie-payment-method/src/EventSubscriber/OrderEventSubscriber.php line 31

Open in your IDE?
  1. <?php
  2. namespace Boldr\Shop\MolliePaymentMethodBundle\EventSubscriber;
  3. use Boldr\Shop\ShopBundle\Event\{ OrderStateUpdatedEvent };
  4. use Boldr\Shop\ShopBundle\Entity\Payment;
  5. use Boldr\Shop\MolliePaymentMethodBundle\Entity\MolliePayment;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. class OrderEventSubscriber implements EventSubscriberInterface
  9. {
  10. private EntityManagerInterface $em;
  11. public function __construct(EntityManagerInterface $em)
  12. {
  13. $this->em = $em;
  14. }
  15. public static function getSubscribedEvents(): array
  16. {
  17. return [
  18. OrderStateUpdatedEvent::class => [
  19. ['onOrderStateUpdated', 10]
  20. ]
  21. ];
  22. }
  23. public function onOrderStateUpdated(OrderStateUpdatedEvent $event)
  24. {
  25. if ($event->getOldState() === 'payment' && $event->getNewState() === 'cart')
  26. {
  27. foreach ($event->getOrder()->getInvoices() as $invoice)
  28. {
  29. foreach ($invoice->getPayments() as $payment)
  30. {
  31. if ($payment instanceof MolliePayment && $payment->getStatus() === Payment::STATUS_FAILED)
  32. {
  33. $payment->setShowFailedScreen(false);
  34. $this->em->flush();
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }