<?php
namespace App\Service\App\Merchant\Integrations\Quickbooks\Listener;
use App\Background\Data\QuickbooksCreateRecordData;
use App\Core\BackgroundWork\Contract\IClient;
use App\Core\MerchantSelector\Contract\IMerchantSelector;
use App\Service\App\Merchant\CustomFeature\Implementation\QuickbooksCustomFeature;
use App\Service\App\Merchant\Payment\Event\ConfirmPaymentEvent;
use App\Types\ReexportMode;
class ConfirmPaymentListener
{
/**
* Background job client
*
* @var IClient
*/
private IClient $backgroundClient;
/**
* Merchant selector
*
* @var IMerchantSelector
*/
private IMerchantSelector $merchantSelector;
/**
* Quickbooks custom feature instance
*
* @var QuickbooksCustomFeature
*/
private QuickbooksCustomFeature $quickbooksCustomFeature;
/**
* Constructor
*
* @param IClient $backgroundClient
* @param IMerchantSelector $merchantSelector
* @param QuickbooksCustomFeature $quickbooksCustomFeature
*/
public function __construct(
IClient $backgroundClient, IMerchantSelector $merchantSelector, QuickbooksCustomFeature $quickbooksCustomFeature
)
{
$this->backgroundClient = $backgroundClient;
$this->merchantSelector = $merchantSelector;
$this->quickbooksCustomFeature = $quickbooksCustomFeature;
}
/**
* On confirm payment action - create quickbooks payment or sales receipt
*
* @param ConfirmPaymentEvent $event
* @return void
*/
public function onAction(ConfirmPaymentEvent $event): void
{
if (!$this->quickbooksCustomFeature->isActive()) {
return;
}
$this->backgroundClient->runJob(
new QuickbooksCreateRecordData(
$event->getRequest()->getId(), $this->merchantSelector->getMerchant(),
ReexportMode::RESYNC_MODE_NONE
)
);
}
}