Index: main/waeup.aaue/trunk/CHANGES.txt
===================================================================
--- main/waeup.aaue/trunk/CHANGES.txt	(revision 12974)
+++ main/waeup.aaue/trunk/CHANGES.txt	(revision 12975)
@@ -4,4 +4,11 @@
 1.2dev (unreleased)
 ===================
+
+* To guarantee that cleared students pay both acceptance fees and
+  school fees, a school fee payment POST request to the Interswitch
+  CollegePAY payment gateway can only be sent if
+  acceptance/clearance fee has been successfully queried/paid
+  beforehand. This requirement applies to students in state 'cleared'
+  and entry_session greater than 2013 only.
 
 * Add and configure Interswitch module.
Index: main/waeup.aaue/trunk/src/waeup/aaue/etranzact/browser.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/etranzact/browser.py	(revision 12974)
+++ main/waeup.aaue/trunk/src/waeup/aaue/etranzact/browser.py	(revision 12975)
@@ -283,7 +283,7 @@
             return
         student = self.context.student
-        if self.context.student.state != CLEARED:
-            return
-        if self.context.student.entry_session < 2013:
+        if student.state != CLEARED:
+            return
+        if student.entry_session < 2013:
             return
         for ticket in student['payments'].values():
Index: main/waeup.aaue/trunk/src/waeup/aaue/etranzact/tests.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/etranzact/tests.py	(revision 12974)
+++ main/waeup.aaue/trunk/src/waeup/aaue/etranzact/tests.py	(revision 12975)
@@ -61,6 +61,5 @@
                            self.browser.contents)
         ctrl = self.browser.getControl(name='val_id')
-        value = ctrl.options[0]
-        self.student['payments'][value].approve()
+        value1 = ctrl.options[0]
 
         self.browser.open(self.payments_path + '/addop')
@@ -70,7 +69,7 @@
                            self.browser.contents)
         ctrl = self.browser.getControl(name='val_id')
-        value = ctrl.options[1]
-        self.p_id = value
-        self.browser.getLink(value).click()
+        value2 = ctrl.options[1]
+        self.p_id = value2
+        self.browser.getLink(value2).click()
         self.assertMatches('...Amount Authorized...',
                            self.browser.contents)
@@ -78,8 +77,17 @@
 
     def test_enterpin(self):
+        self.student['studycourse'].entry_session = 2013
+        self.browser.open(self.payment_url)
         self.browser.getLink("Query eTranzact History").click()
-        self.assertMatches(
-            '...Confirmation Number (PIN)...',
-            self.browser.contents)
+        self.assertTrue(
+            'Please pay acceptance fee firs' in self.browser.contents)
+        self.assertFalse(
+            'Confirmation Number (PIN)' in self.browser.contents)
+        self.student['payments'].values()[0].approve()
+        self.browser.getLink("Query eTranzact History").click()
+        self.assertFalse(
+            'Please pay acceptance fee firs' in self.browser.contents)
+        self.assertTrue(
+            'Confirmation Number (PIN)' in self.browser.contents)
 
     def test_webservice(self):
Index: main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py	(revision 12974)
+++ main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py	(revision 12975)
@@ -21,4 +21,5 @@
 from zope.interface import Interface
 from zope.component import queryAdapter
