source: WAeUP_SRP/trunk/skins/waeup_uniben/etranzact_cb.py @ 17328

Last change on this file since 17328 was 8235, checked in by Henrik Bettermann, 13 years ago

Add member id to log message.

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1## Script (Python) "tranzact_cb"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: etranzact_cb.py 8235 2012-04-20 11:48:31Z henrik $
11"""
12payment callback
13"""
14import logging
15logger = logging.getLogger('Skins.etranzact_cb')
16from AccessControl import Unauthorized
17import DateTime
18
19if context.portal_membership.isAnonymousUser():
20    return None
21
22request = context.REQUEST
23students = context.portal_url.getPortalObject().campus.students
24wftool = context.portal_workflow
25mtool = context.portal_membership
26member = mtool.getAuthenticatedMember()
27member_id = str(member)
28#student_id = context.getStudentId()
29access_info = context.waeup_tool.getAccessInfo(context)
30student_id = access_info['student_id']
31if not context.isSectionOfficer() and (student_id is None or student_id != member_id):
32    logger.info('%s tried to access payment object of %s' % (member_id,student_id))
33    referer = request.get('HTTP_REFERER','none')
34    logger.info('%s:%s illegal access, referer = %s' % (member_id,student_id,referer))
35    real_ip = request.get('HTTP_X_REAL_IP',"none")
36    logger.info('%s:%s illegal access, real_x_ip = %s' % (member_id,student_id,real_ip))
37    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
38
39referer = request.get('HTTP_REFERER','none')
40real_ip = request.get('HTTP_X_REAL_IP',"none")
41logger.info('%s, callback referer = %s, IP = %s' % (student_id,referer,real_ip))
42
43ontest = False
44
45if not ontest and not 'etranzact' in referer and not 'waeup.org' in referer:
46    logger.info('%s, wrong callback referer %s, callback rejected, IP = %s' % (student_id,referer,real_ip))
47    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
48
49student = getattr(students,student_id)
50
51success = request.get('SUCCESS')
52
53logger.info('%s, SUCCESS: %s' % (member,success))
54
55if not 'COL1' in success:
56    logger.info('%s requeried payment %s for %s without success' % (member,context.getId(),student_id))
57    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
58
59success = request.get('SUCCESS').split('&')
60success_dict = dict([tuple(i.split('=')) for i in success])
61
62pay_doc = context.getContent()
63
64oid = pay_doc['order_id']
65col1 = success_dict['COL1']
66
67if oid[len(oid)-8:len(oid)] != col1[len(col1)-8:len(col1)] and not ontest :
68    logger.info('%s requeried payment %s for %s but wrong COL1 %s returned' % (member,context.getId(),student_id,success_dict['COL1']))
69    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
70
71if float(pay_doc['amount']) != float(success_dict['TRANS_AMOUNT']) and not ontest :
72    logger.info('%s requeried payment %s for %s but wrong amount %s returned' % (member,context.getId(),student_id,success_dict['TRANS_AMOUNT']))
73    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
74
75pd = {}
76pd['resp_desc'] = success_dict['TRANS_DESCR'].replace('%20',' ')
77pd['resp_pay_reference'] = success_dict['RECEIPT_NO']
78pd['resp_code'] = 'ET'
79pd['resp_approved_amount'] = success_dict['TRANS_AMOUNT']
80pd['status'] = 'paid'
81
82pay_doc.edit(mapping = pd)
83
84s_brain = context.students_catalog(id=student_id)[0]
85session = s_brain.session
86
87if pay_doc.category == 'schoolfee':
88    next_info = context.getNextInfo(s_brain)
89    next_session_id = next_info['next_session_id']
90    next_session_str = next_info['next_session_str']
91    next_level_id = next_info['next_level_id']
92    next_transition = next_info['next_transition']
93    next_verdict = next_info['next_verdict']
94    next_previous_verdict = next_info['next_previous_verdict']
95    if context.getStudentReviewState() == "school_fee_paid":
96        logger.info('%s paid school_fee in state school_fee_paid' % (student_id))
97    else:
98        study_course = getattr(student,'study_course')
99        try:
100            wftool.doActionFor(study_course,'open')
101        except:
102            pass
103        verdict = s_brain.verdict
104        if next_previous_verdict == 'N/A':
105            next_previous_verdict = ''
106        study_course.getContent().edit(mapping= {'current_level': next_level_id,
107                                                 'current_session': next_session_id,
108                                                 'current_verdict': next_verdict,
109                                                 'previous_verdict': next_previous_verdict,
110                                                 })
111        if next_transition:
112            wftool.doActionFor(student,next_transition)
113
114
115elif pay_doc.category == 'hostel_maintenance':
116
117    ## callback function for accommodation_catalog method
118    data={}
119    data['acco_maint_date'] = pay_doc.date
120    data['catkey'] =student_id + '|' + pay_doc.session_id
121    data['acco_maint_fee'] = pay_doc.amount
122    data['acco_maint_pay_id'] = context.getId()
123    data['reservation_status'] = 'maintenance_fee_paid'
124    context.accommodation_catalog.modifyRecord(**data)
125
126    ## callback function for accommodation object method (deactivated since March 2011)
127    #acco_info = context.getAccommodationInfo()
128    #d = {}
129    #d['acco_maint_date'] = pay_doc.date
130    #d['acco_maint_fee'] = pay_doc.amount
131    #d['acco_maint_pay_id'] = context.getId()
132    #try:
133    #    acco_info['acco_doc'].edit(mapping=d)
134    #except:
135    #    logger.info('%s requeried payment though maintenance already paid' % student_id)
136    #try:
137    #    wftool.doActionFor(acco_info['acco'],'pay_maintenance_fee',dest_container=acco_info['acco'])
138    #except:
139    #    logger.info('%s no workflow action pay_maintenance_fee' % student_id)
140
141elif pay_doc.category == 'acceptance':
142    if context.getStudentReviewState() in ('admitted', 'objection_raised'):
143        logger.info('%s paid acceptance fee' % (student_id))
144        current = DateTime.DateTime()
145        wf = context.portal_workflow
146        info = context.getClearanceInfo()
147        wftool.doActionFor(student,'enter_clearance_pin')
148        context.waeup_tool.changeWorkflowState(info['clear'], 'opened')
149        context.waeup_tool.changeWorkflowState(info['app'], 'closed')
150        dc = {}
151        app_doc = info['app_doc']
152        #dc['clr_ac_pin'] = pay_doc.order_id
153        dc['clr_ac_date'] = current
154        dc['entry_date'] = current
155        info['clear_doc'].edit(mapping = dc)
156        if info['penalty']:
157            logger.info('%s started late clearance' % (info['id']))
158        #return redirect("%s/clearance_edit_form" % info['clear'].absolute_url())
159
160logger.info('%s received valid callback' % student_id)
161
162#review_state = wftool.getInfoFor(context,'review_state',None)
163#if review_state == 'opened':
164#    wftool.doActionFor(context,'close')
165context.waeup_tool.changeWorkflowState(context, 'closed')
166
167return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
Note: See TracBrowser for help on using the repository browser.