src/Service/App/Merchant/Integrations/Quickbooks/Listener/ConfirmPaymentListener.php line 57

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