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