Index: WAeUP_SRP/trunk/profiles/default/vocabularies/payment_categories.xml
===================================================================
--- WAeUP_SRP/trunk/profiles/default/vocabularies/payment_categories.xml	(revision 5163)
+++ WAeUP_SRP/trunk/profiles/default/vocabularies/payment_categories.xml	(revision 5164)
@@ -10,4 +10,5 @@
     <item key="hostel_maintenance" msgid="">Hostel Maintenance</item>
     <item key="schoolfee" msgid="">School Fee</item>
+    <item key="schoolfee2" msgid="">School Fee (2nd Instalment)</item>
     <item key="transfer" msgid="">Transfer</item>
     <item key="gown" msgid="">Gown Hire</item>
Index: WAeUP_SRP/trunk/skins/waeup_aaua/getPaymentsFolderInfo.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_aaua/getPaymentsFolderInfo.py	(revision 5163)
+++ WAeUP_SRP/trunk/skins/waeup_aaua/getPaymentsFolderInfo.py	(revision 5164)
@@ -56,10 +56,15 @@
 # begin customization
 
-if review_state == 'cleared_and_validated':
-    info['payment_method'] = "online_payment"
-#elif review_state == 'cleared_and_validated' and session == '07':
-#    info['payment_method'] = "sc_payment"
-elif review_state == 'returning' and info['next_session'] != session:
-    info['payment_method'] = "online_payment"
+if review_state in ('cleared_and_validated','returning',):
+    if session in ('07','06',):
+        info['payment_method'] = "online_payment"
+    else:
+        info['payment_method'] = "first_instalment"
+else:
+    second_instalment_records = aq_payments(Eq('student_id',student_id) & Eq('category','schoolfee2') & Eq('session_id',session) & Eq('status','paid'))
+    if not second_instalment_records:
+        info['payment_method'] = "second_instalment"
+    else:    
+        pass
 info['prod_id'] = '105'
 
@@ -99,7 +104,8 @@
     row['trans_ref'] = payment.order_id
     if row['is_requeryable']:
-        row['callback_url'] = "%(url)s/interswitch_cb" % row
-#        if payment.category == 'schoolfee':
-#            row['callback_url'] = "%(url)s/interswitch_cb" % row
+        if payment.category == 'schoolfee':
+            row['callback_url'] = "%(url)s/interswitch_cb" % row
+        elif payment.category == 'schoolfee2':
+            row['callback_url'] = "%(url)s/interswitch_cb2" % row            
 #        elif payment.category == 'hostel_maintenance':
 #            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
Index: WAeUP_SRP/trunk/skins/waeup_aaua/getSchoolFee.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_aaua/getSchoolFee.py	(revision 5163)
+++ WAeUP_SRP/trunk/skins/waeup_aaua/getSchoolFee.py	(revision 5164)
@@ -5,5 +5,5 @@
 ##bind script=script
 ##bind subpath=traverse_subpath
-##parameters=brain=None
+##parameters=brain=None,instalment='0'
 ##title=
 ##
