## Script (Python) "epayment_cb" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: interswitch_cb.py 1892 2007-06-13 15:57:09Z joachim $ """ payment callback """ import logging logger = logging.getLogger('Skins.epayment_cb') from AccessControl import Unauthorized import 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"), ("payRet","resp_pay_reference"), ("retRef","retRef"), ("CardNum","resp_card_num"), ("apprAmt","resp_approved_amount"), ) pd = {} #from Products.zdb import set_trace;set_trace() for rc,pdk in resp_codes: pd[pdk] = request.get(rc) 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'): resp = pd['resp_code'] if resp == '00': if context.getStudentReviewState() == "school_fee_paid": logger.info('%s paid school_fee in state school_fee_paid' % (student_id)) else: 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)) else: logger.info('%s received unsuccessfull callback' % student_id) try: wftool.doActionFor(context,'close') except: logger.info('%s no workflow action close' % student_id) return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())