/** * Controller for the direct debit payment page * * @return void */ public function ddAction() { $pageForm = new LandlordsInsuranceQuote_Form_BankConfirmation(); $pageSession = new Zend_Session_Namespace('landlords_insurance_quote'); // Tell page NOT to use AJAX validation as we go $this->view->headScript()->appendScript('var ajaxValidate = false; var ajaxValidatePage = \'dd\';'); // Look up bank details to show in view $bankManager = new Manager_Core_Bank(); $this->view->branchDetails = $bankManager->getBranchDetail($pageSession->paymentSelectionDetails['bank_sortcode_number']); // Drop the branch address lines into an array for accessing on the // front-end. $this->view->branchLines = array($this->view->branchDetails->bankNameFull, $this->view->branchDetails->addressLine1, $this->view->branchDetails->addressLine2, $this->view->branchDetails->addressLine3, $this->view->branchDetails->addressLine4, $this->view->branchDetails->town, $this->view->branchDetails->county, $this->view->branchDetails->postCode); if ($this->getRequest()->isPost()) { $valid = $this->_formStepCommonValidate($pageForm, 'dd'); if ($valid && isset($_POST['next'])) { // Form is valid and the user has confirmed the bank branch details $pageSession->completed['dd'] = true; // Mark page as valid, so user can progress $quoteManager = new Manager_Insurance_LandlordsPlus_Quote($this->_quoteID); // Save the direct debit details and redirect to confirmation page $ddData = new Model_Core_Directdebit(); $ddData->refNo = $this->_customerReferenceNumber; $ddData->policyNumber = $quoteManager->getPolicyNumber(); $ddData->accountName = $pageSession->paymentSelectionDetails['dd_accountname']; $ddData->accountNumber = $pageSession->paymentSelectionDetails['bank_account_number']; $ddData->sortCode = str_replace('-', '', $pageSession->paymentSelectionDetails['bank_sortcode_number']); $startDate = $quoteManager->getStartDate(); $firstPayMonth = date('Y-m-d', strtotime("{$startDate} + 1 month")); $ddData->paymentDate = $firstPayMonth; $ddData->paymentFrequency = ucfirst(strtolower($quoteManager->getPayBy())); // Instantiate a DD manager $ddPayment = new Manager_Core_Directdebit(); // Save the stuffs $ddPayment->save($ddData); $this->_formStepCommonNavigate('dd'); return; } if (isset($_POST['back'])) { $this->_formStepCommonNavigate('dd'); return; } } // Load the element data from the database if we can if ($this->_formStepCommonPopulate($pageForm, 'dd')) { // Render the page unless we have been redirected $this->view->form = $pageForm; $this->view->stepNum = 'dd'; $this->render('step'); } }