src/Module/Checkout/Subscriber/PaymentReceivedSubscriber.php line 54

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Module\Checkout\Subscriber;
  4. use App\Module\Checkout\Event\PaymentReceivedEvent;
  5. use App\Module\Checkout\Notifier\OrderConfirmationNotifier;
  6. use Psr\Log\LoggerAwareInterface;
  7. use Psr\Log\LoggerAwareTrait;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. /**
  10. * Class PaymentReceivedSubscriber
  11. * @package App\Module\Checkout\Subscriber
  12. */
  13. class PaymentReceivedSubscriber implements EventSubscriberInterface, LoggerAwareInterface
  14. {
  15. use LoggerAwareTrait;
  16. private OrderConfirmationNotifier $orderConfirmationNotifier;
  17. /**
  18. * PaymentReceivedSubscriber constructor.
  19. *
  20. * @param OrderConfirmationNotifier $orderConfirmationNotifier
  21. */
  22. public function __construct(OrderConfirmationNotifier $orderConfirmationNotifier)
  23. {
  24. $this->orderConfirmationNotifier = $orderConfirmationNotifier;
  25. }
  26. /**
  27. * @return array
  28. */
  29. public static function getSubscribedEvents(): array
  30. {
  31. return [
  32. PaymentReceivedEvent::NAME => [
  33. ['sendConfirmationMail'],
  34. ]
  35. ];
  36. }
  37. /**
  38. * Send confirmation mail for orders paid with credit card or paypal
  39. *
  40. * Confirmation mail for orders with pre paymeent and invoice is handled \App\Module\Checkout\Subscriber\OrderCreatedSubscriber::sendConfirmationMail
  41. *
  42. * @param PaymentReceivedEvent $event
  43. *
  44. * @return void
  45. */
  46. public function sendConfirmationMail(PaymentReceivedEvent $event): void
  47. {
  48. $order = $event->getOrder();
  49. $this->logger->debug(sprintf('Sending confirmation mail for order (%s) after payment received', $order->get('id') ?? 'unkown'));
  50. $this->orderConfirmationNotifier->sendConfirmationMail($order);
  51. }
  52. }