## Script (Python) "check_transactions" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: check_transactions.py 1625 2007-03-22 23:53:27Z henrik $ """ 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
\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