Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/check_online_payments.py
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/check_online_payments.py	(revision 1653)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/check_online_payments.py	(revision 1653)
@@ -0,0 +1,69 @@
+## Script (Python) "check_online_payments"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+payment callback
+"""
+import logging
+logger = logging.getLogger('Skins.check_online_payments')
+from AccessControl import Unauthorized
+import DateTime
+if context.portal_membership.isAnonymousUser():
+    return None
+
+request = context.REQUEST
+response = request.RESPONSE
+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()
+online_transactions = context.online_payments_import
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+def rwrite(s):
+    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
+    response.write("%s<br>\n" % s)
+try:
+    from Products.AdvancedQuery import Eq, Between, Le,In
+    aq_portal = context.portal_catalog.evalAdvancedQuery
+    aq_students = context.students_catalog.evalAdvancedQuery
+except:
+    aq_portal = None
+
+query1 = Eq('portal_type','Payment')
+query2 = Eq('SearchableText',"Approved Successful")	 	
+online_payments = aq_portal(query1 & query2)
+set_trace()
+online_transactions = context.online_payments_import
+
+for op_brain in online_payments:
+    student_id = op_brain.getPath().split('/')[-3]
+    payment_doc = op_brain.getObject().getContent()
+    order_id = "%s%s" % (student_id[1:],op_brain.getId[1:])
+    transactions = online_transactions(student_id = student_id)
+    payment_id = op_brain.getId
+    if payment_doc.resp_code == "00" and not transactions:
+        rwrite('"%s","%s","no transaction for successfull payment","","%s"' % (student_id,payment_id,payment_doc.date))
+        continue
+    for transaction in transactions:
+        t_order_id = transaction.order_id
+        if t_order_id == order_id:
+            rwrite('"%s","%s","%s","%s","%s"' % (student_id,
+                                                                        op_brain.getId,
+                                                                        transaction.response_code,
+                                                                        payment_doc.resp_code,
+                                                                        payment_doc.date
+                                                                        ))
+            continue
Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/check_transactions.py
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/check_transactions.py	(revision 1653)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/check_transactions.py	(revision 1653)
@@ -0,0 +1,92 @@
+## Script (Python) "check_transactions"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+payment callback
+"""
+import logging
+logger = logging.getLogger('Skins.check_transactions')
+from AccessControl import Unauthorized
+import DateTime
+if context.portal_membership.isAnonymousUser():
+    return None
+
+request = context.REQUEST
+response = request.RESPONSE
+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()
+online_transactions = context.online_payments_import
+def rwrite(s):
+    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
+    response.write("%s<br>\n" % s)
+correct = 0
+count = 0
+approved = 0
+for ot_brain in online_transactions():
+    student_id = ot_brain.student_id
+    if not students.hasObject(student_id):
+        rwrite("%s not found" % student_id)
+        continue
+    student_obj = getattr(students,student_id)
+    if not student_obj.hasObject('payments'):
+        rwrite("%s payments-folder not found" % student_id)
+        continue
+    payments_folder = getattr(student_obj,'payments')
+    payment_id = "p%s" % ot_brain.order_id[6:]
+    if not payments_folder.hasObject(payment_id):
+        rwrite("%s payment %s not found" % (student_id,payment_id))
+        continue
+    payment_obj = getattr(payments_folder,payment_id)
+    payment_doc = payment_obj.getContent()
+    response_code = ot_brain.response_code
+    count +=1
+    if payment_doc.resp_code != response_code:
+        rwrite('"%d","%d","%s","%s","%s","%s"' % (
+                                                  count,correct,
+                                                  student_id,
+                                                  payment_id,
+                                                  response_code,
+                                                  payment_doc.resp_code
+                                                  ))
+    elif payment_doc.resp_code == response_code:
+        correct +=1
+        rwrite('"%d","%d","%s","%s","%s","%s"' % (
+                                                  count,correct,
+                                                  student_id,
+                                                  payment_id,
+                                                  response_code,
+                                                  payment_doc.resp_code
+                                                  ))
+    if payment_doc.resp_code == "" and response_code == "00":
+        pd = {}
+        review_state = wftool.getInfoFor(payment_obj,'review_state',None)
+        if review_state != "opened":
+            logger.info('payment object of %s closed' % (student_id))
+            continue
+        review_state = wftool.getInfoFor(student_obj,'review_state',None)
+        if review_state != "cleared_and_validated":
+            logger.info('%s review_state = %s' % (student_id,review_state))
+            continue
+        pd['resp_code'] = 'IP'
+        pd['resp_desc'] = 'Payment approved by import, %s' % (DateTime.DateTime())
+        payment_doc.edit(mapping=pd)
+        if payment_doc.type_description.startswith('School Fee'):
+            wftool.doActionFor(student_obj,'pay_school_fee')
+        logger.info('%s approves epayment for %s by import' % (member,student_id))
+        wftool.doActionFor(payment_obj,'close')
+        approved += 1
+        if approved > 50:
+            context.waeup_tool.doCommit()
+            logger.info('%s transactions commited' % (approved))
+            approved = 0
Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/epayment_cb.py
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/epayment_cb.py	(revision 1593)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/epayment_cb.py	(revision 1653)
@@ -14,4 +14,5 @@
 import logging
 logger = logging.getLogger('Skins.epayment_cb')
