## Script (Python) "tranzact_cb" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: tranzact_cb.py 7901 2012-03-17 10:16:07Z henrik $ """ payment callback """ import logging logger = logging.getLogger('Skins.etranzact_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() access_info = context.waeup_tool.getAccessInfo(context) student_id = access_info['student_id'] if not context.isSectionOfficer() and (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()) referer = request.get('HTTP_REFERER','none') real_ip = request.get('HTTP_X_REAL_IP',"none") logger.info('%s, callback referer = %s, IP = %s' % (student_id,referer,real_ip)) ontest = True if not ontest and not 'webpay.interswitchng.com' in referer and not 'waeup.org' in referer: logger.info('%s, wrong callback referer %s, callback rejected, IP = %s' % (student_id,referer,real_ip)) return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) student = getattr(students,student_id) success = request.get('SUCCESS') logger.info('SUCCESS: %s' % success) if success == '-1': logger.info('%s requeried payment %s for %s without success' % (member,context.getId(),student_id)) return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) # Example: #'RECEIPT_NO=5001109085339 #&PAYMENT_CODE=500856521315472785095 #&MERCHANT_CODE=0570019903 #&TRANS_AMOUNT=5000.0 #&TRANS_DATE=2011/09/08 10:06:31 #&TRANS_DESCR=Trade%20-%20Tel%20line%20installation%20EO20474-Obinna%20Mbagwu #&CUSTOMER_ID=EO20474 #&BANK_CODE=500 #&BRANCH_CODE=001 #&SERVICE_ID=EO20474 #&CUSTOMER_NAME=Obinna%20Mbagwu #&CUSTOMER_ADDRESS=No%207%20Park%20View%20Estate%20Ikoyi #&TELLER_ID=etzbankteller #&USERNAME=N/A #&PASSWORD=N/A #&BANK_NAME=eTranzact%20Test%20Bank #&BRANCH_NAME=ETZ%20BANK%20HEAD%20OFFICE #&CHANNEL_NAME=Bank #&PAYMENT_METHOD_NAME=Cash #&PAYMENT_CURRENCY=566 #&TRANS_TYPE=002 #&TRANS_FEE=0.0 #&TYPE_NAME=Trade%20-%20Tel%20line%20installation #&LEAD_BANK_CODE=057 #&LEAD_BANK_NAME=eTranzact%20Test%20Bank' success = request.get('SUCCESS').split('&') success_dict = dict([tuple(i.split('=')) for i in success]) pay_doc = context.getContent() if pay_doc['order_id'] != success_dict['PAYMENT_CODE']: logger.info('%s requeried payment %s for %s but wrong payment code %s returned' % (member,context.getId(),student_id,success_dict['PAYMENT_CODE'])) return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) if pay_doc['amount'] != success_dict['TRANS_AMOUNT']: logger.info('%s requeried payment %s for %s but wrong amount %s returned' % (member,context.getId(),student_id,success_dict['TRANS_AMOUNT'])) return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) pd['resp_desc'] = success_dict['TRANS_DESCR'] pd['resp_pay_reference'] = success_dict['RECEIPT_NO'] pd['resp_code'] = '00' pd['resp_approved_amount'] = success_dict['TRANS_AMOUNT'] pay_doc.edit(mapping = pd) s_brain = context.students_catalog(id=student_id)[0] session = s_brain.session next_info = context.getNextInfo(s_brain) next_session_id = next_info['next_session_id'] next_session_str = next_info['next_session_str'] next_level_id = next_info['next_level_id'] next_transition = next_info['next_transition'] next_verdict = next_info['next_verdict'] next_previous_verdict = next_info['next_previous_verdict'] if resp == '00': if pay_doc.category == 'schoolfee': if context.getStudentReviewState() == "school_fee_paid": logger.info('%s paid school_fee in state school_fee_paid' % (student_id)) else: study_course = getattr(student,'study_course') try: wftool.doActionFor(study_course,'open') except: pass verdict = s_brain.verdict if next_previous_verdict == 'N/A': next_previous_verdict = '' study_course.getContent().edit(mapping= {'current_level': next_level_id, 'current_session': next_session_id, 'current_verdict': next_verdict, 'previous_verdict': next_previous_verdict, }) if next_transition: wftool.doActionFor(student,next_transition) elif pay_doc.category == 'hostel_maintenance': ## callback function for accommodation_catalog method data={} data['acco_maint_date'] = pay_doc.date data['catkey'] =student_id + '|' + pay_doc.session_id data['acco_maint_fee'] = pay_doc.amount data['acco_maint_pay_id'] = context.getId() data['reservation_status'] = 'maintenance_fee_paid' context.accommodation_catalog.modifyRecord(**data) ## callback function for accommodation object method (deactivated since March 2011) #acco_info = context.getAccommodationInfo() #d = {} #d['acco_maint_date'] = pay_doc.date #d['acco_maint_fee'] = pay_doc.amount #d['acco_maint_pay_id'] = context.getId() #try: # acco_info['acco_doc'].edit(mapping=d) #except: # logger.info('%s requeried payment though maintenance already paid' % student_id) #try: # wftool.doActionFor(acco_info['acco'],'pay_maintenance_fee',dest_container=acco_info['acco']) #except: # logger.info('%s no workflow action pay_maintenance_fee' % student_id) elif pay_doc.category == 'acceptance': if context.getStudentReviewState() in ('admitted', 'objection_raised'): logger.info('%s paid acceptance fee' % (student_id)) current = DateTime.DateTime() wf = context.portal_workflow info = context.getClearanceInfo() wftool.doActionFor(student,'enter_clearance_pin') context.waeup_tool.changeWorkflowState(info['clear'], 'opened') context.waeup_tool.changeWorkflowState(info['app'], 'closed') dc = {} app_doc = info['app_doc'] #dc['clr_ac_pin'] = pay_doc.order_id dc['clr_ac_date'] = current dc['entry_date'] = current info['clear_doc'].edit(mapping = dc) if info['penalty']: logger.info('%s started late clearance' % (info['id'])) #return redirect("%s/clearance_edit_form" % info['clear'].absolute_url()) logger.info('%s received valid callback' % student_id) else: logger.info('%s received unsuccessful callback: %s' % (student_id,pd['resp_desc'])) #review_state = wftool.getInfoFor(context,'review_state',None) #if review_state == 'opened': # wftool.doActionFor(context,'close') context.waeup_tool.changeWorkflowState(context, 'closed') return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())