<?php
declare(strict_types=1);
namespace App\Module\Checkout\Subscriber;
use App\Module\Checkout\Event\PaymentReceivedEvent;
use App\Module\Checkout\Notifier\OrderConfirmationNotifier;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class PaymentReceivedSubscriber
* @package App\Module\Checkout\Subscriber
*/
class PaymentReceivedSubscriber implements EventSubscriberInterface, LoggerAwareInterface
{
use LoggerAwareTrait;
private OrderConfirmationNotifier $orderConfirmationNotifier;
/**
* PaymentReceivedSubscriber constructor.
*
* @param OrderConfirmationNotifier $orderConfirmationNotifier
*/
public function __construct(OrderConfirmationNotifier $orderConfirmationNotifier)
{
$this->orderConfirmationNotifier = $orderConfirmationNotifier;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
PaymentReceivedEvent::NAME => [
['sendConfirmationMail'],
]
];
}
/**
* Send confirmation mail for orders paid with credit card or paypal
*
* Confirmation mail for orders with pre paymeent and invoice is handled \App\Module\Checkout\Subscriber\OrderCreatedSubscriber::sendConfirmationMail
*
* @param PaymentReceivedEvent $event
*
* @return void
*/
public function sendConfirmationMail(PaymentReceivedEvent $event): void
{
$order = $event->getOrder();
$this->logger->debug(sprintf('Sending confirmation mail for order (%s) after payment received', $order->get('id') ?? 'unkown'));
$this->orderConfirmationNotifier->sendConfirmationMail($order);
}
}