/**
  * Reference purchase summary
  *
  * @Route()
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request)
 {
     $previouslyPostedData = null;
     // if we are not posting new data, and a request for $this->formType is stored in the session, prepopulate the form with the stored request
     $storedRequest = unserialize($request->getSession()->get($this->formType->getName()));
     if ($request->isMethod('GET') && $storedRequest instanceof Request) {
         $previouslyPostedData = $this->createForm($this->formType)->handleRequest($storedRequest)->getData();
     }
     $form = $this->createForm($this->formType, $previouslyPostedData);
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             // Persist the case to IRIS
             /** @var ReferencingCase $case */
             $case = $form->getData()['case'];
             $this->irisEntityManager->persist($case);
             /** @var ReferencingApplication $application */
             foreach ($case->getApplications() as $application) {
                 // Always default
                 $application->setSignaturePreference(SignaturePreference::SCAN_DECLARATION);
                 $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId()));
                 // Persist each guarantor of the application
                 if (null !== $application->getGuarantors()) {
                     foreach ($application->getGuarantors() as $guarantor) {
                         $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId()));
                     }
                 }
             }
             $request->getSession()->set('submitted-case', serialize($case));
             // Send the user to the success page
             return $this->redirect($this->generateUrl('barbon_hostedapi_agent_reference_newreference_tenancyagreement_index'), 301);
         }
     }
     return array('form' => $form->createView());
 }
 /**
  * Get ALL references from IRIS that have been paid for.
  *
  * @Route()
  * @Template()
  * @Method({"GET"})
  * @param Request $request
  * @return array
  */
 public function indexAction(Request $request)
 {
     // Firstly, get all references for this user, regardless of application status and payment status.
     $resultSet = $this->referenceRetriever->getReferencesByStatus(null, true);
     if (!$resultSet instanceof ReferencingApplicationSummaryCollection) {
         return array('landlord' => $this->irisEntityManager->find(new DirectLandlord()), 'results' => array(), 'viewMore' => false);
     }
     // Now filter out all references that haven't had a successful payment
     $filteredResults = $this->referenceRetriever->filterByPaymentStatus($resultSet, array(PaymentStatusCodes::SUCCESS));
     // Update the result with the filtered out results.
     $resultSet->setRecords((array) $filteredResults);
     // Only show the 5 most recent results on the dashboard.
     // Break results into 5 per page...
     if (0 < count($resultSet->getRecords())) {
         $resultPages = array_chunk($resultSet->getRecords(), 5);
         // ...then only return the 1st page
         $resultSet->setRecords(reset($resultPages));
         // Do we have more than 1 page?
         $viewMore = 1 < count($resultPages);
     } else {
         // We filtered down to an empty result set.
         $viewMore = false;
         $resultSet = array();
     }
     return array('landlord' => $this->irisEntityManager->find(new DirectLandlord()), 'results' => $resultSet, 'viewMore' => $viewMore);
 }
 /**
  * @Route()
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @param Request $request
  * @return array|RedirectResponse
  *
  * @throws RequestException
  */
 public function indexAction(Request $request)
 {
     $form = $this->createForm($this->directLandlordType, new DirectLandlord(), array('action' => $this->generateUrl('barbon_hostedapi_landlord_authentication_entrypoint_index')))->add('register', 'submit', array('label' => 'Register', 'attr' => array('class' => 'btn-primary pull-right')));
     $masterRequest = $this->container->get('request_stack')->getMasterRequest();
     // Only process if this is the form that's been POSTed
     if ($masterRequest->request->has($form->getName())) {
         $form->handleRequest($masterRequest);
         if ($form->isValid()) {
             $directLandlord = $form->getData();
             $registrationSuccessful = true;
             // Attempt to register direct landlord, handling any errors from IRIS
             try {
                 // Switch to vendor credentials before creating the Landlord
                 // Checking for its existence in the session has already been handled in the EntryPointController
                 $vendorCredentials = $request->getSession()->get('auth-data');
                 $this->irisEntityManager->getClient()->setSystemCredentials($vendorCredentials->get('systemKey'), $vendorCredentials->get('systemSecret'));
                 // Create the Landlord
                 $this->irisEntityManager->persist($directLandlord);
             } catch (RequestException $e) {
                 $registrationSuccessful = false;
                 switch ($e->getCode()) {
                     // Catch missing/invalid details
                     case 400:
                     case 422:
                         $form->addError(new FormError('One or more required details are bad or missing, please contact us if this problem persists.'));
                         break;
                         // Catch duplicate registrations
                     // Catch duplicate registrations
                     case 409:
                         $form->addError(new FormError('A landlord with this e-mail address already exists, please try logging in or resetting your password instead.'));
                         $form->get('email')->addError(new FormError('E-mail address already exists'));
                         break;
                         // Catch and re-throw server errors and any other kind
                     // Catch and re-throw server errors and any other kind
                     case 500:
                     default:
                         throw $e;
                 }
             }
             if ($registrationSuccessful) {
                 // Commence auto login
                 $username = $form->getData()->getEmail();
                 $password = $form->getData()->getPassword();
                 $this->authenticateUser($username, $password);
                 // Return rendered registration successful message
                 return $this->render('BarbonHostedApiLandlordAuthenticationBundle:Register:success.html.twig');
             }
         }
     }
     // Send custom registration text to the view
     $options = $this->systemBrandService->getSystemBrandOptions();
     $customHeaderText = null;
     if (array_key_exists(DisplayPreferences::CUSTOM_TEXT_REGISTRATION_HEADER, $options->getDisplayPreferences()->getCustomText())) {
         $customHeaderText = $options->getDisplayPreferences()->getCustomText()[DisplayPreferences::CUSTOM_TEXT_REGISTRATION_HEADER];
     }
     $form = $form->createView();
     return compact('form', 'customHeaderText');
 }
 /**
  * Get lookup collection model
  *
  * @return LookupCollection
  */
 public function getCollection()
 {
     if (null === $this->lookupCollection) {
         $this->lookupCollection = $this->cache->fetch('LookupCollection');
         if (!$this->lookupCollection) {
             $this->lookupCollection = $this->entityManager->find(new LookupCollection(), array());
             $this->cache->save('LookupCollection', $this->lookupCollection);
         }
     }
     return $this->lookupCollection;
 }
 /**
  * Latest application report
  *
  * @Route("/{applicationId}/report")
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @param $applicationId
  * @return Response
  */
 public function viewApplicationReportAction($applicationId)
 {
     try {
         /** @var Report $report */
         $report = $this->irisEntityManager->find(new Report(), array('applicationId' => $applicationId));
     } catch (NotFoundException $ex) {
         // Case could not be found
         throw $this->createNotFoundException(sprintf('Application with applicationId "%s" could not be found', $applicationId));
     }
     return new Response($report, 200, array('Content-Type' => $report->getContentType()));
 }
 /**
  * Case overview
  *
  * @Route("/{caseId}")
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @param $caseId
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction($caseId)
 {
     try {
         $case = $this->irisEntityManager->find(new ReferencingCase(), array('caseId' => $caseId));
         $applications = $this->irisEntityManager->find(new ReferencingApplicationCollection(), array('caseId' => $caseId));
     } catch (NotFoundException $ex) {
         // Case could not be found
         throw $this->createNotFoundException(sprintf('Case with caseId "%s" could not be found', $caseId));
     }
     return array('caseId' => $caseId, 'case' => $case, 'applications' => $applications);
 }
 /**
  * @param $id
  * @param $rentGuaranteeOfferingType
  * @param $propertyLettingType
  * @return mixed
  * @throws \Exception
  */
 public function lookupLabel($id, $rentGuaranteeOfferingType, $propertyLettingType)
 {
     $products = $this->irisEntityManager->find(new ProductCollection(), array('rentGuaranteeOfferingType' => $rentGuaranteeOfferingType, 'propertyLettingType' => $propertyLettingType));
     // Search the given product ID within the collection of Products retrieved from IRIS.
     foreach ($products as $product) {
         if ($product->getProductId() == $id) {
             return $product->getName();
         }
     }
     // Error if our loop couldn't find a match.
     throw new \Exception(sprintf('Unable to find a valid product name for product ID: %d', $id));
 }
 /**
  * Application overview
  *
  * @Route("/{applicationId}")
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @param $applicationId
  * @return Response
  */
 public function indexAction($applicationId)
 {
     try {
         /** @var Progress $progress */
         $progress = $this->irisEntityManager->find(new Progress(), array('applicationId' => $applicationId));
     } catch (NotFoundException $ex) {
         // Case could not be found
         throw $this->createNotFoundException(sprintf('Progress for applicationId "%s" could not be found', $applicationId));
     }
     $application = $this->getApplication($this->irisEntityManager, $applicationId);
     $case = $this->getCase($this->irisEntityManager, $application->getCaseId());
     $allowAddGuarantor = $this->isAllowedToAddGuarantor($application) ?: false;
     return array('caseId' => $application->getCaseId(), 'case' => $case, 'application' => $application, 'progress' => $progress, 'allowAddGuarantor' => $allowAddGuarantor);
 }
 /**
  * @param IrisEntityManager $irisEntityManager
  * @param string $caseId
  * @return ReferencingApplication
  * @throws NotFoundException
  */
 public function getApplications(IrisEntityManager $irisEntityManager, $caseId)
 {
     try {
         $collection = $irisEntityManager->find(new ReferencingApplicationCollection(), array('caseId' => $caseId));
         if (null !== $collection) {
             $applications = array();
             foreach ($collection as $application) {
                 $applications[] = $application;
             }
         }
         return $applications;
     } catch (NotFoundException $ex) {
         throw new NotFoundException(sprintf('Applications with caseId "%s" could not be found', $caseId));
     }
 }
