src/Service/App/Merchant/Integrations/Zapier/Listener/CreatePaymentListener.php line 74

Open in your IDE?
  1. <?php
  2. namespace App\Service\App\Merchant\Integrations\Zapier\Listener;
  3. use App\Background\Data\ZapierTriggerPaymentData;
  4. use App\Core\BackgroundWork\Contract\IClient;
  5. use App\Core\MerchantSelector\Contract\IMerchantSelector;
  6. use App\Service\App\Merchant\CustomFeature\Implementation\ZapierCustomFeature;
  7. use App\Service\App\Merchant\Integrations\Logger\IntegrationLoggerProcessor;
  8. use App\Service\App\Merchant\Payment\Event\CreatePaymentEvent;
  9. use App\Types\ZapierTriggerTypes;
  10. use Psr\Log\LoggerInterface;
  11. class CreatePaymentListener
  12. {
  13.     /**
  14.      * Background job client
  15.      *
  16.      * @var IClient
  17.      */
  18.     private IClient $backgroundClient;
  19.     /**
  20.      * Merchant selector
  21.      *
  22.      * @var IMerchantSelector
  23.      */
  24.     private IMerchantSelector $merchantSelector;
  25.     /**
  26.      * Zapier custom feature
  27.      *
  28.      * @var ZapierCustomFeature
  29.      */
  30.     private ZapierCustomFeature $zapierCustomFeature;
  31.     /**
  32.      * Logger interface
  33.      *
  34.      * @var LoggerInterface
  35.      */
  36.     private LoggerInterface $logger;
  37.     /**
  38.      * Integration logger processor
  39.      *
  40.      * @var IntegrationLoggerProcessor
  41.      */
  42.     private IntegrationLoggerProcessor $loggerProcessor;
  43.     /**
  44.      * @param IClient $backgroundClient
  45.      * @param IMerchantSelector $merchantSelector
  46.      * @param ZapierCustomFeature $zapierCustomFeature
  47.      * @param LoggerInterface $logger
  48.      * @param IntegrationLoggerProcessor $loggerProcessor
  49.      */
  50.     public function __construct(
  51.         IClient $backgroundClientIMerchantSelector $merchantSelectorZapierCustomFeature $zapierCustomFeature,
  52.         LoggerInterface $loggerIntegrationLoggerProcessor $loggerProcessor
  53.     )
  54.     {
  55.         $this->backgroundClient $backgroundClient;
  56.         $this->merchantSelector $merchantSelector;
  57.         $this->zapierCustomFeature $zapierCustomFeature;
  58.         $this->logger $logger;
  59.         $this->loggerProcessor $loggerProcessor;
  60.     }
  61.     /**
  62.      * @param CreatePaymentEvent $event
  63.      * @return void
  64.      */
  65.     public function onAction(CreatePaymentEvent $event): void
  66.     {
  67.         if (!$this->zapierCustomFeature->isEnabled()) {
  68.             return;
  69.         }
  70.         // @todo remove after testing
  71.         $this->loggerProcessor->setInfo($event->getOrderId(), ZapierCustomFeature::NAME);
  72.         $this->logger->info('Zapier: Triggering payment created event for the order ' $event->getOrderId());
  73.         $this->backgroundClient->runJob(
  74.             new ZapierTriggerPaymentData(
  75.                 $event->getOrderId(), $this->merchantSelector->getMerchant(),
  76.                 ZapierTriggerTypes::TYPE_PAYMENT_CREATED
  77.             )
  78.         );
  79.     }
  80. }