1 | ## Script (Python) "interswitch_acco_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: interswitch_acco_cb.py 2900 2007-12-09 21:42:44Z henrik $ |
---|
11 | """ |
---|
12 | payment callback |
---|
13 | """ |
---|
14 | try: |
---|
15 | from Products.zdb import set_trace |
---|
16 | except: |
---|
17 | def set_trace(): |
---|
18 | pass |
---|
19 | import logging |
---|
20 | logger = logging.getLogger('Skins.interswitch_acco_cb') |
---|
21 | from AccessControl import Unauthorized |
---|
22 | import DateTime |
---|
23 | current = DateTime.DateTime() |
---|
24 | |
---|
25 | if context.portal_membership.isAnonymousUser(): |
---|
26 | return None |
---|
27 | |
---|
28 | request = context.REQUEST |
---|
29 | students = context.portal_url.getPortalObject().campus.students |
---|
30 | wftool = context.portal_workflow |
---|
31 | mtool = context.portal_membership |
---|
32 | member = mtool.getAuthenticatedMember() |
---|
33 | member_id = str(member) |
---|
34 | student_id = context.getStudentId() |
---|
35 | if student_id is None: # or student_id != member_id: |
---|
36 | logger.info('%s tried to access payment object of %s' % (member_id,student_id)) |
---|
37 | referer = request.get('HTTP_REFERER','none') |
---|
38 | logger.info('%s:%s illegal access, referer = %s' % (member_id,student_id,referer)) |
---|
39 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
40 | logger.info('%s:%s illegal access, real_x_ip = %s' % (member_id,student_id,real_ip)) |
---|
41 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
42 | |
---|
43 | student = getattr(students,student_id) |
---|
44 | resp_codes = (("desc","resp_desc"), |
---|
45 | ("resp","resp_code"), |
---|
46 | ("txnRef","pay_reference"), |
---|
47 | ("payRef","resp_pay_reference"), |
---|
48 | ("retRef","retRef"), |
---|
49 | ("cardNum","resp_card_num"), |
---|
50 | ("apprAmt","resp_approved_amount"), |
---|
51 | ) |
---|
52 | pd = {} |
---|
53 | for rc,pdk in resp_codes: |
---|
54 | pd[pdk] = request.get(rc,'') |
---|
55 | |
---|
56 | |
---|
57 | ## for testing purposes |
---|
58 | #pd['resp_desc'] = 'Simulated Callback' |
---|
59 | #pd['resp_pay_reference'] = 'XXXX' |
---|
60 | #pd['resp_code'] = '00' |
---|
61 | #pd['resp_card_num'] = '0000' |
---|
62 | #pd['resp_approved_amount'] = '10000' |
---|
63 | |
---|
64 | if pd['resp_code'] == '00' and len(pd['resp_approved_amount']) > 4: |
---|
65 | pd['resp_approved_amount'] = pd['resp_approved_amount'][:-2] |
---|
66 | pd['status'] = 'paid' |
---|
67 | else: |
---|
68 | pd['resp_approved_amount'] = '0' |
---|
69 | pd['status'] = 'failed' |
---|
70 | |
---|
71 | review_state = wftool.getInfoFor(context,'review_state',None) |
---|
72 | if pd['resp_code'] == '' and review_state == 'opened': |
---|
73 | logger.info('%s requeried payment %s and got empty response' % (student_id,context.getId())) |
---|
74 | wftool.doActionFor(context,'close') |
---|
75 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
76 | pay_doc = context.getContent() |
---|
77 | pay_doc.edit(mapping = pd) |
---|
78 | resp = pd['resp_code'] |
---|
79 | |
---|
80 | s_brain = context.students_catalog(id=student_id)[0] |
---|
81 | session = s_brain.session |
---|
82 | #next_session, next_session_str = context.getNextSessionId(session) |
---|
83 | |
---|
84 | if pay_doc.category == 'hostel_maintenance': |
---|
85 | if resp == '00': |
---|
86 | d = {} |
---|
87 | acco_info = context.getAccommodationInfo() |
---|
88 | d['acco_maint_date'] = pay_doc.date |
---|
89 | d['acco_maint_fee'] = pay_doc.amount |
---|
90 | d['acco_maint_pay_id'] = context.getId() |
---|
91 | acco_info['acco_doc'].edit(mapping=d) |
---|
92 | referer = request.get('HTTP_REFERER','none') |
---|
93 | logger.info('%s valid callback referer = %s' % (student_id,referer)) |
---|
94 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
95 | logger.info('%s valid callback real_ip = %s' % (student_id,real_ip)) |
---|
96 | else: |
---|
97 | logger.info('%s received unsuccessfull callback: %s' % (student_id,pd['resp_desc'])) |
---|
98 | |
---|
99 | try: |
---|
100 | wftool.doActionFor(context,'close') |
---|
101 | except: |
---|
102 | logger.info('%s no workflow action close' % student_id) |
---|
103 | try: |
---|
104 | wftool.doActionFor(acco_info['acco'],'pay_maintenance_fee',dest_container=acco_info['acco']) |
---|
105 | return request.RESPONSE.redirect("%s/accommodation_view" % acco_info['student'].absolute_url()) |
---|
106 | except: |
---|
107 | logger.info('%s no workflow action pay_maintainance_fee' % student_id) |
---|
108 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
109 | |
---|
110 | |
---|
111 | else: |
---|
112 | next_info = context.getNextInfo(s_brain) |
---|
113 | next_session_id = next_info['next_session_id'] |
---|
114 | next_session_str = next_info['next_session_str'] |
---|
115 | next_level_id = next_info['next_level_id'] |
---|
116 | next_transition = next_info['next_transition'] |
---|
117 | next_verdict = next_info['next_verdict'] |
---|
118 | next_previous_verdict = next_info['next_previous_verdict'] |
---|
119 | |
---|
120 | if resp == '00': |
---|
121 | if context.getStudentReviewState() == "school_fee_paid": |
---|
122 | logger.info('%s paid school_fee in state school_fee_paid' % (student_id)) |
---|
123 | else: |
---|
124 | study_course = getattr(student,'study_course') |
---|
125 | try: |
---|
126 | wftool.doActionFor(study_course,'open') |
---|
127 | except: |
---|
128 | pass |
---|
129 | verdict = s_brain.verdict |
---|
130 | if next_previous_verdict == 'N/A': |
---|
131 | next_previous_verdict = '' |
---|
132 | study_course.getContent().edit(mapping= {'current_level': next_level_id, |
---|
133 | 'current_session': next_session_id, |
---|
134 | 'current_verdict': next_verdict, |
---|
135 | 'previous_verdict': next_previous_verdict, |
---|
136 | }) |
---|
137 | if next_transition: |
---|
138 | wftool.doActionFor(student,next_transition) |
---|
139 | |
---|
140 | logger.info('%s received valid callback' % student_id) |
---|
141 | referer = request.get('HTTP_REFERER','none') |
---|
142 | logger.info('%s valid callback referer = %s' % (student_id,referer)) |
---|
143 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
144 | logger.info('%s valid callback real_ip = %s' % (student_id,real_ip)) |
---|
145 | else: |
---|
146 | logger.info('%s received unsuccessfull callback: %s' % (student_id,pd['resp_desc'])) |
---|
147 | try: |
---|
148 | wftool.doActionFor(context,'close') |
---|
149 | except: |
---|
150 | logger.info('%s no workflow action close' % student_id) |
---|
151 | |
---|
152 | |
---|