Index: WAeUP_SRP/base/skins/waeup_accommodation/reserve_accommodation.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_accommodation/reserve_accommodation.py	(revision 2856)
+++ WAeUP_SRP/base/skins/waeup_accommodation/reserve_accommodation.py	(revision 2857)
@@ -1,2 +1,8 @@
+## Script (Python) "reserve_accommodation.py"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
 ##parameters=REQUEST
 # $Id$
@@ -4,4 +10,9 @@
 process the the accommodation reservation
 """
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
 import DateTime
 current = DateTime.DateTime()
@@ -26,12 +37,16 @@
     return context.REQUEST.RESPONSE.redirect("%s/no_booking_allowed" % info['student'].absolute_url())
 student = info['student']
+student_id = info['student_id']
 acco_id = info['acco_id']
-session = info['session'][1]
+#session = info['session'][1]
+session = info['session']
 #session = acco_id[-4:]
 validate = REQUEST.has_key("cpsdocument_create_button")
 if info.has_key('acco') and info['acco']:
     validate = REQUEST.has_key("cpsdocument_edit_button")
-    if info['acco_review_state'] == "maintenance_fee_paid":
+    if info['maintenance_paid']:
         return context.REQUEST.RESPONSE.redirect("%s/accommodation_view" % info['acco'].absolute_url())
+    elif info['online_payment']:
+        return context.REQUEST.RESPONSE.redirect("%s/pay_interswitch_acco?paytype=HOM" % info['student'].absolute_url())
     else:
         mode = 'edit'
@@ -61,5 +76,5 @@
     else:
         psm = "Error in data, unable to reserve bed."
-    return context.accommodation_pin_edit_form(rendered = res,
+    return context.accommodation_edit_form(rendered = res,
                                  psm = psm,
                                  #psm = "%s, %s" % (psm,ds),
@@ -68,5 +83,5 @@
                                  )
 elif psm == '':
-    return context.accommodation_pin_edit_form(rendered = res,
+    return context.accommodation_edit_form(rendered = res,
                                  psm = None,
                                  mode = mode,
@@ -74,35 +89,39 @@
                                  )
 elif psm == 'valid':
-    s_id = ds.get('s_id')
     if mode == 'create':
+        set_trace()
         pin = str(ds.get('acco_res_sc_pin'))
-        pa = context.portal_accommodation
-        already = pa(student=s_id)
-        if not already:
-            code,bed = pa.searchAndReserveBed(s_id,"%s" % (info['student_status']))
-            #code,bed = pa.searchAndReserveBed(s_id,"%s_%s" % (info['sex'],ds.get('student_status')))
+        code,bed = context.portal_accommodation.searchAndReserveBed(student_id,
+                                                                    "%s" % (info['student_status']))
+        while True:
+            if code == 1:
+                break
             if code == -1:
-                return context.accommodation_pin_edit_form(rendered = res,
-                                     psm = "%s" % bed,
-                                     mode = mode,
-                                     ds = ds,
-                                     )
+                return context.accommodation_edit_form(rendered = res,
+                                        psm = "%s" % bed,
+                                        mode = mode,
+                                        ds = ds,
+                                        )
             elif code == -2:
-                return context.accommodation_pin_edit_form(rendered = res,
-                                     psm = "No bed available. Your category is already fully booked.",
-                                     mode = mode,
-                                     ds = ds,
-                                     )
-        else:
-            bed = already[0].bed
+                return context.accommodation_edit_form(rendered = res,
+                                        psm = "No bed available. Your category is already fully booked.",
+                                        mode = mode,
+                                        ds = ds,
+                                        )
+            else: # unknown error
+                return context.accommodation_edit_form(rendered = res,
+                                        psm = "Unexpected Error!",
+                                        mode = mode,
+                                        ds = ds,
+                                        )
         student.invokeFactory('StudentAccommodation',acco_id)
-        acco = getattr(student,acco_id)
-        acco_info = context.waeup_tool.getHallInfo(bed)
-        ds.set('acco_maint_code', acco_info.get('maintenance_code'))
-        ds.set('acco_maint_fee', acco_info.get('maintenance_fee'))
+        hall_info = context.waeup_tool.getHallInfo(bed)
+        ds.set('acco_maint_code', hall_info.get('maintenance_code'))
+        ds.set('acco_maint_fee', hall_info.get('maintenance_fee'))
         ds.set('acco_res_date', current)
         ds.set('bed', bed)
         ds.set('session', session)
         ds.set('student_status',info['student_status'])
+        acco = getattr(student,acco_id)
         acco.getContent().edit(mapping=ds)
         #wftool.doActionFor(acco,'pay_maintenance_fee',dest_container=acco)
Index: WAeUP_SRP/base/skins/waeup_epayment/interswitch_acco_cb.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_epayment/interswitch_acco_cb.py	(revision 2857)
+++ WAeUP_SRP/base/skins/waeup_epayment/interswitch_acco_cb.py	(revision 2857)
@@ -0,0 +1,136 @@
+## Script (Python) "interswitch_acco_cb"
+##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_acco_cb')
+from AccessControl import Unauthorized
+import DateTime
+current = DateTime.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()
+if 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())
+
+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,'')
+
+if pd['resp_code'] == '00' and len(pd['resp_approved_amount']) > 4:
+    pd['resp_approved_amount'] = pd['resp_approved_amount'][:-2]
+else:
+    pd['resp_approved_amount'] = '0'
+
+review_state = wftool.getInfoFor(context,'review_state',None)
+if pd['resp_code'] == '' and review_state == 'opened':
+    logger.info('%s requeried payment %s and got empty response' % (student_id,context.getId()))
+    wftool.doActionFor(context,'close')
+    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
+pay_doc = context.getContent()
+pay_doc.edit(mapping = pd)
+resp = pd['resp_code']
+
+s_brain = context.students_catalog(id=student_id)[0]
+session = s_brain.session
+#next_session, next_session_str = context.getNextSessionId(session)
+
+if pay_doc.subject == 'hostel_maintenance':
+    if  resp == '00':
+        d = {}
+        acco_info = context.getAccommodationInfo()
+        d['acco_maint_date'] = pay_doc.date
+        d['acco_maint_fee'] = pay_doc.amount
+        d['acco_maint_pay_id'] = context.getId()
+        acco_info['acco_doc'].edit(mapping=d)
+        referer = request.get('HTTP_REFERER','none')
+        logger.info('%s valid callback referer = %s' % (student_id,referer))
+        real_ip = request.get('HTTP_X_REAL_IP',"none")
+        logger.info('%s valid callback real_ip = %s' % (student_id,real_ip))
+    else:
+        logger.info('%s received unsuccessfull callback: %s' % (student_id,pd['resp_desc']))
+    try:
+        wftool.doActionFor(acco_info['acco'],'pay_maintenance_fee',dest_container=acco_info['acco'])
+        return request.RESPONSE.redirect("%s/accommodation_view" % acco_info['student'].absolute_url())
+    except:
+        logger.info('%s no workflow action pay_maintainance_fee' % student_id)
+        return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
+    
+else:        
+    next_info = context.getNextInfo(s_brain)
+    next_session_id = next_info['next_session_id']
+    next_session_str = next_info['next_session_str']
+    next_level_id = next_info['next_level_id']
+    next_transition = next_info['next_transition']
+    next_verdict = next_info['next_verdict']
+    next_previous_verdict = next_info['next_previous_verdict']
+    
+    if  resp == '00':
+        if context.getStudentReviewState() == "school_fee_paid":
+            logger.info('%s paid school_fee in state school_fee_paid' % (student_id))
+        else:
+            study_course = getattr(student,'study_course')
+            try:
+                wftool.doActionFor(study_course,'open')
+            except:
+                pass
+            verdict = s_brain.verdict
+            if next_previous_verdict == 'N/A':
+                next_previous_verdict = ''
+            study_course.getContent().edit(mapping= {'current_level': next_level_id,
+                                                    'current_session': next_session_id,
+                                                    'current_verdict': next_verdict,
+                                                    'previous_verdict': next_previous_verdict,
+                                                    })
+            if next_transition:
+                wftool.doActionFor(student,next_transition)
+    
+        logger.info('%s received valid callback' % student_id)
+        referer = request.get('HTTP_REFERER','none')
+        logger.info('%s valid callback referer = %s' % (student_id,referer))
+        real_ip = request.get('HTTP_X_REAL_IP',"none")
+        logger.info('%s valid callback real_ip = %s' % (student_id,real_ip))
+    else:
+        logger.info('%s received unsuccessfull callback: %s' % (student_id,pd['resp_desc']))
+    try:
+        wftool.doActionFor(context,'close')
+    except:
+        logger.info('%s no workflow action close' % student_id)
+    
+
Index: WAeUP_SRP/base/skins/waeup_epayment/pay_interswitch_acco.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_epayment/pay_interswitch_acco.py	(revision 2857)
+++ WAeUP_SRP/base/skins/waeup_epayment/pay_interswitch_acco.py	(revision 2857)
@@ -0,0 +1,131 @@
+## Script (Python) "pay_interswitch_acco"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=paytype=None
+##title=
+##
+# $Id$
+"""
+pay online
+"""
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+from urllib import urlencode
+import logging
+logger = logging.getLogger('Skins.pay_interswitch')
+import DateTime
+
+if context.portal_membership.isAnonymousUser():
+    return None
+
+request = context.REQUEST
+wftool = context.portal_workflow
+students = context.portal_url.getPortalObject().campus.students
+
+student_id = context.getStudentId()
+if student_id is None:
+    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
+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)
+now = DateTime.DateTime()
+timestamp = "%d" % int(now.timeTime()*1000)
+payment_id = "p%s" % timestamp
+hostel = paytype == "HOM"
+if hostel:
+    info = context.getInterswitchParams(paytype,student,payment_id)
+    info['student'] = student_record
+else:
+    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)
+    fulltime = student_record.mode.endswith('_ft')
+    new = student_record.review_state == 'cleared_and_validated'
+    returning = student_record.review_state == 'returning'
+    if not fee_dict or (not new and fulltime) or not (new or returning):
+        return context.interswitch_form(info=info)
+    if new:
+        amount = info['amount'] = fee_dict['new']
+    elif returning:
+        amount = info['amount'] = fee_dict['returning']
+    if fulltime:
+        pay_item_id = "6100"
+        info['type_code'] = student_record.faculty   #type_code is redundant and will be removed soon
+        info['bank'] = ''
+    else:
+        pay_item_id = "6101"
+        info['type_code'] = student_record.course  #type_code is redundant and will be removed soon
+        info['bank'] = ''
+    info['payment_possible'] = True
+    info['type_description'] = fee_dict['description']
+    info['pay_ship_to'] = "University of Benin"
+info['pay_bill_to'] = student_record.name
+info['student_id'] = student_id
+info['student_name'] = student_record.name
+info['student_email'] = student_record.email
+info['date'] = now
+info['order_id'] = "%s%s" % (student_id[1:],timestamp)
+
+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_form(info=info)
+
+
+payments.invokeFactory('Payment', payment_id)
+payment = getattr(payments,payment_id)
+wftool.doActionFor(payment,'open')
+d = {}
+d.update(info)
+payment.getContent().edit(mapping=d)
+#wftool.doActionFor(payment,'close')
+#wftool.doActionFor(student,'pay_school_fee')
+info['callback_url'] = "%s/payments/%s/%s?echo=%s" % (student.absolute_url(),
+                                                      payment_id,
+                                                      info['callback_function'],
+                                                      payment_id)
+
+logger.info('%(student_id)s initiated %(description)s payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
+payment_fields = (('product_id','site_id'),
+                  ('site_name','site_name'),
+                  ('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'),
+                  ('pay_item_id','pay_item_id'),
+                  ('pay_item_name','pay_item_name'),
+                  ('payment_params','payment_params'),
+                  )
+args = {}
+for arg,field in payment_fields:
+    args[arg] = info[field]
+interswitch_amount = int(info['surcharge'])*100
+uni_amount = int(info['amount'])*100
+total_amount = interswitch_amount + uni_amount
+args['Amount'] = "%d" % (total_amount)
+args['cust_name_desc'] = "Student Name"
+args['xml_data'] = ''
+info['args'] = args
+return context.goto_interswitch_form(info=info)
Index: WAeUP_SRP/base/skins/waeup_epayment/simulate_callback.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_epayment/simulate_callback.py	(revision 2857)
+++ WAeUP_SRP/base/skins/waeup_epayment/simulate_callback.py	(revision 2857)
@@ -0,0 +1,28 @@
+##parameters=REQUEST
+# $Id$
+"""
+simulate a callback
+"""
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+
+import DateTime,logging
+current = DateTime.DateTime()
+pr = context.portal_registration
+logger = logging.getLogger('EPayment.Simulate')
+
+args = {}
+args['desc'] = 'Simulated Callback'
+args['PayRef'] = 'GTB|WEB|ISW|1-01-2000|000234'
+args['resp'] = '00'
+args['cardNum'] = '0000'
+args['ApprAmt'] = REQUEST.get('x_amt')
+from urllib import urlencode
+#set_trace()
+#url = "%s" % (context.absolute_url())
+raw_url = REQUEST.get("site_redirect_url") 
+url = "%s&%s" % (raw_url,urlencode(args))
+return REQUEST.RESPONSE.redirect(url)
Index: WAeUP_SRP/base/skins/waeup_layout/layout_student_acco_create.pt
===================================================================
--- WAeUP_SRP/base/skins/waeup_layout/layout_student_acco_create.pt	(revision 2856)
+++ WAeUP_SRP/base/skins/waeup_layout/layout_student_acco_create.pt	(revision 2857)
@@ -1,4 +1,3 @@
-<tal:block define="global creation python:1;
-                   global formaction string:apply_admission" />
+<tal:block define="global creation python:1" />
 <!-- a layout_lib macro -->
 <!-- $Id: layout_student_acco_create.pt 805 2006-11-09 09:38:29Z joachim $ -->
@@ -14,5 +13,4 @@
   ti python:type_name and getattr(here.portal_types,type_name,None) or getattr(here.portal_types,here.portal_type,None);
   cpsmcat nocall:here/translation_service;
-  apply request/apply_button|nothing;
   widgets python:context.getRenderedWidgets(layout);
   ">
@@ -119,17 +117,7 @@
   </table>
   <br />
-  <input type="submit" class="standalone" name="cpsdocument_edit_button"
-         value="Save" 
-         id="cpsdocument_edit_button"
-         tal:condition="not:creation" />
-  <input type="submit" class="standalone" name="apply_admission"
-         value="apply for admission"
-         id="cpsdocument_edit_and_view_button"
-         tal:condition="apply" 
-         tal:attributes="value apply"/>
   <input type="submit" 
          class="standalone" 
          name="cpsdocument_create_button"
-         value="apply"
          tal:attributes="value options/button"
          tal:condition="creation" />
Index: WAeUP_SRP/base/skins/waeup_student/accommodation_slip.pt
===================================================================
--- WAeUP_SRP/base/skins/waeup_student/accommodation_slip.pt	(revision 2856)
+++ WAeUP_SRP/base/skins/waeup_student/accommodation_slip.pt	(revision 2857)
@@ -19,5 +19,5 @@
             <tr>
               <td width="180px">Student ID:</td> 
-              <td><span tal:content="info_acco/id" /></td>
+              <td><span tal:content="info_acco/student_id" /></td>
             </tr>
             <tr tal:condition="info_acco/matric_no">
Index: WAeUP_SRP/base/skins/waeup_student/accommodation_view.pt
===================================================================
--- WAeUP_SRP/base/skins/waeup_student/accommodation_view.pt	(revision 2856)
+++ WAeUP_SRP/base/skins/waeup_student/accommodation_view.pt	(revision 2857)
@@ -29,8 +29,22 @@
          <tr>
           <td width="220px">Level:</td><td tal:content="info/level" />
-         </tr>
-         </table>
-      </span>
-    </metal:main>
+        </tr>
+        <tr tal:condition="not: info/maintenance_paid">
+          <form action="pay_interswitch_acco" method="post" 
+                enctype="multipart/form-data" class="workflow"
+                >
+        <td colspan="2">  
+            <input type="submit" 
+                   class="standalone" 
+                   name="cpsdocument_create_button"
+                   value="apply"
+                   tal:attributes="value options/button"
+                   tal:condition="creation" />
+            </td>
+          </form>
+        </tr>
+      </table>
+    </span>
+  </metal:main>
 </metal:body>
 
