getContainer()->getPermissionsService()->currentUserCanDelete(Entities::FINANCE)) { throw new AccessDeniedException('You are not allowed to delete payments.'); } $result = new CommandResult(); $this->checkMandatoryFields($command); /** @var PaymentRepository $paymentRepository */ $paymentRepository = $this->container->get('domain.payment.repository'); $payment = $paymentRepository->getById($command->getArg('id')); if (!$payment instanceof Payment) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Unable to delete payment.'); return $result; } if ($paymentRepository->delete($command->getArg('id'))) { $result->setResult(CommandResult::RESULT_SUCCESS); $result->setMessage('Payment successfully deleted.'); $result->setData( [ Entities::PAYMENT => $payment->toArray() ] ); } return $result; } }