/**
  * Retrieve TCI+ or LI+ quote.
  */
 public function retrieveQuoteAction()
 {
     $this->_setBreadcrumbs(array('/' => 'Home', '/my-homelet' => 'My HomeLet', '/my-homelet/retrieve-quote' => 'Retrieve Quote'));
     $params = Zend_Registry::get('params');
     $form = new Account_Form_RetrieveQuote();
     $quoteManager = new Manager_Insurance_LegacyQuote();
     $customerManager = new Manager_Core_Customer();
     // If there's a quote number in the GET vars then sanitise and uppercase it, and place it in the form
     if (isset($_GET['number'])) {
         // Sanitise and uppercase supplied quote number, place in form
         $quoteNumber = strtoupper(preg_replace('/[^\\w\\/]/', '', $_GET['number']));
         $form->quote_number->setValue($quoteNumber);
         // Also pre-populate the form with first name and last name if the quote number is valid
         $quote = $quoteManager->getQuoteByPolicyNumber($quoteNumber);
         if ($quote) {
             // Get customer details from quote refNo
             $quoteRefNo = $quote->refNo;
             $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
             if ($customer) {
                 $form->first_name->setValue($customer->getFirstName());
                 $form->last_name->setValue($customer->getLastName());
             }
         }
     }
     // Get email address, place in form if it looks valid
     if (isset($_GET['email'])) {
         $getEmail = $_GET['email'];
         $emailValidator = new Zend_Validate_EmailAddress();
         if ($emailValidator->isValid($getEmail)) {
             $form->email->setValue($getEmail);
         }
     }
     $request = $this->getRequest();
     $postData = $request->getPost();
     // Handle retrieve attempts
     if ($request->isPost()) {
         if ($form->isValid($postData)) {
             // Are we looking up by quote number or by e-mail address?  If a quote number is present it takes
             // precedence
             $quotes = array();
             $customer = null;
             $quoteNumber = $form->quote_number->getValue();
             $email = $form->email->getValue();
             if ('' != $quoteNumber) {
                 $quote = $quoteManager->getQuoteByPolicyNumber($quoteNumber);
                 if ($quote) {
                     // Look up customer from quote retrieved
                     $quoteRefNo = $quote->refNo;
                     $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
                     $quotes = array($quote);
                 }
             } else {
                 // Get all legacy quote IDs by customer e-mail address
                 $legacyIDs = array();
                 // Try to look up a customer record's quotes' IDs by the e-mail provided
                 $newCustomer = $customerManager->getCustomerByEmailAddress($email);
                 if ($newCustomer) {
                     $legacyCustomerMap = new Datasource_Core_CustomerMaps();
                     $legacyIDs = $legacyCustomerMap->getLegacyIDs($newCustomer->getIdentifier(Model_Core_Customer::IDENTIFIER));
                 }
                 // Also check in the legacy DB only to ensure landlords quotes are found
                 $customer = $customerManager->getLegacyCustomerByEmailAddress($email);
                 if ($customer) {
                     $legacyCustomerId = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
                     if (!in_array($legacyCustomerId, $legacyIDs)) {
                         $legacyIDs[] = $legacyCustomerId;
                     }
                 }
                 // Retrieve all quotes for the linked customer reference numbers
                 $quoteDatasource = new Datasource_Insurance_LegacyQuotes();
                 $quotes = $quoteDatasource->getActiveQuotes($legacyIDs, '', array('policynumber', 'startdate'));
             }
             // Do we have at least one quote and the customer details
             if (count($quotes) > 0 && $customer) {
                 // Check that the security requirements are met (matching email, first name, last name, postcode and
                 // DOB)
                 if (trim($customer->getEmailAddress()) == trim($form->email->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getFirstName(), $form->first_name->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getLastName(), $form->last_name->getValue()) && Application_Core_Utilities::simplifiedStringCompare($customer->getPostCode(), $form->cor_postcode->getValue()) && Application_Core_Utilities::mysqlDateToUk($customer->getDateOfBirthAt()) == trim($form->date_of_birth_at->getValue())) {
                     // If this is a single quote then generate an auth token and bounce them on
                     if (count($quotes) == 1) {
                         // Ensure there's a quote number to use in the security token (because there won't be one if
                         // it was a single match based only on an e-mail address)
                         if ('' == $quoteNumber) {
                             $quoteNumber = $quotes[0]->policyNumber;
                         }
                         // Generate an authentication token for a single policy
                         $securityManager = new Application_Core_Security($params->myhomelet->retrieveWithoutAccount->macSecret, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance != 0, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance);
                         $securityData = array('quoteNumber' => $quoteNumber);
                         $authToken = $securityManager->generate($securityData);
                         // Bounce to the right Q&B depending on quote type
                         if ($quotes[0]->getProductName() == 'tenants') {
                             $this->_helper->redirector->gotoUrl('/tenants/insurance-quote/retrieve?auth=' . $authToken);
                             return;
                         } elseif ($quotes[0]->getProductName() == 'landlords') {
                             $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/retrieve?auth=' . $authToken);
                             return;
                         } else {
                             $form->setDescription('Sorry, we don\'t yet allow resuming the type of quote you have - please call us.');
                         }
                     } else {
                         // Generate an authentication token for the customer email
                         $securityManager = new Application_Core_Security($params->myhomelet->retrieveWithoutAccount->macSecret, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance != 0, $params->myhomelet->retrieveWithoutAccount->macTimestampVariance);
                         $securityData = array('customerEmail' => $email);
                         $authToken = $securityManager->generate($securityData);
                         $this->_helper->redirector->gotoUrl('/my-homelet/retrieve-multiple-quotes?auth=' . $authToken);
                         return;
                     }
                 } else {
                     // Security check failed, show error
                     $form->setDescription('Sorry, we could not find your quote from the details provided - please check them and try again.');
                 }
             } else {
                 // Lookup failed, show error
                 $form->setDescription('Sorry, we could not find your quote from the details provided - please check them and try again.');
             }
         }
     }
     $this->view->form = $form;
 }
