src/Service/App/Merchant/Integrations/Quickbooks/Listener/RefundPaymentListener.php line 67

Open in your IDE?
  1. <?php
  2. namespace App\Service\App\Merchant\Integrations\Quickbooks\Listener;
  3. use App\Background\Data\QuickbooksRefundPaymentData;
  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\Integrations\Quickbooks\Contract\IQuickbooksIntegration;
  8. use App\Service\App\Merchant\Payment\Event\RefundPaymentEvent;
  9. class RefundPaymentListener
  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.      * Quickbooks integration
  31.      *
  32.      * @var IQuickbooksIntegration
  33.      */
  34.     private IQuickbooksIntegration $quickbooksIntegration;
  35.     /**
  36.      * Constructor
  37.      *
  38.      * @param IClient $backgroundClient
  39.      * @param IMerchantSelector $merchantSelector
  40.      * @param QuickbooksCustomFeature $quickbooksCustomFeature
  41.      * @param IQuickbooksIntegration $quickbooksIntegration
  42.      */
  43.     public function __construct(
  44.         IClient $backgroundClientIMerchantSelector $merchantSelectorQuickbooksCustomFeature $quickbooksCustomFeature,
  45.         IQuickbooksIntegration $quickbooksIntegration
  46.     )
  47.     {
  48.         $this->backgroundClient $backgroundClient;
  49.         $this->merchantSelector $merchantSelector;
  50.         $this->quickbooksCustomFeature $quickbooksCustomFeature;
  51.         $this->quickbooksIntegration $quickbooksIntegration;
  52.     }
  53.     /**
  54.      * On refund payment action - create quickbooks credit memo
  55.      *
  56.      * @param RefundPaymentEvent $event
  57.      * @return void
  58.      */
  59.     public function onAction(RefundPaymentEvent $event): void
  60.     {
  61.         if (!$this->quickbooksCustomFeature->isActive()) {
  62.             return;
  63.         }
  64.         if (!$this->quickbooksIntegration->isRefundEnabled()) {
  65.             return;
  66.         }
  67.         $this->backgroundClient->runJob(
  68.             new QuickbooksRefundPaymentData($event->getRequest()->getId(), $this->merchantSelector->getMerchant())
  69.         );
  70.     }
  71. }