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 8145 2012-04-13 15:49:31Z henrik $ |
---|
11 | """ |
---|
12 | payment callback |
---|
13 | """ |
---|
14 | import logging |
---|
15 | logger = logging.getLogger('Skins.etranzact_cb') |
---|
16 | from AccessControl import Unauthorized |
---|
17 | import DateTime |
---|
18 | |
---|
19 | if context.portal_membership.isAnonymousUser(): |
---|
20 | return None |
---|
21 | |
---|
22 | request = context.REQUEST |
---|
23 | students = context.portal_url.getPortalObject().campus.students |
---|
24 | wftool = context.portal_workflow |
---|
25 | mtool = context.portal_membership |
---|
26 | member = mtool.getAuthenticatedMember() |
---|
27 | member_id = str(member) |
---|
28 | #student_id = context.getStudentId() |
---|
29 | access_info = context.waeup_tool.getAccessInfo(context) |
---|
30 | student_id = access_info['student_id'] |
---|
31 | if 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 | |
---|
39 | referer = request.get('HTTP_REFERER','none') |
---|
40 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
41 | logger.info('%s, callback referer = %s, IP = %s' % (student_id,referer,real_ip)) |
---|
42 | |
---|
43 | ontest = False |
---|
44 | |
---|
45 | if 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 | |
---|
49 | student = getattr(students,student_id) |
---|
50 | |
---|
51 | success = request.get('SUCCESS') |
---|
52 | |
---|
53 | logger.info('SUCCESS: %s' % success) |
---|
54 | |
---|
55 | if success == '-1': |
---|
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 | |
---|
59 | |
---|
60 | # Example: |
---|
61 | #'RECEIPT_NO=5001109085339 |
---|
62 | #&PAYMENT_CODE=500856521315472785095 |
---|
63 | #&MERCHANT_CODE=0570019903 |
---|
64 | #&TRANS_AMOUNT=5000.0 |
---|
65 | #&TRANS_DATE=2011/09/08 10:06:31 |
---|
66 | #&TRANS_DESCR=Trade%20-%20Tel%20line%20installation%20EO20474-Obinna%20Mbagwu |
---|
67 | #&CUSTOMER_ID=EO20474 |
---|
68 | #&BANK_CODE=500 |
---|
69 | #&BRANCH_CODE=001 |
---|
70 | #&SERVICE_ID=EO20474 |
---|
71 | #&CUSTOMER_NAME=Obinna%20Mbagwu |
---|
72 | #&CUSTOMER_ADDRESS=No%207%20Park%20View%20Estate%20Ikoyi |
---|
73 | #&TELLER_ID=etzbankteller |
---|
74 | #&USERNAME=N/A |
---|
75 | #&PASSWORD=N/A |
---|
76 | #&BANK_NAME=eTranzact%20Test%20Bank |
---|
77 | #&BRANCH_NAME=ETZ%20BANK%20HEAD%20OFFICE |
---|
78 | #&CHANNEL_NAME=Bank |
---|
79 | #&PAYMENT_METHOD_NAME=Cash |
---|
80 | #&PAYMENT_CURRENCY=566 |
---|
81 | #&TRANS_TYPE=002 |
---|
82 | #&TRANS_FEE=0.0 |
---|
83 | #&TYPE_NAME=Trade%20-%20Tel%20line%20installation |
---|
84 | #&LEAD_BANK_CODE=057 |
---|
85 | #&LEAD_BANK_NAME=eTranzact%20Test%20Bank' |
---|
86 | |
---|
87 | success = request.get('SUCCESS').split('&') |
---|
88 | success_dict = dict([tuple(i.split('=')) for i in success]) |
---|
89 | |
---|
90 | pay_doc = context.getContent() |
---|
91 | |
---|
92 | if pay_doc['order_id'] != success_dict['COL1'] and not ontest : |
---|
93 | logger.info('%s requeried payment %s for %s but wrong COL1 %s returned' % (member,context.getId(),student_id,success_dict['COL1'])) |
---|
94 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
95 | |
---|
96 | if float(pay_doc['amount']) != float(success_dict['TRANS_AMOUNT']) and not ontest : |
---|
97 | logger.info('%s requeried payment %s for %s but wrong amount %s returned' % (member,context.getId(),student_id,success_dict['TRANS_AMOUNT'])) |
---|
98 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
99 | |
---|
100 | pd = {} |
---|
101 | pd['resp_desc'] = success_dict['TRANS_DESCR'].replace('%20',' ') |
---|
102 | pd['resp_pay_reference'] = success_dict['RECEIPT_NO'] |
---|
103 | pd['resp_code'] = 'ET' |
---|
104 | pd['resp_approved_amount'] = success_dict['TRANS_AMOUNT'] |
---|
105 | pd['status'] = 'paid' |
---|
106 | |
---|
107 | pay_doc.edit(mapping = pd) |
---|
108 | |
---|
109 | s_brain = context.students_catalog(id=student_id)[0] |
---|
110 | session = s_brain.session |
---|
111 | |
---|
112 | if pay_doc.category == 'schoolfee': |
---|
113 | next_info = context.getNextInfo(s_brain) |
---|
114 | next_session_id = next_info['next_session_id'] |
---|
115 | next_session_str = next_info['next_session_str'] |
---|
116 | next_level_id = next_info['next_level_id'] |
---|
117 | next_transition = next_info['next_transition'] |
---|
118 | next_verdict = next_info['next_verdict'] |
---|
119 | next_previous_verdict = next_info['next_previous_verdict'] |
---|
120 | if context.getStudentReviewState() == "school_fee_paid": |
---|
121 | logger.info('%s paid school_fee in state school_fee_paid' % (student_id)) |
---|
122 | else: |
---|
123 | study_course = getattr(student,'study_course') |
---|
124 | try: |
---|
125 | wftool.doActionFor(study_course,'open') |
---|
126 | except: |
---|
127 | pass |
---|
128 | verdict = s_brain.verdict |
---|
129 | if next_previous_verdict == 'N/A': |
---|
130 | next_previous_verdict = '' |
---|
131 | study_course.getContent().edit(mapping= {'current_level': next_level_id, |
---|
132 | 'current_session': next_session_id, |
---|
133 | 'current_verdict': next_verdict, |
---|
134 | 'previous_verdict': next_previous_verdict, |
---|
135 | }) |
---|
136 | if next_transition: |
---|
137 | wftool.doActionFor(student,next_transition) |
---|
138 | |
---|
139 | |
---|
140 | elif pay_doc.category == 'hostel_maintenance': |
---|
141 | |
---|
142 | ## callback function for accommodation_catalog method |
---|
143 | data={} |
---|
144 | data['acco_maint_date'] = pay_doc.date |
---|
145 | data['catkey'] =student_id + '|' + pay_doc.session_id |
---|
146 | data['acco_maint_fee'] = pay_doc.amount |
---|
147 | data['acco_maint_pay_id'] = context.getId() |
---|
148 | data['reservation_status'] = 'maintenance_fee_paid' |
---|
149 | context.accommodation_catalog.modifyRecord(**data) |
---|
150 | |
---|
151 | ## callback function for accommodation object method (deactivated since March 2011) |
---|
152 | #acco_info = context.getAccommodationInfo() |
---|
153 | #d = {} |
---|
154 | #d['acco_maint_date'] = pay_doc.date |
---|
155 | #d['acco_maint_fee'] = pay_doc.amount |
---|
156 | #d['acco_maint_pay_id'] = context.getId() |
---|
157 | #try: |
---|
158 | # acco_info['acco_doc'].edit(mapping=d) |
---|
159 | #except: |
---|
160 | # logger.info('%s requeried payment though maintenance already paid' % student_id) |
---|
161 | #try: |
---|
162 | # wftool.doActionFor(acco_info['acco'],'pay_maintenance_fee',dest_container=acco_info['acco']) |
---|
163 | #except: |
---|
164 | # logger.info('%s no workflow action pay_maintenance_fee' % student_id) |
---|
165 | |
---|
166 | elif pay_doc.category == 'acceptance': |
---|
167 | if context.getStudentReviewState() in ('admitted', 'objection_raised'): |
---|
168 | logger.info('%s paid acceptance fee' % (student_id)) |
---|
169 | current = DateTime.DateTime() |
---|
170 | wf = context.portal_workflow |
---|
171 | info = context.getClearanceInfo() |
---|
172 | wftool.doActionFor(student,'enter_clearance_pin') |
---|
173 | context.waeup_tool.changeWorkflowState(info['clear'], 'opened') |
---|
174 | context.waeup_tool.changeWorkflowState(info['app'], 'closed') |
---|
175 | dc = {} |
---|
176 | app_doc = info['app_doc'] |
---|
177 | #dc['clr_ac_pin'] = pay_doc.order_id |
---|
178 | dc['clr_ac_date'] = current |
---|
179 | dc['entry_date'] = current |
---|
180 | info['clear_doc'].edit(mapping = dc) |
---|
181 | if info['penalty']: |
---|
182 | logger.info('%s started late clearance' % (info['id'])) |
---|
183 | #return redirect("%s/clearance_edit_form" % info['clear'].absolute_url()) |
---|
184 | |
---|
185 | logger.info('%s received valid callback' % student_id) |
---|
186 | |
---|
187 | #review_state = wftool.getInfoFor(context,'review_state',None) |
---|
188 | #if review_state == 'opened': |
---|
189 | # wftool.doActionFor(context,'close') |
---|
190 | context.waeup_tool.changeWorkflowState(context, 'closed') |
---|
191 | |
---|
192 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|