Index: /WAeUP_SRP/trunk/skins/waeup_utilities/readOnlinePaymentsFromLog.py
===================================================================
--- /WAeUP_SRP/trunk/skins/waeup_utilities/readOnlinePaymentsFromLog.py	(revision 1666)
+++ /WAeUP_SRP/trunk/skins/waeup_utilities/readOnlinePaymentsFromLog.py	(revision 1667)
@@ -10,6 +10,15 @@
 # $Id$
 """
-list Students for ClearanceOfficers
+read the successfull epayments from an extract of Z2.log
+this extract must be created with
+
+cat /zope/instances/uniben1/log/Z2.log.1 | grep epayment_cb | grep RespCode=00 
+> /zope/instances/uniben1/import/successfullepaymentsDDMMYY.log
+
+in /zope/instances/uniben1/import/ are already all files from 25.3.07
+
 """
+import logging
+logger = logging.getLogger('Skins.readOnlinePaymentsFromLog')
 
 request = context.REQUEST
@@ -17,4 +26,5 @@
 response = request.RESPONSE
 setheader = request.RESPONSE.setHeader
+import DateTime
 
 def rwrite(s):
@@ -32,10 +42,19 @@
 aq_students = context.students_catalog.evalAdvancedQuery
 students_folder = context.portal_url.getPortalObject().campus.students
-tas = context.waeup_tool.getCallbacksFromLog('epaymentsuccessful_z2log2')
+resp_codes = (("x_RespDesc","resp_desc"),
+      ("x_RespPayRef","resp_pay_reference"),
+      ("x_RespCode","resp_code"),
+      ("x_CardNum","resp_card_num"),
+      ("x_ApprAmt","resp_approved_amount"),
+      )
+count = 0
+correct = 0
+approved = 0
+tas = context.waeup_tool.getCallbacksFromLog('successfullepayments260307.log')
 for ta in tas:
+    count += 1
     student_id = ta['student_id']
     payment_id = ta['payment_id']
     qs_dict = ta['qs_dict']
-    rwrite(qs_dict)
     if not students_folder.hasObject(student_id):
         rwrite("no student %s" % student_id)
@@ -50,24 +69,49 @@
         continue
     payment_obj = getattr(payments,payment_id)
-    review_state = wftool.getInfoFor(student_obj,'review_state',None)
-    #from pdb import set_trace
-    if review_state == 'schoolfee_paid':
-        rwrite("student %s has already state %s" % (student_id,review_state))
-        continue
-    review_state = wftool.getInfoFor(payment_obj,'review_state',None)
-    #from pdb import set_trace
-    if review_state != 'open':
-        rwrite("payment %s for student %s has state %s" % (payment_id,student_id,review_state))
-        continue
-    resp_codes = (("x_RespDesc","resp_desc"),
-      ("x_RespPayRef","resp_pay_reference"),
-      ("x_RespCode","resp_code"),
-      ("x_CardNum","resp_card_num"),
-      ("x_ApprAmt","resp_approved_amount"),
-      )
-    pd = {}
+    payment_doc = payment_obj.getContent()
+    pdoc = {}
+    for rc,key in resp_codes:
+        pdoc[key] = getattr(payment_doc,key)
+    readin = {}
     for rc,pdk in resp_codes:
-        pd[pdk] = request.get(rc)
-    rwrite(pd)
-    #payment_obj.getContent().edit(mapping=pd)
-    continue
+        readin[pdk] = qs_dict.get(rc)[0]
+    response_code = readin['resp_code']
+    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
