src/Service/App/Merchant/Integrations/Zapier/Listener/PaidInvoiceListener.php line 60

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\Service\App\Merchant\CustomFeature\Implementation\InvoiceCustomFeature;
  7. use App\Service\App\Merchant\CustomFeature\Implementation\ZapierCustomFeature;
  8. use App\Service\App\Merchant\Invoice\Event\PaidInvoiceEvent;
  9. use App\Types\ZapierTriggerTypes;
  10. class PaidInvoiceListener
  11. {
  12.     /**
  13.      * Background job client
  14.      *
  15.      * @var IClient
  16.      */
  17.     private IClient $backgroundClient;
  18.     /**
  19.      * Merchant selector
  20.      *
  21.      * @var IMerchantSelector
  22.      */
  23.     private IMerchantSelector $merchantSelector;
  24.     /**
  25.      * @var ZapierCustomFeature
  26.      */
  27.     private ZapierCustomFeature $zapierCustomFeature;
  28.     /**
  29.      * @var InvoiceCustomFeature
  30.      */
  31.     private InvoiceCustomFeature $invoiceCustomFeature;
  32.     /**
  33.      * @param IClient $backgroundClient
  34.      * @param IMerchantSelector $merchantSelector
  35.      * @param ZapierCustomFeature $zapierCustomFeature
  36.      * @param InvoiceCustomFeature $invoiceCustomFeature
  37.      */
  38.     public function __construct(
  39.         IClient $backgroundClientIMerchantSelector $merchantSelector,
  40.         ZapierCustomFeature $zapierCustomFeatureInvoiceCustomFeature $invoiceCustomFeature
  41.     )
  42.     {
  43.         $this->backgroundClient $backgroundClient;
  44.         $this->merchantSelector $merchantSelector;
  45.         $this->zapierCustomFeature $zapierCustomFeature;
  46.         $this->invoiceCustomFeature $invoiceCustomFeature;
  47.     }
  48.     /**
  49.      * @param PaidInvoiceEvent $event
  50.      * @return void
  51.      */
  52.     public function onAction(PaidInvoiceEvent $event): void
  53.     {
  54.         if (!$this->zapierCustomFeature->isEnabled() || !$this->invoiceCustomFeature->isEnabled()) {
  55.             return;
  56.         }
  57.         $this->backgroundClient->runJob(
  58.             new ZapierTriggerInvoiceData(
  59.                 $event->getInvoiceId(), $this->merchantSelector->getMerchant(),
  60.                 ZapierTriggerTypes::TYPE_INVOICE_PAID
  61.             )
  62.         );
  63.     }
  64. }