Example #10
0
 /**
  * Initialise the product collection from the products service
  *
  * @return ProductCollection|null
  */
 private function initialiseChoices()
 {
     // Fetch a vendor key if possible, to cache against
     try {
         $vendorKey = $this->systemBrandService->getVendorCredentials()['vendorKey'];
     } catch (\Exception $e) {
         $vendorKey = 'defaultVendor';
     }
     if (null !== $this->rentGuaranteeOfferingType && null !== $this->propertyLettingType && !$this->isInitialised) {
         $cacheKey = sprintf('Lookup-Product-Collection-%s-%s-%s', $this->rentGuaranteeOfferingType, $this->propertyLettingType, $vendorKey);
         $productCollection = $this->cache->fetch($cacheKey);
         $this->values = array();
         $this->choices = array();
         if (!$productCollection) {
             $productCollection = $this->entityManager->find(new ProductCollection(), array('rentGuaranteeOfferingType' => $this->rentGuaranteeOfferingType, 'propertyLettingType' => $this->propertyLettingType));
             $this->cache->save($cacheKey, $productCollection);
         }
         /** @var \Barbon\HostedApi\AppBundle\Form\Common\Model\Product $product */
         foreach ($productCollection as $product) {
             $this->values[] = (string) $product->getProductId();
             $this->choices[] = (string) $product->getProductId();
             //$product->getName();
             $this->labels[] = (string) $product->getName();
         }
         $this->isInitialised = true;
         return $productCollection;
     }
     return null;
 }
 /**
  * Application overview
  *
  * @Route("/{applicationId}")
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @param $applicationId
  * @return Response
  */
 public function indexAction($applicationId)
 {
     try {
         /** @var ReferencingApplication $application */
         $application = $this->irisEntityManager->find(new ReferencingApplication(), array('applicationId' => $applicationId));
         /** @var Progress $progress */
         $progress = $this->irisEntityManager->find(new Progress(), array('applicationId' => $applicationId));
     } catch (NotFoundException $ex) {
         // Case could not be found
         throw $this->createNotFoundException(sprintf('Application with applicationId "%s" could not be found', $applicationId));
     }
     try {
         /** @var ReferencingCase $case */
         $case = $this->irisEntityManager->find(new ReferencingCase(), array('caseId' => $application->getCaseId()));
     } catch (NotFoundException $ex) {
         // Case could not be found
         throw $this->createNotFoundException(sprintf('Case with caseId "%s" could not be found', $application->getCaseId()));
     }
     return array('caseId' => $application->getCaseId(), 'case' => $case, 'application' => $application, 'progress' => $progress);
 }
 /**
  * @param NewGuarantorReferenceEvent $event
  */
 public function persistGuarantorReference(NewGuarantorReferenceEvent $event)
 {
     $case = $event->getCase();
     $application = $event->getApplication();
     $guarantor = $event->getGuarantor();
     // We don't gather this, but IRIS requires it, so always set to this default.
     $guarantor->setSignaturePreference(SignaturePreference::SCAN_DECLARATION);
     $guarantor->setProduct($application->getProduct());
     // Persist the Guarantor to IRIS, attaching it to the Application.
     $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId()));
     // Put the newly persisted Guarantor into the session
     $this->requestStack->getCurrentRequest()->getSession()->set('submitted-guarantor', serialize($guarantor));
     // Add the Guarantor to the Application.
     $application->setGuarantors(array($guarantor));
     // Add the newly updated Application back into the Case.
     $case->setApplications(array($application));
     // Explicitly set the caseId into the session
     $case->setCaseId($application->getCaseId());
     // Put the newly updated Case back into the session.
     $this->requestStack->getCurrentRequest()->getSession()->set('submitted-case', serialize($case));
 }
 /**
  * Success page after reference purchase
  *
  * @Route()
  * @Method({"GET", "POST"})
  * @Template()
  *
  * @param Request $request
  * @return array
  * @throws CaseNotSubmittedException
  */
 public function indexAction(Request $request)
 {
     // Get the submitted case
     /** @var ReferencingCase $case */
     $case = unserialize($request->getSession()->get('submitted-case'));
     if (false === $case) {
         // Failed to retrieve case from session
         throw new CaseNotSubmittedException('submitted-case could not be retrieved from the session.');
     }
     // Flatten application/guarantor hierarchy in depth first search order
     // todo: only needs doing for applications who are completing now
     $applications = array();
     foreach ($case->getApplications() as $application) {
         $applications[] = $application;
         if (null !== $application->getGuarantors()) {
             foreach ($application->getGuarantors() as $guarantor) {
                 $applications[] = $guarantor;
             }
         }
     }
     $tenancyAgreement = new TenancyAgreement();
     $tenancyAgreement->setApplications($applications);
     // Create form, with flattened data
     $form = $this->createForm(new TenancyAgreementType(), $tenancyAgreement);
     $form->handleRequest($request);
     if ($form->isValid()) {
         // Persist each application/guarantor model with the updated marketing preferences
         /** @var AbstractReferencingApplication $application */
         foreach ($applications as $application) {
             $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId(), 'applicationId' => $application->getApplicationId()));
         }
         // Submit the entire case
         $case->submit($this->irisEntityManager->getClient());
         // Flush the case/applications from the session for the next reference
         $request->getSession()->remove('submitted-case');
         return $this->redirect($this->generateUrl('barbon_hostedapi_agent_reference_cases_view_index', array('caseId' => $case->getCaseId())));
     }
     return array('form' => $form->createView());
 }
 /**
  * Postcode lookup from address
  *
  * @Route("/postcode/{postcode}", defaults={"postcode" = null})
  * @Method({"GET"})
  * @Template()
  *
  * @param Request $request
  * @return Response
  */
 public function postcodeAction(Request $request)
 {
     // Get postcode from request
     $postcode = $request->get('postcode');
     // todo: Check postcode is in valid format
     // Set cache key
     $cacheKey = 'postcodeLookup-' . $postcode;
     // Check if cache contains address lookup details for this postcode
     if ($addressDataJson = $this->cache->fetch($cacheKey)) {
         // Cache hit, do nothing
     } else {
         // Cache miss or stale, do the work of fetching new details
         $addressDataAsPaf = $this->irisEntityManager->find(new AddressLookupCollection(), array('postcode' => $postcode));
         $addressData = $this->addressLookupCollectionToAddressCollection($addressDataAsPaf);
         $addressDataJson = json_encode($addressData);
         // Cache the results
         $this->cache->save($cacheKey, $addressDataJson);
     }
     // Formulate JSON response
     $this->response->headers->set('Content-Type', 'application/json');
     $this->response->setContent($addressDataJson);
     return $this->response;
 }
 /**
  * @param NewMultiReferenceEvent $event
  */
 public function persistMultiReference(NewMultiReferenceEvent $event)
 {
     $case = $event->getCase();
     // Persist the Case to IRIS.
     $this->irisEntityManager->persist($case);
     // Process each Tenant Application.
     foreach ($case->getApplications() as $application) {
         // We don't gather this, but IRIS requires it, so always set to this default.
         $application->setSignaturePreference(SignaturePreference::SCAN_DECLARATION);
         // Persist the Applicant to IRIS.
         $this->irisEntityManager->persist($application, array('caseId' => $case->getCaseId()));
         // If present, process each Guarantor of the Application.
         if (null !== $application->getGuarantors()) {
             foreach ($application->getGuarantors() as $guarantor) {
                 // We don't gather this, but IRIS requires it, so always set to this default.
                 $guarantor->setSignaturePreference(SignaturePreference::SCAN_DECLARATION);
                 // Persist the Guarantor to IRIS.
                 $this->irisEntityManager->persist($guarantor, array('applicationId' => $application->getApplicationId()));
             }
         }
     }
     // Put the newly updated Case back into the session.
     $this->requestStack->getCurrentRequest()->getSession()->set('submitted-case', serialize($case));
 }
 /**
  * Create a ReferencingCase with pre populated ProspectiveLandlord object.
  *
  * @return ReferencingCase
  */
 private function getPrePopulatedCase()
 {
     // First, get the DirectLandlord object from IRIS and instantiate an empty ProspectiveLandlord.
     $directLandlord = $this->irisEntityManager->find(new DirectLandlord());
     $prospectiveLandlord = new ProspectiveLandlord();
     // Now map the DirectLandlord into a new ProspectiveLandlord:
     // foreach property in the DirectLandlord, if the ProspectiveLandlord contains a setter method, set it using the corresponding get method.
     // TODO getter and setter discovery can be handled more effectively
     $directLandlordReflect = new \ReflectionClass($directLandlord);
     $properties = $directLandlordReflect->getProperties();
     foreach ($properties as $property) {
         $setMethod = sprintf('set%s', ucfirst($property->getName()));
         $getMethod = sprintf('get%s', ucfirst($property->getName()));
         if (method_exists($prospectiveLandlord, $setMethod) && method_exists($directLandlord, $getMethod)) {
             $prospectiveLandlord->{$setMethod}($directLandlord->{$getMethod}());
         }
     }
     // Add the newly formed ProspectiveLandlord to the case.
     $case = new ReferencingCase();
     $case->setProspectiveLandlord($prospectiveLandlord);
     return $case;
 }
 /**
  * Fetch a system brand object from cache or via REST, using the vendor key and secret
  *
  * @param mixed $model
  * @param string $cacheKeyRoot
  * @return mixed
  * @throws \Exception
  */
 private function getCachableSystemBrandObject($model, $cacheKeyRoot)
 {
     $vendorCredentials = $this->getVendorCredentials();
     $cacheKey = $cacheKeyRoot . '-' . $vendorCredentials['vendorKey'];
     // Check if cache contains system brand object details for this key
     if ($systemBrandObjectSerialized = $this->cache->fetch($cacheKey)) {
         // Cache hit
         $systemBrandObject = unserialize($systemBrandObjectSerialized);
     } else {
         // Cache miss or stale, do the work of fetching new details
         // Temporarily "resume" the vendor's key and secret for the brand details lookup
         $irisClient = $this->irisEntityManager->getClient();
         // Take note of the original auth details to set back to
         $originalAuth = $irisClient->getSubscriber();
         // Switch to using the vendor credentials and look up the system brand object
         $client = $irisClient->resume(array('consumerKey' => $vendorCredentials['vendorKey'], 'consumerSecret' => $vendorCredentials['vendorSecret']));
         $systemBrandObject = $this->irisEntityManager->find($model);
         // Now resume the original auth
         $irisClient->setSubscriber($originalAuth);
         // Cache the results
         $this->cache->save($cacheKey, serialize($systemBrandObject));
     }
     return $systemBrandObject;
 }
 /**
  * Fetch all products available to this vendor.
  * todo: Hardcoded criteria should come from user input data instead.
  *
  * @return ProductCollection
  */
 protected function getProducts()
 {
     $criteria = array('rentGuaranteeOfferingType' => 1, 'propertyLettingType' => 1);
     $products = $this->irisEntityManager->find(new ProductCollection(), $criteria);
     return $products;
 }
 /**
  * @param AbstractReferencingApplication $application
  * @param $caseId
  */
 protected function persistMarketingPreferences(AbstractReferencingApplication $application, $caseId)
 {
     $this->irisEntityManager->persist($application, array('caseId' => $caseId, 'applicationId' => $application->getApplicationId()));
 }
 /**
  * @param $productId
  * @param ReferencingCase $case
  * @param AbstractReferencingApplication $application
  * @param int $guarantorSequenceNumber
  * @return int
  */
 public function getPrice($productId, ReferencingCase $case, AbstractReferencingApplication $application, $guarantorSequenceNumber = 0)
 {
     $criteria = array('productId' => $productId, 'propertyLetType' => $case->getPropertyLetType(), 'rentGuaranteeOfferingType' => $case->getRentGuaranteeOfferingType(), 'shareOfRent' => $application->getRentShare(), 'policyLengthInMonths' => $case->getTenancyTerm(), 'guarantorSequenceNumber' => $guarantorSequenceNumber, 'isRenewal' => 0);
     $productPrice = $this->irisEntityManager->find(new ProductPrice(), $criteria);
     return $productPrice->getGrossPrice();
 }
 /**
  * {@inheritdoc}
  */
 public function refreshUser(UserInterface $user)
 {
     // set the consumer key and secret into the OAuth client
     $this->irisEntityManager->getClient()->resume(array('consumerKey' => $user->getConsumerKey(), 'consumerSecret' => $user->getConsumerSecret()));
     return $user;
 }