messageGenerator = $messageGenerator; $this->caseRepository = $caseRepository; $this->commentsHistoryUpdater = $commentsHistoryUpdater; $this->orderGridUpdater = $orderGridUpdater; $this->orderStateService = $orderStateService; } /** * Updates Signifyd Case entity by received data. * * @param CaseInterface $case * @param array $data * @return void * @throws LocalizedException */ public function update(CaseInterface $case, array $data) { if (empty($case->getEntityId()) || empty($case->getCaseId())) { throw new LocalizedException(__('The case entity should not be empty.')); } try { $previousDisposition = $case->getGuaranteeDisposition(); $this->setCaseData($case, $data); $orderHistoryComment = $this->messageGenerator->generate($data); $case = $this->caseRepository->save($case); $this->orderGridUpdater->update($case->getOrderId()); $this->commentsHistoryUpdater->addComment($case, $orderHistoryComment); if ($case->getGuaranteeDisposition() !== $previousDisposition) { $this->orderStateService->updateByCase($case); } } catch (\Exception $e) { throw new LocalizedException(__('Cannot update Case entity.'), $e); } } /** * Sets data to case entity. * * @param CaseInterface $case * @param array $data * @return void */ private function setCaseData(CaseInterface $case, array $data) { // list of keys which should not be replaced, like order id $notResolvedKeys = [ 'orderId' ]; foreach ($data as $key => $value) { $methodName = 'set' . SimpleDataObjectConverter::snakeCaseToUpperCamelCase($key); if (!in_array($key, $notResolvedKeys) && method_exists($case, $methodName)) { call_user_func([$case, $methodName], $value); } } } }