/**
  * Terms and conditions
  *
  * @return void
  */
 public function termsAndConditionsAction()
 {
     $form = $this->getFormFactory()->create(new RootStepType(new TermsAndConditionsType()), $this->getSystemProgressiveStore()->fetch(self::MODEL_APPLICATION_CLASS));
     if ($this->getSymfonyRequest()->isMethod('POST')) {
         $form->submit($this->getSymfonyRequest());
         $this->getFormFlow()->setForm($form);
         if ($form->get('back')->isClicked()) {
             $this->_helper->redirector->gotoUrlAndExit($this->getFormFlow()->getBackUrl());
         }
         if ($form->isValid()) {
             $object = null;
             try {
                 /** @var \Barbondev\IRISSDK\IndividualApplication\ReferencingApplication\Model\ReferencingApplication $object */
                 $object = $this->getSystemProgressiveStore()->store($form->getData());
             } catch (ValidationException $e) {
                 $this->getFormValidationErrorBinder()->bind($form, $e);
             }
             if ($object) {
                 // Perform submission
                 $this->getIrisSystemContext()->getSystemApplicationClient()->submitApplication(array('referencingApplicationUuId' => $object->getReferencingApplicationUuId()));
                 if ($form->get('next')->isClicked()) {
                     $this->_helper->redirector->gotoUrlAndExit($this->getFormFlow()->getNextUrl());
                 }
             }
         }
     }
     $sysAppclientContext = $this->getIrisSystemContext()->getSystemApplicationClient();
     $declarationOwnership = new DeclarationOwnership();
     $agentSchemeNumber = $declarationOwnership->getAgentSchemeNumberByLinkRef($sysAppclientContext, $this->authSession->linkRef);
     $canDisplayDeclaration = $declarationOwnership->canDisplayDeclaration($agentSchemeNumber);
     $this->renderTwigView('/iris-continue-reference/generic-step.html.twig', array('bodyTitle' => 'Terms and Conditions', 'formTheme' => 'form/continue-terms-and-conditions-widgets.html.twig', 'form' => $form->createView(), 'canDisplayDeclaration' => $canDisplayDeclaration));
 }
 /**
  * Terms and conditions
  *
  * @return void
  */
 public function termsAndConditionsAction()
 {
     $form = $this->getFormFactory()->create(new RootStepType(new TermsAndConditionsType()), $this->getSystemProgressiveStore()->fetch(self::MODEL_APPLICATION_CLASS));
     if ($this->getSymfonyRequest()->isMethod('POST')) {
         $form->submit($this->getSymfonyRequest());
         $this->getFormFlow()->setForm($form);
         if ($form->get('back')->isClicked()) {
             $this->_helper->redirector->gotoUrlAndExit($this->getFormFlow()->getBackUrl());
         }
         if ($form->isValid()) {
             $paymentStatusResponse = null;
             $application = $this->getSystemProgressiveStore()->getPrototypeByClass(self::MODEL_APPLICATION_CLASS);
             try {
                 /** @var \Barbondev\IRISSDK\IndividualApplication\ReferencingApplication\Model\PaymentStatus $paymentStatusResponse */
                 $paymentStatusResponse = $this->getIrisSystemContext()->getSystemApplicationClient()->paymentStatus(array('applicationUuId' => $application->getReferencingApplicationUuId()));
             } catch (ValidationException $e) {
                 $this->getFormValidationErrorBinder()->bind($form, $e);
             }
             if ($paymentStatusResponse) {
                 if ($form->get('next')->isClicked()) {
                     $paymentStatus = $paymentStatusResponse->getPaymentStatus();
                     // note: Don't like the id numbers, should be strings
                     if (2 == $paymentStatus || 4 == $paymentStatus || 5 == $paymentStatus) {
                         // Payment complete, move straight to submission
                         $this->getIrisSystemContext()->getSystemApplicationClient()->submitApplication(array('referencingApplicationUuId' => $application->getReferencingApplicationUuId()));
                         $this->_helper->redirector->gotoUrlAndExit($this->params->homelet->domain . $this->getFormFlow()->getNextUrl());
                     } else {
                         // Payment pending, create an order
                         $paymentOrderResponse = null;
                         try {
                             /** @var \Barbondev\IRISSDK\IndividualApplication\ReferencingApplication\Model\PaymentOrder $paymentOrderResponse */
                             $paymentOrderResponse = $this->getIrisSystemContext()->getSystemApplicationClient()->paymentOrder(array('applicationUuId' => $application->getReferencingApplicationUuId(), 'paymentTypes' => array(1), 'redirectOnSuccessUrl' => $this->params->homelet->domain . $this->getFormFlow()->getNextUrl()));
                         } catch (ValidationException $e) {
                             $this->getFormValidationErrorBinder()->bind($form, $e);
                         }
                         if ($paymentOrderResponse) {
                             $this->_helper->redirector->gotoUrlAndExit($paymentOrderResponse->getPaymentPortalStartUrl());
                         }
                     }
                 }
             }
         }
     }
     $sysAppclientContext = $this->getIrisSystemContext()->getSystemApplicationClient();
     $declarationOwnership = new DeclarationOwnership();
     $agentSchemeNumber = $declarationOwnership->getAgentSchemeNumberByLinkRef($sysAppclientContext, $this->authSession->linkRef);
     $canDisplayDeclaration = $declarationOwnership->canDisplayDeclaration($agentSchemeNumber);
     $this->renderTwigView('/iris-complete-reference/generic-step.html.twig', array('bodyTitle' => 'Terms and Conditions', 'formTheme' => 'form/complete-terms-and-conditions-widgets.html.twig', 'form' => $form->createView(), 'canDisplayDeclaration' => $canDisplayDeclaration));
 }