src/Service/App/Merchant/Integrations/TeamBlue/Listener/PaidInvoiceListener.php line 59

Open in your IDE?
  1. <?php
  2. namespace App\Service\App\Merchant\Integrations\TeamBlue\Listener;
  3. use App\Background\Data\TeamBlueSyncInvoiceData;
  4. use App\Core\BackgroundWork\Contract\IClient;
  5. use App\Core\MerchantSelector\Contract\IMerchantSelector;
  6. use App\Service\App\Merchant\CustomFeature\Implementation\TeamBlueCustomFeature;
  7. use App\Service\App\Merchant\Invoice\Event\PaidInvoiceEvent;
  8. class PaidInvoiceListener
  9. {
  10.     /**
  11.      * Background job client
  12.      *
  13.      * @var IClient
  14.      */
  15.     private IClient $backgroundClient;
  16.     /**
  17.      * Merchant selector
  18.      *
  19.      * @var IMerchantSelector
  20.      */
  21.     private IMerchantSelector $merchantSelector;
  22.     /**
  23.      * Team blue custom feature instance
  24.      *
  25.      * @var TeamBlueCustomFeature
  26.      */
  27.     private TeamBlueCustomFeature $teamBlueCustomFeature;
  28.     /**
  29.      * Constructor
  30.      *
  31.      * @param TeamBlueCustomFeature $teamBlueCustomFeature
  32.      * @param IClient $backgroundClient
  33.      * @param IMerchantSelector $merchantSelector
  34.      */
  35.     public function __construct(
  36.         TeamBlueCustomFeature $teamBlueCustomFeature,
  37.         IClient $backgroundClient,
  38.         IMerchantSelector $merchantSelector
  39.     )
  40.     {
  41.         $this->teamBlueCustomFeature $teamBlueCustomFeature;
  42.         $this->backgroundClient $backgroundClient;
  43.         $this->merchantSelector $merchantSelector;
  44.     }
  45.     /**
  46.      * Listen on invoice finalized event
  47.      *
  48.      * @param PaidInvoiceEvent $event
  49.      * @return void
  50.      */
  51.     public function onAction(PaidInvoiceEvent $event): void
  52.     {
  53.         if (!$this->teamBlueCustomFeature->isEnabled()) {
  54.             return;
  55.         }
  56.         $this->backgroundClient->runJob(
  57.             new TeamBlueSyncInvoiceData($event->getInvoiceId(), $this->merchantSelector->getMerchant())
  58.         );
  59.     }
  60. }