Index: WAeUP_SRP/base/Payment.py
===================================================================
--- WAeUP_SRP/base/Payment.py	(revision 2857)
+++ WAeUP_SRP/base/Payment.py	(revision 2859)
@@ -13,4 +13,5 @@
 import Globals
 import DateTime
+import logging
 import re
 p_home = Globals.package_home(globals())
@@ -29,4 +30,50 @@
         """compose title"""
         return "Payments"
+
+    security.declareProtected(View,"updatePayments")
+    def updatePayments(self):
+        """upgrade all payments in folder"""
+        logger = logging.getLogger('PaymentsFolder.updatePayments')
+        #import pdb;pdb.set_trace()
+        for payment in self.aq_parent.objectValues():
+            d = {}
+            student_record = self.students_catalog.getRecordByKey(self.getStudentId())
+            doc = payment.getContent()
+            d['key'] = payment.getId()
+            d['amount'] = doc.amount
+            d['description'] = d['type_description'] = doc.type_description
+            subject = ''
+            if doc.type_description.startswith('School'):
+                subject = 'schoolfee'
+            sp = doc.type_description.rfind('/')
+            d['session_id'] = doc.type_description[sp-2:sp]
+            d['subject'] = subject # zb. schoolfee
+            while True:
+                if doc.resp_code == "SC":
+                    p_type = "sc"
+                    p_status = "paid"
+                    break
+                if doc.resp_code in ("00","IP"):
+                    p_type = "online"
+                    p_status = "paid"
+                    break
+                p_type = "online"
+                p_status = "open"
+                break
+            d['key'] = payment.getId()
+            d['type'] = p_type  # scratch card
+            d['target'] = student_record.course
+            d['status'] = p_status
+            d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None)
+            d['resp_pay_reference'] = doc.resp_pay_reference
+            d['resp_desc'] = doc.resp_desc
+            d['order_id'] = doc.order_id
+            d['resp_code'] = doc.resp_code
+            d['resp_card_num'] = doc.resp_card_num
+            d['date'] = getattr(doc,'date',None)
+            d['resp_date'] = getattr(doc,'resp_date',None)
+            # msg = " ".join(["%s: %s" % (key,value) for key,value in d.items()])
+            # logger.info(msg)
+            doc.edit(mapping = d)
 
 InitializeClass(PaymentsFolder)
Index: WAeUP_SRP/base/WAeUPTables.py
===================================================================
--- WAeUP_SRP/base/WAeUPTables.py	(revision 2857)
+++ WAeUP_SRP/base/WAeUPTables.py	(revision 2859)
@@ -516,4 +516,5 @@
     name = "portal_pins"
     key = 'pin'
+
     def __init__(self,name=None):
         if name ==  None:
@@ -1435,4 +1436,5 @@
         WAeUPTable.__init__(self, name)
 
+
     security.declarePrivate('notify_event_listener') ###(
     def notify_event_listener(self,event_type,object,infos):
@@ -1458,9 +1460,15 @@
             return
         for field in self.schema():
-            data[field] = getattr(object,field)
+            data[field] = getattr(object,field,'')
         rpl = infos['rpath'].split('/')
         student_id = rpl[-3]
         data['student_id'] = student_id
-        self.modifyRecord(**data)
+        try:
+            self.modifyRecord(**data)
+        except KeyError:
+            self.addRecord(**data)
+        except:
+            logger = logging.getLogger('WAeUPTables.PaymentsCatalog.%s' % self.__name__)
+            logger.info("could not add or modify entry for %(key)s" % data)
     ###)
 
Index: WAeUP_SRP/base/skins/waeup_epayment/interswitch_cb.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_epayment/interswitch_cb.py	(revision 2857)
+++ WAeUP_SRP/base/skins/waeup_epayment/interswitch_cb.py	(revision 2859)
@@ -61,6 +61,8 @@
 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)
Index: WAeUP_SRP/base/skins/waeup_epayment/pay_by_sc.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_epayment/pay_by_sc.py	(revision 2857)
+++ WAeUP_SRP/base/skins/waeup_epayment/pay_by_sc.py	(revision 2859)
@@ -103,4 +103,8 @@
     info['type_code'] = "%s" % pin  #type_code is redundant and will be removed soon
     info['type_description'] = 'School Fee for Session %s' % next_session_str