+from waeup.kofa.interfaces import CLEARED
 from kofacustom.nigeria.interswitch.browser import (
     InterswitchPaymentRequestWebservicePageStudent,
@@ -68,5 +69,9 @@
     def update(self):
 
-        super(CustomInterswitchPageApplicant, self).update()
+        error = self.init_update()
+        if error:
+            self.flash(error, type='danger')
+            self.redirect(self.url(self.context, '@@index'))
+            return
         xmldict = {}
         provider_amt = 1000.0
@@ -116,9 +121,32 @@
 
     def update(self):
-        #self.flash('Payment method not yet configured.', type='danger')
-        #self.redirect(self.url(self.context, '@@index'))
-        #return
-        super(CustomInterswitchPageStudent, self).update()
+        error = self.init_update()
+        if error:
+            self.flash(error, type='danger')
+            self.redirect(self.url(self.context, '@@index'))
+            return
         student = self.student
+
+        # To guarantee that cleared students pay both acceptance fee
+        # and school fees, the page can only be accessed
+        # for school fee payments if acceptance/clearance fee has
+        # been successfully queried/paid beforehand. This
+        # requirement applies to students in state 'cleared' and
+        # entry_session greater than 2013 only.
+        if self.context.p_category == 'schoolfee' and \
+            student.state == CLEARED and \
+            student.entry_session > 2012:
+            acceptance_fee_paid = False
+            for ticket in student['payments'].values():
+                if ticket.p_state == 'paid' and \
+                    ticket.p_category == 'clearance':
+                    acceptance_fee_paid = True
+                    break
+            if not acceptance_fee_paid:
+                self.flash(
+                    _('Please pay acceptance fee first.'), type="danger")
+                self.redirect(self.url(self.context, '@@index'))
+                return
+
         xmldict = self.xmldict
         xmltext = ""
Index: main/waeup.aaue/trunk/src/waeup/aaue/interswitch/tests.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/interswitch/tests.py	(revision 12974)
+++ main/waeup.aaue/trunk/src/waeup/aaue/interswitch/tests.py	(revision 12975)
@@ -107,4 +107,5 @@
 
     def test_interswitch_form_school_fees(self):
+        self.student['studycourse'].entry_session = 2013
         self.app['configuration']['2004'].school_fee_1 = 51750.0
         # Manager can access InterswitchForm
@@ -128,4 +129,11 @@
         self.payment_url = self.browser.url
         self.browser.getLink("CollegePAY", index=0).click()
+        self.assertTrue(
+            'Please pay acceptance fee first' in self.browser.contents)
+        acc_payment = createObject('waeup.StudentOnlinePayment')
+        acc_payment.p_state = 'paid'
+        acc_payment.p_category = 'clearance'
+        self.student['payments']['xyz'] = acc_payment
+        self.browser.getLink("CollegePAY", index=0).click()
         self.assertMatches('...<input type="hidden" name="pay_item_id" value="105" />...',
                            self.browser.contents)
@@ -139,4 +147,5 @@
             '...item_name="School Fee" item_amt="4600000" bank_id="7" acct_num="1014847058"...',
             self.browser.contents)
+
 
     def test_interswitch_form_acceptance_fees(self):
Index: main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py	(revision 12974)
+++ main/waeup.aaue/trunk/src/waeup/aaue/students/utils.py	(revision 12975)
@@ -81,12 +81,18 @@
             and student.state in (PAID, ) \
             and student.is_fresh:
-            return None, "PTP/%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
+            return None, "PTP/%s/%s/%s/%05d" % (
+                faccode, depcode, year, next_integer)
+
         #if student.current_mode in ('pg_ft', 'pg_pt'):
-        #    return None, "SPS/%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
+        #    return None, "SPS/%s/%s/%s/%05d" % (
+        #    faccode, depcode, year, next_integer)
         #if student.current_mode in ('dp_ft', 'dp_pt'):
-        #    return None, "DIP/%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
+        #    return None, "DIP/%s/%s/%s/%05d" % (
+        #    faccode, depcode, year, next_integer)
         #if student.current_mode == 'found':
-        #    return _('Foundation programme students don\'t have matric number.'), None
+        #    return _(
+        #    'Foundation programme students don\'t have matric number.'), None
         #return None, "%s/%s/%s/%05d" % (faccode, depcode, year, next_integer)
+
         return _('Matriculation number cannot be set.'), None
 
Index: main/waeup.aaue/trunk/src/waeup/aaue/students/viewlets.py
===================================================================
--- main/waeup.aaue/trunk/src/waeup/aaue/students/viewlets.py	(revision 12974)
+++ main/waeup.aaue/trunk/src/waeup/aaue/students/viewlets.py	(revision 12975)
@@ -53,5 +53,6 @@
         if self.context.matric_number:
             return ''
-        error, matric_number = students_utils.constructMatricNumber(self.context)
+        error, matric_number = students_utils.constructMatricNumber(
+            self.context)
         if error:
             return ''
