src/Service/App/Merchant/Integrations/Zapier/Listener/RefundPaymentListener.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Service\App\Merchant\Integrations\Zapier\Listener;
  3. use App\Background\Data\ZapierTriggerPaymentData;
  4. use App\Core\BackgroundWork\Contract\IClient;
  5. use App\Core\MerchantSelector\Contract\IMerchantSelector;
  6. use App\Service\App\Merchant\CustomFeature\Implementation\ZapierCustomFeature;
  7. use App\Service\App\Merchant\Payment\Event\RefundPaymentEvent;
  8. use App\Types\ZapierTriggerTypes;
  9. class RefundPaymentListener
  10. {
  11.     /**
  12.      * Background job client
  13.      *
  14.      * @var IClient
  15.      */
  16.     private IClient $backgroundClient;
  17.     /**
  18.      * Merchant selector
  19.      *
  20.      * @var IMerchantSelector
  21.      */
  22.     private IMerchantSelector $merchantSelector;
  23.     /**
  24.      * @var ZapierCustomFeature
  25.      */
  26.     private ZapierCustomFeature $zapierCustomFeature;
  27.     /**
  28.      * @param IClient $backgroundClient
  29.      * @param IMerchantSelector $merchantSelector
  30.      * @param ZapierCustomFeature $zapierCustomFeature
  31.      */
  32.     public function __construct(IClient $backgroundClientIMerchantSelector $merchantSelectorZapierCustomFeature $zapierCustomFeature)
  33.     {
  34.         $this->backgroundClient $backgroundClient;
  35.         $this->merchantSelector $merchantSelector;
  36.         $this->zapierCustomFeature $zapierCustomFeature;
  37.     }
  38.     /**
  39.      * @param RefundPaymentEvent $event
  40.      * @return void
  41.      */
  42.     public function onAction(RefundPaymentEvent $event): void
  43.     {
  44.         if (!$this->zapierCustomFeature->isEnabled()) {
  45.             return;
  46.         }
  47.         $this->backgroundClient->runJob(
  48.             new ZapierTriggerPaymentData(
  49.                 $event->getRequest()->getId(), $this->merchantSelector->getMerchant(),
  50.                 ZapierTriggerTypes::TYPE_PAYMENT_REFUNDED
  51.             )
  52.         );
  53.     }
  54. }