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

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

Some improvements and repairs.

  • Property svn:keywords set to Id
File size: 7.3 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 7902 2012-03-17 11:49:56Z 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 = {}
102pd['resp_desc'] = success_dict['TRANS_DESCR'].replace('%20',' ')
103pd['resp_pay_reference'] = success_dict['RECEIPT_NO']
104pd['resp_code'] = 'ET'
105pd['resp_approved_amount'] = success_dict['TRANS_AMOUNT']
106pd['status'] = 'paid'
107
108pay_doc.edit(mapping = pd)
109
110s_brain = context.students_catalog(id=student_id)[0]
111session = s_brain.session
112
113next_info = context.getNextInfo(s_brain)
114next_session_id = next_info['next_session_id']
115next_session_str = next_info['next_session_str']
116next_level_id = next_info['next_level_id']
117next_transition = next_info['next_transition']
118next_verdict = next_info['next_verdict']
119next_previous_verdict = next_info['next_previous_verdict']
120if pay_doc.category == 'schoolfee':
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
141elif pay_doc.category == 'hostel_maintenance':
142
143    ## callback function for accommodation_catalog method
144    data={}
145    data['acco_maint_date'] = pay_doc.date
146    data['catkey'] =student_id + '|' + pay_doc.session_id
147    data['acco_maint_fee'] = pay_doc.amount
148    data['acco_maint_pay_id'] = context.getId()
149    data['reservation_status'] = 'maintenance_fee_paid'
150    context.accommodation_catalog.modifyRecord(**data)
151
152    ## callback function for accommodation object method (deactivated since March 2011)
153    #acco_info = context.getAccommodationInfo()
154    #d = {}
155    #d['acco_maint_date'] = pay_doc.date
156    #d['acco_maint_fee'] = pay_doc.amount
157    #d['acco_maint_pay_id'] = context.getId()
158    #try:
159    #    acco_info['acco_doc'].edit(mapping=d)
160    #except:
161    #    logger.info('%s requeried payment though maintenance already paid' % student_id)
162    #try:
163    #    wftool.doActionFor(acco_info['acco'],'pay_maintenance_fee',dest_container=acco_info['acco'])
164    #except:
165    #    logger.info('%s no workflow action pay_maintenance_fee' % student_id)
166
167elif pay_doc.category == 'acceptance':
168    if context.getStudentReviewState() in ('admitted', 'objection_raised'):
169        logger.info('%s paid acceptance fee' % (student_id))
170        current = DateTime.DateTime()
171        wf = context.portal_workflow
172        info = context.getClearanceInfo()
173        wftool.doActionFor(student,'enter_clearance_pin')
174        context.waeup_tool.changeWorkflowState(info['clear'], 'opened')
175        context.waeup_tool.changeWorkflowState(info['app'], 'closed')
176        dc = {}
177        app_doc = info['app_doc']
178        #dc['clr_ac_pin'] = pay_doc.order_id
179        dc['clr_ac_date'] = current
180        dc['entry_date'] = current
181        info['clear_doc'].edit(mapping = dc)
182        if info['penalty']:
183            logger.info('%s started late clearance' % (info['id']))
184        #return redirect("%s/clearance_edit_form" % info['clear'].absolute_url())
185
186logger.info('%s received valid callback' % student_id)
187
188#review_state = wftool.getInfoFor(context,'review_state',None)
189#if review_state == 'opened':
190#    wftool.doActionFor(context,'close')
191context.waeup_tool.changeWorkflowState(context, 'closed')
192
193return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
Note: See TracBrowser for help on using the repository browser.