source: WAeUP_SRP/trunk/skins/waeup_uniben/tranzact_cb.py @ 7901

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

Implement eTranzact payment and restructure change school fee payment.

Session 2011/2012: eTranzact and Interswitch payments only
Previous sessions: scratch card payments only

  • Property svn:keywords set to Id
File size: 7.6 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: tranzact_cb.py 7901 2012-03-17 10:16:07Z 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 = True
44
45if not ontest and not 'webpay.interswitchng.com' 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('SUCCESS: %s' % success)
54
55if 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
88success = request.get('SUCCESS').split('&')
89success_dict = dict([tuple(i.split('=')) for i in success])
90
91pay_doc = context.getContent()
92
93if pay_doc['order_id'] != success_dict['PAYMENT_CODE']:
94    logger.info('%s requeried payment %s for %s but wrong payment code %s returned' % (member,context.getId(),student_id,success_dict['PAYMENT_CODE']))
95    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
96
97if pay_doc['amount'] != success_dict['TRANS_AMOUNT']:
98    logger.info('%s requeried payment %s for %s but wrong amount %s returned' % (member,context.getId(),student_id,success_dict['TRANS_AMOUNT']))
99    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
100
101pd['resp_desc'] = success_dict['TRANS_DESCR']
102pd['resp_pay_reference'] = success_dict['RECEIPT_NO']
103pd['resp_code'] = '00'
104pd['resp_approved_amount'] = success_dict['TRANS_AMOUNT']
105
106pay_doc.edit(mapping = pd)
107
108s_brain = context.students_catalog(id=student_id)[0]
109session = s_brain.session
110
111next_info = context.getNextInfo(s_brain)
112next_session_id = next_info['next_session_id']
113next_session_str = next_info['next_session_str']
114next_level_id = next_info['next_level_id']
115next_transition = next_info['next_transition']
116next_verdict = next_info['next_verdict']
117next_previous_verdict = next_info['next_previous_verdict']
118if  resp == '00':
119    if pay_doc.category == 'schoolfee':
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
187else:
188    logger.info('%s received unsuccessful callback: %s' % (student_id,pd['resp_desc']))
189
190#review_state = wftool.getInfoFor(context,'review_state',None)
191#if review_state == 'opened':
192#    wftool.doActionFor(context,'close')
193context.waeup_tool.changeWorkflowState(context, 'closed')
194
195return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
Note: See TracBrowser for help on using the repository browser.