Beispiel #2
0
 /**
  * Intended to be run by cron.
  *
  * Looks through recent quotes to process mailers for.  Criteria to be satisfied: a) must be x minutes old (eg,
  * probably abandoned) (also should be no older than y to prevent historic quotes being pinged), b) user must have
  * reached at least step z, and c) no mailer has been sent.
  *
  * Values for x, y and z are set in parameters and are independent of the web lead view and status from IAS.
  *
  * @return void
  */
 public function sendMailers()
 {
     // Prepare web lead summary data source
     if (null == $this->_webLeadSummaries) {
         $this->_webLeadSummaries = new Datasource_Core_WebLeadSummaries();
     }
     // Fetch relevant parameters
     $params = Zend_Registry::get('params');
     $hourOffset = $params->weblead->hourOffset;
     $minLastUpdated = $params->weblead->mailer->abandonedAge;
     // In seconds
     $maxLastUpdated = $params->weblead->mailer->ignoredAge;
     // In seconds
     $mailerAtSteps = array(Model_Core_WebLeadProduct::TCIPLUS => array('continueQuote' => explode(',', $params->weblead->mailer->tenant->continueQuote->steps), 'completeQuote' => explode(',', $params->weblead->mailer->tenant->completeQuote->steps)), Model_Core_WebLeadProduct::LANDLORDSPLUS => array('continueQuote' => explode(',', $params->weblead->mailer->landlord->continueQuote->steps), 'completeQuote' => explode(',', $params->weblead->mailer->landlord->completeQuote->steps)));
     $mailerProduct = array(Model_Core_WebLeadProduct::TCIPLUS => 'tenant', Model_Core_WebLeadProduct::LANDLORDSPLUS => 'landlord');
     $searchCriteria = array('hourOffset' => $hourOffset, 'minLastUpdated' => $minLastUpdated, 'maxLastUpdated' => $maxLastUpdated, 'products' => array(Model_Core_WebLeadProduct::TCIPLUS, Model_Core_WebLeadProduct::LANDLORDSPLUS), 'isMailerSent' => 0);
     // Fetch summaries that match the criteria
     $webLeadSummaries = $this->_webLeadSummaries->searchActiveSummaries($searchCriteria);
     // Early exit if there's nothing to do
     if (count($webLeadSummaries) == 0) {
         return;
     }
     // Loop through summaries looking for those that meet a "mailer at step" requirement
     foreach ($webLeadSummaries as $webLeadSummary) {
         $product = $webLeadSummary->product;
         $maxCompletedStep = $this->getBlobMaxStep($webLeadSummary->webLeadSummaryId);
         foreach ($mailerAtSteps[$product] as $mailerType => $mailerStepFilter) {
             if (in_array($maxCompletedStep, $mailerStepFilter)) {
                 // We need to send a mailer!
                 $mail = new Application_Core_Mail();
                 $link = str_replace('http:', 'https:', $params->homelet->domain) . $params->weblead->mailer->retrieveRelativeUrl;
                 $link = str_replace(array('[quoteNumber]', '[email]'), array($webLeadSummary->quoteNumber, $webLeadSummary->emailAddress), $link);
                 $replacements = array('title' => $webLeadSummary->title, 'firstName' => $webLeadSummary->firstName, 'lastName' => $webLeadSummary->lastName, 'fullName' => "{$webLeadSummary->title} {$webLeadSummary->firstName} {$webLeadSummary->lastName}", 'quoteNumber' => $webLeadSummary->quoteNumber, 'link' => htmlentities($link), 'imageBaseUrl' => $params->weblead->mailer->imageBaseUrl);
                 $subjectLine = $params->weblead->mailer->{$mailerProduct[$product]}->{$mailerType}->subject;
                 foreach ($replacements as $key => $val) {
                     $subjectLine = str_replace("[{$key}]", $val, $subjectLine);
                 }
                 $replacements['pageTitle'] = $subjectLine;
                 // If this is a "Complete Quote" mailer then fetch the actual quote to get some values out of it
                 if ('completeQuote' == $mailerType) {
                     $replacements['annualPremium'] = '';
                     $replacements['monthlyPremium'] = '';
                     $replacements['expiryDate'] = '';
                     $quoteManager = new Manager_Insurance_LegacyQuote();
                     $quote = $quoteManager->getQuoteByPolicyNumber($webLeadSummary->quoteNumber);
                     if ($quote) {
                         if ('Annually' == $quote->payBy) {
                             $replacements['annualPremium'] = number_format($quote->quote, 2);
                             $replacements['monthlyPremium'] = number_format($quote->quote / 12, 2);
                         } else {
                             $replacements['annualPremium'] = number_format($quote->quote * 12, 2);
                             $replacements['monthlyPremium'] = number_format($quote->quote, 2);
                         }
                         $replacements['expiryDate'] = $quote->getExpiresAt();
                     }
                 }
                 $template = $params->weblead->mailer->{$mailerProduct[$product]}->{$mailerType}->template;
                 $mail->setTo($webLeadSummary->emailAddress, $replacements['fullName'])->setFrom($params->weblead->mailer->fromAddress, $params->weblead->mailer->fromName)->setSubject($subjectLine)->applyTemplate($template, $replacements, true);
                 $mail->send();
                 // Update web lead summary to mark mailer as sent
                 $webLeadSummary->isMailerSent = true;
                 $this->_webLeadSummaries->updateSummary($webLeadSummary);
             }
         }
     }
 }
 /**
  * Resume an existing quote for customers who either have a temporary auth token for a retrieval with no My HomeLet
  * account, or who are My HomeLet authenticated.  Customers with no form of valid authentication are redirected to
  * the My HomeLet login page.
  *
  * @return void
  */
 public function retrieveAction()
 {
     // Authorisation using no-account My HomeLet retrieval auth token
     if ($this->getRequest()->getParam('auth') != '') {
         $mac = $this->getRequest()->getParam('auth');
         $securityManager = new Application_Core_Security($this->_params->myhomelet->retrieveWithoutAccount->macSecret, $this->_params->myhomelet->retrieveWithoutAccount->macTimestampVariance != 0, $this->_params->myhomelet->retrieveWithoutAccount->macTimestampVariance);
         $dataKeys = array('quoteNumber');
         $securityCheck = $securityManager->authenticate($mac, $dataKeys);
         if (isset($securityCheck['result']) && $securityCheck['result']) {
             $quoteNumber = $securityCheck['data']['quoteNumber'];
             $quoteManager = new Manager_Insurance_LegacyQuote();
             $customerManager = new Manager_Core_Customer();
             $quote = $quoteManager->getQuoteByPolicyNumber($quoteNumber);
             $quoteRefNo = $quote->refNo;
             $customer = $customerManager->getCustomer(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
             $customerID = $referenceNumber = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER, $quoteRefNo);
             $quoteManager = new Manager_Insurance_LandlordsPlus_Quote(null, $quoteNumber, null, $customerID);
             $quote = $quoteManager->getModel();
             $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
             $pageSession->quoteID = $quote->ID;
             $pageSession->customerRefNo = $referenceNumber;
             //Retrieve the WebLead summary ID so that the WebLead can continue to be updated and important
             //details captured, such as the campaign code.
             $webLeadManager = new Manager_Core_WebLead();
             $pageSession->webLeadSummaryId = $webLeadManager->getSummaryId($quoteNumber);
             $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/step1');
             return;
         }
     }
     // Authorisation using My HomeLet logged in details
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('homelet_customer'));
     if ($auth->hasIdentity()) {
         // Check to see if we have a reference number to load up
         if ($this->getRequest()->getParam('quote') != '') {
             $quoteNumber = $this->getRequest()->getParam('quote');
             // Customer is logged in and is trying to retrieve a specific quote
             // We need to check to make sure they own it
             $customerID = $auth->getStorage()->read()->id;
             // Now we need to get their legacy ID
             $customerManager = new Manager_Core_Customer();
             $customer = $customerManager->getCustomer(Model_Core_Customer::IDENTIFIER, $customerID);
             $referenceNumber = $customer->getIdentifier(Model_Core_Customer::LEGACY_IDENTIFIER);
             // Need to find the quote ID by the policy number
             $quotes = new Manager_Insurance_LandlordsPlus_Quote(null, $quoteNumber, null, $customerID);
             $quote = $quotes->getModel();
             $legacyCustomerMap = new Datasource_Core_CustomerMaps();
             $legacyIDs = $legacyCustomerMap->getLegacyIDs($customerID);
             if (in_array($quote->legacyCustomerID, $legacyIDs)) {
                 // This customer does own this reference - so set the page session stuff up and redirect
                 $pageSession = new Zend_Session_Namespace('landlords_insurance_quote');
                 $pageSession->quoteID = $quote->ID;
                 $pageSession->customerRefNo = $referenceNumber;
                 //Retrieve the WebLead summary ID so that the WebLead can continue to be updated and important
                 //details captured, such as the campaign code.
                 $webLeadManager = new Manager_Core_WebLead();
                 $pageSession->webLeadSummaryId = $webLeadManager->getSummaryId($quoteNumber);
                 $this->_helper->redirector->gotoUrl('/landlords/insurance-quote/step1');
             }
         }
     }
     $this->_helper->redirector->gotoUrl('/login?referrerUrl=/my-homelet/quotes');
 }