getContainer()->getPermissionsService()->currentUserCanWrite(Entities::FINANCE)) { throw new AccessDeniedException('You are not allowed to add new payment.'); } $result = new CommandResult(); $this->checkMandatoryFields($command); $payment = PaymentFactory::create($command->getFields()); if (!$payment instanceof Payment) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Unable to create payment.'); return $result; } /** @var PaymentRepository $paymentRepository */ $paymentRepository = $this->container->get('domain.payment.repository'); if ($paymentRepository->add($payment)) { $result->setResult(CommandResult::RESULT_SUCCESS); $result->setMessage('New payment successfully created.'); $result->setData( [ Entities::PAYMENT => $payment->toArray(), ] ); } return $result; } }