/** * @param Request $request * @return Response * @throws \Exception */ public function __invoke(Request $request) { $walletId = $request->get('walletId'); $walletDto = $this->walletServiceFacade->getWallet($walletId); $this->checkAuthorizationForWallet($walletDto); $createTransactionCommand = $this->createCreateTransactionCommand($walletId); $user = $this->getUser(); $createTransactionForm = $this->transactionFormFactory->createCreateForm($createTransactionCommand, $user->getId()->getValue()); $createTransactionForm->handleRequest($request); if (!$createTransactionForm->isValid()) { $validationMsg = $this->getAllFormErrorMessagesAsString($createTransactionForm); $this->addFlash('error', $this->trans('create_transaction_form.flash.invalid_form') . ' ' . $validationMsg); } else { /** @var CreateTransactionCommand $createTransactionCommand */ $createTransactionCommand = $createTransactionForm->getData(); try { $commandValidator = new CreateTransactionCommandValidator(); $commandValidator->validate($createTransactionCommand); $this->commandBus->handle($createTransactionCommand); $this->addFlash('success', $this->trans('transaction.flash.create_successfully')); $url = $this->router->generate('bc_app_wallet_transaction.index', array('walletId' => $createTransactionCommand->getWalletId())); return new RedirectResponse($url); } catch (\Exception $e) { $this->addFlash('error', $e->getMessage()); } } $walletDto = $this->walletServiceFacade->getWallet($walletId); return $this->renderTransactionShowNew($request, $createTransactionForm->createView(), $walletDto); }
/** * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function __invoke(Request $request) { $walletId = $request->get('walletId'); $walletDto = $this->walletServiceFacade->getWallet($walletId); $this->checkAuthorizationForWallet($walletDto); // Default form data $createTransactionCommand = $this->createCreateTransactionCommand($walletId, "mwmabpJVisvti3WEP5vhFRtn3yqHRD9KNP", "Your transaction description", 1000); $user = $this->getUser(); $createTransactionForm = $this->transactionFormFactory->createCreateForm($createTransactionCommand, $user->getId()->getValue()); $template = $this->getBaseTemplatePrefix() . ':Transaction:show_new.html'; return $this->templating->renderResponse($template . '.' . $this->getEngine(), array_merge($this->getBasicTemplateVariables($request), array('transaction_form' => $createTransactionForm->createView(), 'wallet' => $walletDto))); }