src/Service/App/Merchant/Integrations/Freshbooks/Listener/ConfirmPaymentListener.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Service\App\Merchant\Integrations\Freshbooks\Listener;
  3. use App\Background\Data\FreshbooksCreateRecordData;
  4. use App\Core\BackgroundWork\Contract\IClient;
  5. use App\Core\MerchantSelector\Contract\IMerchantSelector;
  6. use App\Service\App\Merchant\CustomFeature\Implementation\FreshbooksCustomFeature;
  7. use App\Service\App\Merchant\Payment\Event\ConfirmPaymentEvent;
  8. use App\Types\ReexportMode;
  9. class ConfirmPaymentListener
  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.      * Freshbooks custom feature instance
  25.      *
  26.      * @var FreshbooksCustomFeature
  27.      */
  28.     private FreshbooksCustomFeature $freshbooksCustomFeature;
  29.     /**
  30.      * Constructor
  31.      *
  32.      * @param IClient $backgroundClient
  33.      * @param IMerchantSelector $merchantSelector
  34.      * @param FreshbooksCustomFeature $freshbooksCustomFeature
  35.      */
  36.     public function __construct(IClient $backgroundClientIMerchantSelector $merchantSelectorFreshbooksCustomFeature $freshbooksCustomFeature)
  37.     {
  38.         $this->backgroundClient $backgroundClient;
  39.         $this->merchantSelector $merchantSelector;
  40.         $this->freshbooksCustomFeature $freshbooksCustomFeature;
  41.     }
  42.     /**
  43.      * On confirm payment action - create freshbooks payment and link it to invoice
  44.      *
  45.      * @param ConfirmPaymentEvent $event
  46.      * @return void
  47.      */
  48.     public function onAction(ConfirmPaymentEvent $event): void
  49.     {
  50.         if (!$this->freshbooksCustomFeature->isActive()) {
  51.             return;
  52.         }
  53.         $this->backgroundClient->runJob(
  54.             new FreshbooksCreateRecordData(
  55.                 $event->getRequest()->getId(), $this->merchantSelector->getMerchant(),
  56.                 ReexportMode::RESYNC_MODE_NONE
  57.             )
  58.         );
  59.     }
  60. }