public function display()
 {
     if (isset($_POST['next'])) {
         unset($_POST['next']);
         // To prevent unwarranted use of browser back button.
         if (!isset($_SESSION['payAccountID'])) {
             header('Location: New-Bill-Payment');
         }
         // Process on submission of password.
         if (isset($_POST['password'])) {
             $validate = new Validation();
             // Validate the password.
             try {
                 $validate->password($_POST['password']);
             } catch (ValidationException $e) {
                 $_SESSION['error'] = $e->getError();
             }
             if (isset($_SESSION['error'])) {
                 unset($_POST['password']);
                 header('Location: Bill-Payment-Amount');
             } else {
                 $user = new Users();
                 $user->userID = $_SESSION['userID'];
                 $user->password = $_POST['password'];
                 unset($_POST['password']);
                 // Check for a password match.
                 try {
                     $user->confirmPassword();
                 } catch (ValidationException $e) {
                     $_SESSION['error'] = $e->getError();
                 }
                 if (isset($_SESSION['error'])) {
                     header('Location: Bill-Payment-Amount');
                 } else {
                     // Process the payment.
                     $account = new Account();
                     $account->accountID = $_SESSION['payAccountID'];
                     if ($account->processPayment()) {
                         // Display the Acknowledgement Page.
                         $paymentack = new Paymentack();
                         $paymentack->init();
                         include 'view/layout/paymentack.php';
                         unset($_SESSION['payCreated']);
                         unset($_SESSION['payDate']);
                         unset($_SESSION['payAccountID']);
                         unset($_SESSION['payAmount']);
                         unset($_SESSION['payStatus']);
                         unset($_SESSION['payConf']);
                         unset($_SESSION['payAccount']);
                         unset($_SESSION['payBillerCode']);
                         unset($_SESSION['payBillerName']);
                         unset($_SESSION['payBillerNickname']);
                         unset($_SESSION['payCustomerRef']);
                     } else {
                         // Display the Payment Confirmation Page.
                         $paymentconf = new Paymentconf();
                         $paymentconf->init();
                         include 'view/layout/paymentconf.php';
                     }
                 }
             }
         }
         // Cancel the Payment
     } else {
         if (isset($_POST['cancel'])) {
             unset($_POST['cancel']);
             $payment = new Payment();
             $payment->cancelSessions();
             // Return to the Payment Page.
             $payment->init();
             include 'view/layout/payment.php';
         } else {
             // For any other reason, return to the Payment page.
             $payment = new Payment();
             $payment->init();
             include 'view/layout/payment.php';
         }
     }
 }
 public function display()
 {
     // Process if posted to from the Payment Amount Page.
     if (isset($_POST['next'])) {
         unset($_POST['next']);
         // In the event the back button is hit on the browser
         // after the transaction has been processed.
         if (!isset($_SESSION['payBillerCode']) || !isset($_SESSION['payBillerName']) || !isset($_SESSION['payBillerNickname'])) {
             header("Location: New-Bill-Payment");
         }
         if (isset($_POST['account'])) {
             $_SESSION['payAccountID'] = $_POST['account'];
             unset($_POST['account']);
         }
         $validate = new Validation();
         if (isset($_POST['custref'])) {
             // Validate the customer reference.
             try {
                 $custref = $_POST['custref'];
                 unset($_POST['custref']);
                 $validate->custref($custref);
             } catch (ValidationException $e) {
                 $_SESSION['error'] = $e->getError();
             }
             if (isset($_SESSION['error'])) {
                 $custref = null;
                 unset($_POST['next']);
                 header('Location: Bill-Payment-Amount');
             } else {
                 $_SESSION['payCustomerRef'] = $custref;
                 if (isset($_POST['amount'])) {
                     // Validate the amount.
                     try {
                         $amount = $_POST['amount'];
                         unset($_POST['amount']);
                         $validate->payAmount($amount);
                     } catch (ValidationException $e) {
                         $_SESSION['error'] = $e->getError();
                     }
                     if (isset($_SESSION['error'])) {
                         $amount = null;
                         unset($_POST['next']);
                         header('Location: Bill-Payment-Amount');
                     } else {
                         $_SESSION['payAmount'] = $amount;
                         if (isset($_POST['paymentDate'])) {
                             // Validate the date.
                             try {
                                 $paymentDate = $_POST['paymentDate'];
                                 unset($_POST['paymentDate']);
                                 $validate->payDate($paymentDate);
                             } catch (ValidationException $e) {
                                 $_SESSION['error'] = $e->getError();
                             }
                             if (isset($_SESSION['error'])) {
                                 $paymentDate = null;
                                 unset($_POST['next']);
                                 header('Location: Bill-Payment-Amount');
                             } else {
                                 // If all is OK, display the Payment Confirmation Page.
                                 $_SESSION['payDate'] = $paymentDate;
                                 $paymentconf = new Paymentconf();
                                 $paymentconf->init();
                                 include 'view/layout/paymentconf.php';
                             }
                         }
                     }
                 }
             }
         }
         // Cancel the Payment
     } else {
         if (isset($_POST['cancel'])) {
             unset($_POST['cancel']);
             $payment = new Payment();
             $payment->cancelSessions();
             $payment->init();
             include 'view/layout/payment.php';
         } else {
             // For any other reason, display the Payment Page.
             $payment = new Payment();
             $payment->cancelSessions();
             $payment->init();
         }
     }
 }