<?php
namespace App\Service\App\Merchant\Integrations\Zapier\Listener;
use App\Background\Data\ZapierTriggerPaymentData;
use App\Core\BackgroundWork\Contract\IClient;
use App\Core\MerchantSelector\Contract\IMerchantSelector;
use App\Service\App\Merchant\CustomFeature\Implementation\ZapierCustomFeature;
use App\Service\App\Merchant\Payment\Event\RefundPaymentEvent;
use App\Types\ZapierTriggerTypes;
class RefundPaymentListener
{
/**
* Background job client
*
* @var IClient
*/
private IClient $backgroundClient;
/**
* Merchant selector
*
* @var IMerchantSelector
*/
private IMerchantSelector $merchantSelector;
/**
* @var ZapierCustomFeature
*/
private ZapierCustomFeature $zapierCustomFeature;
/**
* @param IClient $backgroundClient
* @param IMerchantSelector $merchantSelector
* @param ZapierCustomFeature $zapierCustomFeature
*/
public function __construct(IClient $backgroundClient, IMerchantSelector $merchantSelector, ZapierCustomFeature $zapierCustomFeature)
{
$this->backgroundClient = $backgroundClient;
$this->merchantSelector = $merchantSelector;
$this->zapierCustomFeature = $zapierCustomFeature;
}
/**
* @param RefundPaymentEvent $event
* @return void
*/
public function onAction(RefundPaymentEvent $event): void
{
if (!$this->zapierCustomFeature->isEnabled()) {
return;
}
$this->backgroundClient->runJob(
new ZapierTriggerPaymentData(
$event->getRequest()->getId(), $this->merchantSelector->getMerchant(),
ZapierTriggerTypes::TYPE_PAYMENT_REFUNDED
)
);
}
}