<?php
namespace App\Service\App\Merchant\Integrations\Notando\Listener;
use App\Background\Data\NotandoCreateInvoiceData;
use App\Core\BackgroundWork\Contract\IClient;
use App\Core\MerchantSelector\Contract\IMerchantSelector;
use App\Service\App\Merchant\CustomFeature\Implementation\NotandoCustomFeature;
use App\Service\App\Merchant\Invoice\Event\FinalizeInvoiceEvent;
class FinalizeInvoiceListener
{
/**
* Background job client
*
* @var IClient
*/
private IClient $backgroundClient;
/**
* Merchant selector
*
* @var IMerchantSelector
*/
private IMerchantSelector $merchantSelector;
/**
* Notando custom feature instance
*
* @var NotandoCustomFeature
*/
private NotandoCustomFeature $notandoCustomFeature;
/**
* Constructor
*
* @param NotandoCustomFeature $notandoCustomFeature
* @param IClient $backgroundClient
* @param IMerchantSelector $merchantSelector
*/
public function __construct(
NotandoCustomFeature $notandoCustomFeature,
IClient $backgroundClient,
IMerchantSelector $merchantSelector
)
{
$this->notandoCustomFeature = $notandoCustomFeature;
$this->backgroundClient = $backgroundClient;
$this->merchantSelector = $merchantSelector;
}
/**
* Listen on invoice finalized event
*
* @param FinalizeInvoiceEvent $event
* @return void
*/
public function onAction(FinalizeInvoiceEvent $event): void
{
if (!$this->notandoCustomFeature->isActive()) {
return;
}
$this->backgroundClient->runJob(
new NotandoCreateInvoiceData($event->getInvoiceId(), $this->merchantSelector->getMerchant())
);
}
}