public function verifyCreditUsage(OrderEvent $event)
 {
     $session = $this->request->getSession();
     if ($session->get('creditAccount.used') == 1) {
         $customer = $event->getOrder()->getCustomer();
         $amount = $session->get('creditAccount.amount');
         $creditEvent = new CreditAccountEvent($customer, $amount * -1, $event->getOrder()->getId());
         $creditEvent->setWhoDidIt(Translator::getInstance()->trans('Customer', [], CreditAccount::DOMAIN))->setOrderId($event->getOrder()->getId());
         $event->getDispatcher()->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $creditEvent);
         $session->set('creditAccount.used', 0);
         $session->set('creditAccount.amount', 0);
     }
 }
 public function addAmount()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::CUSTOMER), array('CreditAccount'), AccessManager::UPDATE))) {
         return $response;
     }
     $form = new CreditAccountForm($this->getRequest());
     try {
         $creditForm = $this->validateForm($form);
         $customer = CustomerQuery::create()->findPk($creditForm->get('customer_id')->getData());
         $event = new CreditAccountEvent($customer, $creditForm->get('amount')->getData());
         /** @var  Admin $admin */
         $admin = $this->getSession()->getAdminUser();
         $event->setWhoDidIt($admin->getFirstname() . " " . $admin->getLastname());
         $this->dispatch(CreditAccount::CREDIT_ACCOUNT_ADD_AMOUNT, $event);
     } catch (\Exception $ex) {
         $this->setupFormErrorContext($this->getTranslator()->trans("Add amount to credit account"), $ex->getMessage(), $form, $ex);
     }
     return $this->generateRedirect($form->getSuccessUrl());
 }