webhookRequest = $webhookRequest; $this->logger = $logger; $this->webhookMessageReader = $webhookMessageReader; $this->caseUpdatingServiceFactory = $caseUpdatingServiceFactory; $this->webhookRequestValidator = $webhookRequestValidator; $this->caseRepository = $caseRepository; $this->config = $config; } /** * Processes webhook request data and updates case entity * * @return void */ public function execute() { if ($this->config->isDebugModeEnabled()) { $this->logger->debug($this->webhookRequest->getEventTopic() . '|' . $this->webhookRequest->getBody()); } if (!$this->webhookRequestValidator->validate($this->webhookRequest)) { $this->_redirect('noroute'); return; } $webhookMessage = $this->webhookMessageReader->read($this->webhookRequest); if ($webhookMessage->getEventTopic() === self::$eventTopicTest) { return; } $data = $webhookMessage->getData(); if (empty($data['caseId'])) { $this->_redirect('noroute'); return; } $case = $this->caseRepository->getByCaseId($data['caseId']); if ($case === null) { $this->_redirect('noroute'); return; } $caseUpdatingService = $this->caseUpdatingServiceFactory->create($webhookMessage->getEventTopic()); try { $caseUpdatingService->update($case, $data); } catch (LocalizedException $e) { $this->getResponse()->setHttpResponseCode(400); $this->logger->critical($e); } } /** * @inheritDoc */ public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException { return null; } /** * @inheritDoc */ public function validateForCsrf(RequestInterface $request): ?bool { return true; } }