src/Service/App/Merchant/Integrations/Zapier/Listener/VoidInvoiceListener.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Service\App\Merchant\Integrations\Zapier\Listener;
  3. use App\Background\Data\ZapierTriggerInvoiceData;
  4. use App\Core\BackgroundWork\Contract\IClient;
  5. use App\Core\MerchantSelector\Contract\IMerchantSelector;
  6. use App\Entity\Merchant\ZapierTriggerSubscribeEntity;
  7. use App\Service\App\Merchant\CustomFeature\Implementation\InvoiceCustomFeature;
  8. use App\Service\App\Merchant\CustomFeature\Implementation\ZapierCustomFeature;
  9. use App\Service\App\Merchant\Invoice\Event\PaidInvoiceEvent;
  10. use App\Service\App\Merchant\Invoice\Event\VoidInvoiceEvent;
  11. use App\Types\ZapierTriggerTypes;
  12. class VoidInvoiceListener
  13. {
  14.     /**
  15.      * Background job client
  16.      *
  17.      * @var IClient
  18.      */
  19.     private IClient $backgroundClient;
  20.     /**
  21.      * Merchant selector
  22.      *
  23.      * @var IMerchantSelector
  24.      */
  25.     private IMerchantSelector $merchantSelector;
  26.     /**
  27.      * @var ZapierCustomFeature
  28.      */
  29.     private ZapierCustomFeature $zapierCustomFeature;
  30.     /**
  31.      * @var InvoiceCustomFeature
  32.      */
  33.     private InvoiceCustomFeature $invoiceCustomFeature;
  34.     /**
  35.      * @param IClient $backgroundClient
  36.      * @param IMerchantSelector $merchantSelector
  37.      * @param ZapierCustomFeature $zapierCustomFeature
  38.      * @param InvoiceCustomFeature $invoiceCustomFeature
  39.      */
  40.     public function __construct(
  41.         IClient $backgroundClientIMerchantSelector $merchantSelector,
  42.         ZapierCustomFeature $zapierCustomFeatureInvoiceCustomFeature $invoiceCustomFeature
  43.     )
  44.     {
  45.         $this->backgroundClient $backgroundClient;
  46.         $this->merchantSelector $merchantSelector;
  47.         $this->zapierCustomFeature $zapierCustomFeature;
  48.         $this->invoiceCustomFeature $invoiceCustomFeature;
  49.     }
  50.     /**
  51.      * @param VoidInvoiceEvent $event
  52.      * @return void
  53.      */
  54.     public function onAction(VoidInvoiceEvent $event): void
  55.     {
  56.         if (!$this->zapierCustomFeature->isEnabled() || !$this->invoiceCustomFeature->isEnabled()) {
  57.             return;
  58.         }
  59.         $this->backgroundClient->runJob(
  60.             new ZapierTriggerInvoiceData(
  61.                 $event->getInvoiceId(), $this->merchantSelector->getMerchant(),
  62.                 ZapierTriggerTypes::TYPE_INVOICE_VOIDED
  63.             )
  64.         );
  65.     }
  66. }