+from AccessControl import Unauthorized
 import DateTime
 if context.portal_membership.isAnonymousUser():
@@ -21,6 +22,14 @@
 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:
+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())
 
@@ -37,5 +46,9 @@
 for rc,pdk in resp_codes:
     pd[pdk] = request.get(rc)
-context.getContent().edit(mapping=pd)
+try:
+    context.getContent().edit(mapping=pd)
+except UnAuthorized,E:
+    logger.info('%s ' % student_id)
+
 #resp = pd['resp_desc']
 #if  resp.startswith('Appro') and resp.endswith('essful'):
@@ -44,4 +57,8 @@
     wftool.doActionFor(student,'pay_school_fee')
     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))
 
 elif len(resp) < 3:
Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/getPaymentsFolderInfo.py
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/getPaymentsFolderInfo.py	(revision 1593)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/getPaymentsFolderInfo.py	(revision 1653)
@@ -53,5 +53,9 @@
     else:
         row['is_approvable'] = is_so and (review_state == "opened")
-    if (review_state == "closed") and so_object.resp_code in ('SC','00','AP',):
+    if so_object.type_description.startswith('School Fee'):
+        row['is_requeryable'] = (review_state == "opened") and info['review_state'] == 'cleared_and_validated'
+    else:
+        row['is_requeryable'] = is_so and (review_state == "opened")
+    if (review_state == "closed") and so_object.resp_code in ('SC','00','AP','IP',):
         row['confirmed'] = 'active'
     else:
Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/pay_online.py
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/pay_online.py	(revision 1593)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/pay_online.py	(revision 1653)
@@ -91,5 +91,5 @@
 info['callback_url'] = "%s/payments/%s/epayment_cb" % (student.absolute_url(),p_id)
 