@@ -12,38 +12,52 @@
 return SchoolFee
 """
-
-
+ 
 d = {}
 
-if brain.mode == 'ug_sw':  
+if brain.mode == 'ug_sw':    # ug_sw students payment does not depend on the current session
     if str(brain.level) in ('100','200',) and brain.review_state == 'cleared_and_validated': 
-        d['all'] = 40000
+        d['all'] = 45000
     elif str(brain.level) in ('100',):   #200 returning students
-        d['all'] = 40000
-    else:
-        d['all'] = 30000
-elif brain.mode == 'pg_sw':  
-    d['all'] = 35000
-elif brain.mode == 'dp_pt':  
-    if str(brain.level) in ('100',) and brain.review_state == 'cleared_and_validated':    # only 100 fresh 
-        d['all'] = 40000
+        d['all'] = 45000
     else:
         d['all'] = 35000
-elif brain.mode == 'ug_pt':  
-    if str(brain.level) in ('100','200',) and brain.review_state == 'cleared_and_validated':    # only 100 or 200 fresh 
-        d['all'] = 50000
+elif brain.mode == 'pg_sw':
+     if str(brain.level) == '600' and brain.review_state == 'cleared_and_validated':    # only 600 fresh 
+         d['all'] = 65000
+     else:   
+        d['all'] = 80000
+elif brain.session in ('06','07',): 
+    if brain.mode == 'dp_pt':  
+        if str(brain.level) in ('100',) and brain.review_state == 'cleared_and_validated':    # only 100 fresh 
+            d['all'] = 40000
+        else:
+            d['all'] = 35000
+    elif brain.mode == 'ug_pt':  
+        if str(brain.level) in ('100','200',) and brain.review_state == 'cleared_and_validated':    # only 100 or 200 fresh 
+            d['all'] = 50000
+        else:
+            d['all'] = 45000
+    elif brain.mode == 'pg_pt':  
+        if str(brain.level) == '600' and brain.review_state == 'cleared_and_validated':    # only 600 fresh 
+            d['all'] = 60000
+        elif str(brain.level) == '600' and brain.verdict == 'C':                           # 600 repeaters
+            d['all'] = 55000
+        elif str(brain.level) == '700' and brain.review_state == 'cleared_and_validated':  # only 700 fresh
+            d['all'] = 75000      
+        elif str(brain.level) == '600':                                                    # going to register for 700
+            d['all'] = 75000        
+        else:
+            d['all'] = 65000
     else:
-        d['all'] = 45000
-elif brain.mode == 'pg_pt':  
-    if str(brain.level) == '600' and brain.review_state == 'cleared_and_validated':    # only 600 fresh 
-        d['all'] = 60000
-    elif str(brain.level) == '600' and brain.verdict == 'C':                           # 600 repeaters
-        d['all'] = 55000
-    elif str(brain.level) == '700' and brain.review_state == 'cleared_and_validated':  # only 700 fresh                                             # going to register for 700
-        d['all'] = 75000      
-    elif str(brain.level) == '600':                                                    # going to register for 700
-        d['all'] = 75000        
+        d['all'] = 0
+elif brain.session in ('08',): 
+    if instalment == '1':
+        d['all'] = 8888888      # for testing
+        d['instalment'] = '1'
+    elif instalment == '2':
+        d['all'] = 9999999      # for testing
+        d['instalment'] = '2'
     else:
-        d['all'] = 65000
+        d['all'] = 0
 else:
     d['all'] = 0
Index: WAeUP_SRP/trunk/skins/waeup_aaua/interswitch_cb2.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_aaua/interswitch_cb2.py	(revision 5164)
+++ WAeUP_SRP/trunk/skins/waeup_aaua/interswitch_cb2.py	(revision 5164)
@@ -0,0 +1,120 @@
+## Script (Python) "interswitch_cb2"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+payment callback
+"""
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+import logging
+logger = logging.getLogger('Skins.interswitch_cb')
+from AccessControl import Unauthorized
+import DateTime
+
+if context.portal_membership.isAnonymousUser():
+    return None
+
+request = context.REQUEST
+students = context.portal_url.getPortalObject().campus.students
+wftool = context.portal_workflow
+mtool = context.portal_membership
+member = mtool.getAuthenticatedMember()
+member_id = str(member)
+#student_id = context.getStudentId()
+access_info = context.waeup_tool.getAccessInfo(context)
+student_id = access_info['student_id']
+if not context.isSectionOfficer() and (student_id is None or student_id != member_id):
+    logger.info('%s tried to access payment object of %s' % (member_id,student_id))
+    referer = request.get('HTTP_REFERER','none')
+    logger.info('%s:%s illegal access, referer = %s' % (member_id,student_id,referer))
+    real_ip = request.get('HTTP_X_REAL_IP',"none")
+    logger.info('%s:%s illegal access, real_x_ip = %s' % (member_id,student_id,real_ip))
+    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
+
+referer = request.get('HTTP_REFERER','none')
+real_ip = request.get('HTTP_X_REAL_IP',"none")  
+logger.info('%s, callback referer = %s, IP = %s' % (student_id,referer,real_ip))
+
+if not 'webpay.interswitchng.com' in referer and not 'waeup.org' in referer:
+    logger.info('%s, wrong callback referer %s, callback rejected, IP = %s' % (student_id,referer,real_ip))
+    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
+
+student = getattr(students,student_id)
+resp_codes = (("desc","resp_desc"),
+              ("resp","resp_code"),
+              ("txnRef","pay_reference"),
+              ("payRef","resp_pay_reference"),
+              ("retRef","retRef"),
+              ("cardNum","resp_card_num"),
+              ("apprAmt","resp_approved_amount"),
+              )
+pd = {}
+for rc,pdk in resp_codes:
+    pd[pdk] = request.get(rc,'')
+
+## for testing purposes
+#pd['resp_desc'] = 'Simulated Callback'
+#pd['resp_pay_reference'] = 'XXXX'
+#pd['resp_code'] = '00'
+#pd['resp_card_num'] = '0000'
+#pd['resp_approved_amount'] = '99999999999999'
+
+if pd['resp_code'] == '00' and len(pd['resp_approved_amount']) > 4:
+    pd['resp_approved_amount'] = pd['resp_approved_amount'][:-2]
+    pd['status'] = 'paid'
+else:
+    pd['resp_approved_amount'] = '0'
+    pd['status'] = 'failed'
+
+review_state = wftool.getInfoFor(context,'review_state',None)
+if pd['resp_code'] == '':
+    logger.info('%s requeried payment %s for %s and got empty response' % (member,context.getId(),student_id))
+    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
+if access_info['is_student'] and review_state == 'closed':
+    wftool.doActionFor(context,'open')
+pay_doc = context.getContent()
+resp = pd['resp_code']  
+
+if  resp == '00':
+    try:
+        amount = int(getattr(pay_doc,'amount',0))
+        surcharge = int(getattr(pay_doc,'surcharge',0))
+        resp_approved_amount = int(pd['resp_approved_amount'])
+        #set_trace()
+        if amount + surcharge != resp_approved_amount:
+            logger.info('Warning: %s, approved amount %s and authorized amount %s are different for payment %s of %s' % (member,resp_approved_amount,amount+surcharge,context.getId(),student_id))
+            pd['status'] = 'failed'
+            pd['resp_desc'] = 'Warning: approved amount in callback does not match!'
+            resp = ''
+        else:
+            pass
+    except:
+        logger.info('%s: approved amount could not be verified for payment %s of %s' % (member,context.getId(),student_id))
+        pd['status'] = 'failed'
+        pd['resp_desc'] = 'Warning: approved amount could not be verified!'
+        resp = ''    
+
+pay_doc.edit(mapping = pd)
+
+if  resp == '00':
+    logger.info('%s received valid callback' % student_id)
+    logger.info('%s paid second instalment' % student_id)
+else:
+    logger.info('%s received unsuccessful callback: %s' % (student_id,pd['resp_desc']))
+
+review_state = wftool.getInfoFor(context,'review_state',None)
+if review_state == 'opened':
+    wftool.doActionFor(context,'close')
+
+return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
+
Index: WAeUP_SRP/trunk/skins/waeup_aaua/interswitch_form2.pt
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_aaua/interswitch_form2.pt	(revision 5164)
+++ WAeUP_SRP/trunk/skins/waeup_aaua/interswitch_form2.pt	(revision 5164)
@@ -0,0 +1,46 @@
+<metal:body use-macro="here/main_template/macros/master">
+  <metal:main fill-slot="main"
+              tal:define="info options/info">
+    <h3>Confirm Your Payment Data! </h3>
+    <br />
+    <span tal:condition="not: info/payment_possible">
+      No payment information for your course available.
+    </span>
+    <span tal:condition="info/payment_possible">
+      <form method="post" action="pay_interswitch2">
+        <table>
+          <tr>
+            <td width="100px">
+            Payment:</td>
+            <td tal:content="info/type_description"></td>
+          </tr>
+          <tr>
+            <td>
+            Name:
+            </td>
+            <td tal:content="info/pay_bill_to" />
+          </tr>
+          <tr>
+            <td >
+            Amount:
+            </td>
+            <td> Naira <span tal:content="info/amount" /></td>
+          </tr>
+          <tr>
+            <td >
+            Surcharge:
+            </td>
+            <td> Naira <span tal:content="info/surcharge" /></td>
+          </tr>                  
+        </table>
+        <br />
+        <input type="submit" 
+               class="standalone" 
+               name="goto_bank" 
+               value="Confirm" 
+               />
+      </form>
+    </span>
+    </metal:main>
+</metal:body>
+
Index: WAeUP_SRP/trunk/skins/waeup_aaua/pay_interswitch.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_aaua/pay_interswitch.py	(revision 5163)
+++ WAeUP_SRP/trunk/skins/waeup_aaua/pay_interswitch.py	(revision 5164)
@@ -139,6 +139,8 @@
 if student_record.mode.endswith('_pt'):
     xmldict['aaua_acct'] = "0321100000000046"
