/**
  * Retrieve the document
  *
  * @param string $policyNumber Policy number
  * @param string $documentId Unique document request hash
  * @return string null or PDF contents
  */
 private function _fetchDocument($policyNumber, $documentId)
 {
     // Get the customer session
     $customerSession = $this->auth->getStorage()->read();
     // Get the request policy
     if ($policyNumber[0] == 'Q') {
         // Quotes
         $legacyPolicies = new Datasource_Insurance_LegacyQuotes();
     } else {
         // Policies
         $legacyPolicies = new Datasource_Insurance_LegacyPolicies();
     }
     $policy = $legacyPolicies->getByPolicyNumber($policyNumber);
     if (!$policy) {
         return null;
     }
     // Check the policy customer refno is linked to the customer id through mapping
     $customerMaps = new Datasource_Core_CustomerMaps();
     $customerMap = $customerMaps->getMap(Model_Core_Customer::LEGACY_IDENTIFIER, $policy->refNo);
     // Confirm the policy number belongs to the logged in customer
     if ($customerMap == false || $customerMap->getIdentifier() != $customerSession->id) {
         // Customer map not found or customer is not mapped to refno, render error message
         return null;
     }
     // Get all document details
     $documentHistory = new Datasource_Insurance_DocumentHistory();
     $document = $documentHistory->getDocument($documentId, $policyNumber);
     if (!$document) {
         return null;
     }
     // Retrieve document from store
     $documentFulfillmentService = new Service_Insurance_Document();
     return $documentFulfillmentService->retrieveDocumentFromStore($documentId, $document->template_name, Service_Insurance_Document::DOCUMENT_AND_ATTACHMENTS);
 }
 public function fetchDocumentAction()
 {
     $request = $this->getRequest();
     $hash = $request->getParam('requestHash');
     $docName = $request->getParam('documentName');
     $docs = new Service_Insurance_Document();
     // Insurance Document Service Call - fetchDocument()
     $response = $docs->fetchDocument($hash, $docName);
     $this->_helper->redirector->gotoUrlAndExit($response);
 }