-logger.info('%(student_id)s initiated online school fee payment' % info)
+logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
 payment_fields = (('x_SiteID','site_id'),
                   ('x_Redirect_url','callback_url'),
Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/payment_receipt.pt
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/payment_receipt.pt	(revision 1593)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/payment_receipt.pt	(revision 1653)
@@ -8,5 +8,5 @@
       <span tal:condition="info">
       
-        <metal:block tal:condition="python:info_doc['doc'].resp_code in ('00','AP',)">            
+        <metal:block tal:condition="python:info_doc['doc'].resp_code in ('00','AP','IP')">            
         <h3>Online Payment Receipt</h3>
         <br />
@@ -106,5 +106,5 @@
         </metal:block>
         
-        <metal:block tal:condition="python:info_doc['doc'].resp_code not in ('SC','00','AP','')">            
+        <metal:block tal:condition="python:info_doc['doc'].resp_code not in ('SC','00','AP','IP','')">            
         <h3>Response from Bank: "<span tal:content="python:info_doc['doc'].resp_desc" />"</h3>
         <br />        
Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/payments_view.pt
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/payments_view.pt	(revision 1593)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/payments_view.pt	(revision 1653)
@@ -34,9 +34,17 @@
             </td>
             <td>
-            <a tal:condition="python:row['is_approvable']"
+            <a tal:condition="row/is_approvable"
                tal:attributes="href string:${context/absolute_url}/${row/id}/approve_epayment;
                                onclick python:'return window.confirm(\'%s\')' %(cpsmcat('Are you sure? You will not be able to undo the approval.'), );
                                ">
                 [approve payment]
+            </a>             
+            </td>
+            <td tal:condition="nothing">
+            <a tal:condition="row/is_requeryable"
+               tal:attributes="href string:${context/absolute_url}/${row/id}/requery_payment;
+                               onclick python:'return window.confirm(\'%s\')' %(cpsmcat('Are you sure? You will not be able to undo the approval.'), );
+                               ">
+                [requery payment]
             </a>             
             </td>
@@ -53,4 +61,8 @@
                 value="Initiate School Fee Online Payment" 
                 />
+                
+
+
+                
         </form>  
 
Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/requery_payment.py
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/requery_payment.py	(revision 1653)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/requery_payment.py	(revision 1653)
@@ -0,0 +1,66 @@
+## Script (Python) "pay_online"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+requery online-payment
+"""
+from urllib import urlencode
+import logging
+logger = logging.getLogger('Skins.requery_payment')
+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()
+student = getattr(students,student_id)
+
+sbrain = context.students_catalog(id=student_id)[0]
+info = {}
+info['site_id'] = '300100100'
+info['currency_id'] = '566'
+
+#from Products.zdb import set_trace;set_trace()
+if student_id is None:
+    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
+
+if context.portal_url().find('uniben-demo.waeup.org') >-1 or\
+   context.portal_url().find('uniben.waeup.org') >-1:
+    info['action'] = "http://www.wemaonlinepayments.biz/querytransaction.aspx"
+else:
+    #pass
+    #return None
+    info['action'] = "%s/payments/%s/simulate_queryatransaction" % (student.absolute_url(),p_id)
+
+
+payment = context
+if payment.portal_type != 'Payment':
+    return
+payment_doc = payment.getContent()
+#from Products.zdb import set_trace;set_trace()
+info['order_id'] = p_id = payment_doc.order_id
+info['callback_url'] = "%s/payments/%s/epayment_requery_cb" % (student.absolute_url(),p_id)
+info['type_description'] = payment_doc.type_description
+info['amount'] = payment_doc.amount
+info['student_id'] = student_id
+logger.info('%(student_id)s requeried online school fee payment for order_id %(order_id)s' % info)
+payment_fields = (('x_SiteID','site_id'),
+                  ('x_OrderID','order_id'),
+                  ('x_Redirect_url','callback_url'),
+                  )
+args = {}
+for arg,field in payment_fields:
+    args[arg] = info[field]
+info['args'] = args
+return context.requery_payment_form(info=info)
Index: WAeUP_SRP/branches/uli/skins/waeup_epayment/requery_payment_form.pt
===================================================================
--- WAeUP_SRP/branches/uli/skins/waeup_epayment/requery_payment_form.pt	(revision 1653)
+++ WAeUP_SRP/branches/uli/skins/waeup_epayment/requery_payment_form.pt	(revision 1653)
@@ -0,0 +1,42 @@
+<metal:body use-macro="here/main_template/macros/master">
+    <metal:main fill-slot="main"
+                tal:define="info options/info">
+                
+        <h3>Requery Online Payment! </h3>
+        <br />
+                
+      <form method="post" action="pay_online"
+            tal:attributes="action info/action ">
+      <span tal:repeat="arg python:info['args'].items()"
+            tal:omit-tag="">
+          <input type="hidden" tal:attributes="name python:arg[0];value python:arg[1]" />
+      </span>          
+        <table>
+          <tr>
+            <td width="100px">
+            Payment:</td>
+            <td tal:content="info/type_description"></td>
+          </tr>
+          <tr>
+            <td >
+            Amount:
+            </td>
+            <td> Naira <span tal:content="info/amount" /></td>
+          </tr>
+          <tr>
+            <td >
+            Bank:
+            </td>
+            <td>Wema Bank</td>
+          </tr>          
+        </table>
+        <br />
+        <input type="submit" 
+               class="standalone" 
+               name="goto_bank" 
+               value="Requery this payment with Bank" 
+               />
+      </form>
+    </metal:main>
+</metal:body>
+