+    info['type'] = 'SC' 
+    info['status'] = 'paid'
+    info['target'] = s_brain.course
+    info['subject'] = 'schoolfee'
     info['resp_code'] = "SC"
     info['resp_desc'] = "SC Payment Successful"
Index: WAeUP_SRP/base/skins/waeup_epayment/upgradePayments.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_epayment/upgradePayments.py	(revision 2859)
+++ WAeUP_SRP/base/skins/waeup_epayment/upgradePayments.py	(revision 2859)
@@ -0,0 +1,109 @@
+## Script (Python) "upgradePayments.py"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+"""
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+
+mtool = context.portal_membership
+member = mtool.getAuthenticatedMember()
+if str(member) not in ('admin','joachim'):
+    return
+
+
+import logging
+import DateTime
+logger = logging.getLogger('Skins.upgradePayments')
+from Products.AdvancedQuery import Eq, Between, Le,In
+aq_portal = context.portal_catalog_real.evalAdvancedQuery
+aq_student = context.students_catalog.evalAdvancedQuery
+students_folder = context.portal_url.getPortalObject().campus.students
+
+request = context.REQUEST
+session = request.SESSION
+response = request.RESPONSE
+setheader = request.RESPONSE.setHeader
+def rwrite(s):
+    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
+    response.write("%s<br>\n\r" % s)
+
+count = 1
+d = {}
+l = []
+sum_total = 0.0
+log_after = 100
+logger.info("start")
+query = Eq('portal_type','Payment')
+payments = aq_portal(query,sortSpecs=('container_path',))
+total = len(payments)
+logger.info("found %d payments" % total)
+sid = "xxx"
+#set_trace()
+count = 1
+commit_after = 5
+commit_count = 0
+
+set_trace()
+for payment in payments:
+    student_id = payment.getPath().split('/')[-3]
+    student_brain = context.students_catalog.getRecordByKey(student_id)
+    if student_brain is None:
+        logger.info("student %s not in students_catalog" % student_id)
+        continue
+    d = {}
+    doc = payment.getObject().getContent()
+    d['key'] = payment.getId
+    d['amount'] = doc.amount
+    d['description'] = d['type_description'] = doc.type_description
+    subject = ''
+    if doc.type_description.startswith('School'):
+        subject = 'schoolfee'
+    sp = doc.type_description.rfind('/')
+    d['session_id'] = doc.type_description[sp-2:sp]
+    d['subject'] = subject # zb. schoolfee
+    d['target'] = "%s" % (student_brain.course)  # faculty departmen course
+    while True:
+        if doc.resp_code == "SC":
+            p_type = "sc"
+            p_status = "paid"
+            break
+        if doc.resp_code == "00":
+            p_type = "onl"
+            p_status = "paid"
+            break
+        p_type = "ONL"
+        p_status = "open"
+        break
+    d['key'] = payment.getId
+    d['type'] = p_type  # scratch card
+    d['status'] = p_status
+    d['resp_approved_amount'] = getattr(doc,'resp_approved_amount',None)
+    d['resp_pay_reference'] = doc.resp_pay_reference
+    d['resp_desc'] = doc.resp_desc
+    d['order_id'] = doc.order_id
+    d['resp_code'] = doc.resp_code
+    d['resp_card_num'] = doc.resp_card_num
+    d['date'] = getattr(doc,'date',None)
+    d['resp_date'] = getattr(doc,'resp_date',None)
+    doc.edit(mapping = d)
+    msg = " ".join(["%s: %s" % (key,value) for key,value in d.items()])
+    rwrite(msg)
+    logger.info('upgraded student %s payment %s' % (student_id,d['key']))
+    if not count % commit_after:
+        logger.info("committing %d total %d" % (commit_after,count))
+        commit_count += 1
+        # if not commit_count % 2:
+        #     break
+    count += 1
+logger.info("%d of %d upgraded" % (count,total))