+    xmldict['bank_id'] = "89"
 elif student_record.mode.endswith('_sw'):
     xmldict['aaua_acct'] = "2461770000021"
+    xmldict['bank_id'] = "76"
 else:
     xmldict['aaua_acct'] = "0000000000000000"
@@ -147,5 +149,5 @@
 xmltext = """<payment_item_detail>
 <item_details detail_ref="%(detail_ref)s" college="AAUA" department="%(department)s" faculty="%(faculty)s">
-<item_detail item_id="1" item_name="AAUA" item_amt="%(aaua_amount)s" bank_id="89" acct_num="%(aaua_acct)s" />
+<item_detail item_id="1" item_name="AAUA" item_amt="%(aaua_amount)s" bank_id="%(bank_id)s" acct_num="%(aaua_acct)s" />
 <item_detail item_id="2" item_name="BT" item_amt="%(bt_amount)s" bank_id="117" acct_num="6012015294" />
 </item_details>
Index: WAeUP_SRP/trunk/skins/waeup_aaua/pay_interswitch2.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_aaua/pay_interswitch2.py	(revision 5164)
+++ WAeUP_SRP/trunk/skins/waeup_aaua/pay_interswitch2.py	(revision 5164)
@@ -0,0 +1,169 @@
+## Script (Python) "pay_interswitch2"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+pay online
+"""
+from urllib import urlencode
+import logging
+logger = logging.getLogger('Skins.pay_interswitch2')
+import DateTime
+
+if context.portal_membership.isAnonymousUser():
+    return None
+
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+request = context.REQUEST
+wftool = context.portal_workflow
+students = context.portal_url.getPortalObject().campus.students
+
+
+student_id = context.getStudentId()
+student = getattr(students,student_id)
+
+student_record = context.students_catalog.getRecordByKey(student_id)
+#amount,description = context.getSchoolFee(student_record.faculty,student_record.session,student_record.course)
+info = {}
+info['student'] = student_record
+info['payment_possible'] = False
+info['amount'] = '0'
+info['bank'] = ''
+info['type_description'] = ''
+info['pay_bill_to'] = ''
+fee_dict = context.getSchoolFee(student_record,'2')
+fulltime = student_record.mode.endswith('_ft')
+
+if not fee_dict:
+    return context.interswitch_form(info=info)
+
+info['site_id'] = '105'
+info['currency_id'] = '566'
+pay_item_id = "10500"
+
+#info['type_code'] = sbrain.course  #type_code is redundant and will be removed soon
+info['bank'] = ''
+info['payment_possible'] = True
+info['type_description'] = fee_dict['description']
+info['pay_bill_to'] = student_record.name
+info['student_id'] = student_id
+info['student_name'] = student_record.name
+info['type'] = 'online'
+info['status'] = 'started'
+info['session_id'] = fee_dict['next_session_id']
+info['item'] = student_record.course
+info['category'] = 'schoolfee2'
+info['student_email'] = student_record.email
+now = DateTime.DateTime()
+info['date'] = now
+info['pay_ship_to'] = "Adekunle Ajasin University"
+timestamp = "%d" % int(now.timeTime()*1000)
+info['order_id'] = "%s%s" % (student_id[1:],timestamp)
+p_id = "p%s" % timestamp
+
+
+info['surcharge'] = interswitch_amount = '150'
+info['amount'] = amount = fee_dict['all']
+total_amount = 100*int(amount) + 100*int(interswitch_amount)
+
+
+if student_id is None:
+    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
+
+if True:
+    info['action'] = "https://webpay.interswitchng.com/paydirect/webpay/pay.aspx"
+else:
+    #pass
+    #return None
+    info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
+
+
+if "payments" not in student.objectIds():
+    student.invokeFactory('PaymentsFolder','payments')
+    payments = getattr(student,'payments')
+    d = {}
+    d['Title'] = 'Payments'
+    payments.getContent().edit(mapping=d)
+    wftool.doActionFor(payments,'open')
+else:
+    payments = getattr(student,'payments')
+if request.has_key('epayment'):
+    return context.interswitch_form2(info=info)
+
+
+payments.invokeFactory('Payment', p_id)
+payment = getattr(payments,p_id)
+wftool.doActionFor(payment,'open')
+d = {}
+d.update(info)
+payment.getContent().edit(mapping=d)
+
+
+info['callback_url'] = "%s/payments/%s/interswitch_cb2?echo=%s" % (student.absolute_url(),
+                                                                  p_id,
+                                                                  p_id)
+
+logger.info('%(student_id)s initiated second online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
+payment_fields = (('product_id','site_id'),
+                  ('site_redirect_url','callback_url'),
+                  ('Currency','currency_id'),
+                  ('cust_id','student_id'),
+                  ('cust_id_desc','type_description'),
+                  ('cust_name','student_name'),
+                  ('txn_ref','order_id'),
+                  ('Amount','amount'),
+                  )
+args = {}
+for arg,field in payment_fields:
+    args[arg] = info[field]
+
+bt_amount = 0
+
+aaua_amount = amount - bt_amount
+xmldict = {}
+xmldict['detail_ref'] = args['txn_ref']
+xmldict['department'] = student_record.department
+xmldict['faculty'] = student_record.faculty
+xmldict['aaua_amount'] = "%d" % int(100*aaua_amount)
+xmldict['bt_amount'] = "%d" % int(100*bt_amount)
+if student_record.mode.endswith('_pt'):
+    xmldict['aaua_acct'] = "0321100000000046"
+    xmldict['bank_id'] = "89"
+elif student_record.mode.endswith('_sw'):
+    xmldict['aaua_acct'] = "2461770000021"
+    xmldict['bank_id'] = "76"
+else:
+    xmldict['aaua_acct'] = "0000000000000000"
+
+
+xmltext = """<payment_item_detail>
+<item_details detail_ref="%(detail_ref)s" college="AAUA" department="%(department)s" faculty="%(faculty)s">
+<item_detail item_id="1" item_name="AAUA" item_amt="%(aaua_amount)s" bank_id="%(bank_id)s" acct_num="%(aaua_acct)s" />
+<item_detail item_id="2" item_name="BT" item_amt="%(bt_amount)s" bank_id="117" acct_num="6012015294" />
+</item_details>
+</payment_item_detail>""" % xmldict
+
+info['xml_data'] = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
+
+args['Amount'] = "%d" % (total_amount)
+args['site_name'] = "aaua.waeup.org"
+args['cust_name_desc'] = "Student Name"
+args['pay_item_id'] = pay_item_id
+args['pay_item_name'] = "AAUA Tuition Payments"
+args['payment_params'] = 'college_split'
+#args['xml_data'] = ''
+#args['xml_data'] = xmltext   # info['xml_data']can be used instead
+info['args'] = args
+
+return context.goto_interswitch_form(info=info)
+
Index: WAeUP_SRP/trunk/skins/waeup_epayment/payments_view.pt
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_epayment/payments_view.pt	(revision 5163)
+++ WAeUP_SRP/trunk/skins/waeup_epayment/payments_view.pt	(revision 5164)
@@ -75,4 +75,20 @@
                    />
           </form>  
+          <form tal:condition="python: info.get('payment_method') in ('first_instalment',)" 
+                tal:attributes="action string: ${context/absolute_url}/pay_interswitch" method="post" class="group">
+            <input type="submit" name="epayment" 
+                   class="context" 
+                   value="Pay"
+                   tal:attributes="value string:Initiate ${info/next_session_str} School Fee Payment by Cash Card (First Instalment)"
+                   />
+          </form>  
+          <form tal:condition="python: info.get('payment_method') in ('second_instalment',)" 
+                tal:attributes="action string: ${context/absolute_url}/pay_interswitch2" method="post" class="group">
+            <input type="submit" name="epayment" 
+                   class="context" 
+                   value="Pay"
+                   tal:attributes="value string:Initiate School Fee Payment by Cash Card (Second Instalment)"
+                   />
+          </form>                       
           <form tal:condition="python: info.get('payment_method') in ('sc_payment','both_payments')" 
                 tal:attributes="action string: ${context/absolute_url}/pay_by_sc" method="post" class="group">
