source: WAeUP_SRP/base/skins/waeup_epayment/interswitch_cb.py @ 2762

Last change on this file since 2762 was 2679, checked in by Henrik Bettermann, 17 years ago

fixed

  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1## Script (Python) "interswitch_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_cb.py 2679 2007-11-16 13:57:40Z henrik $
11"""
12payment callback
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19import logging
20logger = logging.getLogger('Skins.interswitch_cb')
21from AccessControl import Unauthorized
22import DateTime
23if context.portal_membership.isAnonymousUser():
24    return None
25
26request = context.REQUEST
27students = context.portal_url.getPortalObject().campus.students
28wftool = context.portal_workflow
29mtool = context.portal_membership
30member = mtool.getAuthenticatedMember()
31member_id = str(member)
32student_id = context.getStudentId()
33if student_id is None: # or student_id != member_id:
34    logger.info('%s tried to access payment object of %s' % (member_id,student_id))
35    referer = request.get('HTTP_REFERER','none')
36    logger.info('%s:%s illegal access, referer = %s' % (member_id,student_id,referer))
37    real_ip = request.get('HTTP_X_REAL_IP',"none")
38    logger.info('%s:%s illegal access, real_x_ip = %s' % (member_id,student_id,real_ip))
39    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
40
41student = getattr(students,student_id)
42resp_codes = (("desc","resp_desc"),
43              ("resp","resp_code"),
44              ("txnRef","pay_reference"),
45              ("payRef","resp_pay_reference"),
46              ("retRef","retRef"),
47              ("cardNum","resp_card_num"),
48              ("apprAmt","resp_approved_amount"),
49              )
50pd = {}
51for rc,pdk in resp_codes:
52    pd[pdk] = request.get(rc,'')
53
54## for testing purposes
55#pd['resp_desc'] = 'Simulated Callback'
56#pd['resp_pay_reference'] = 'XXXX'
57#pd['resp_code'] = '00'
58#pd['resp_card_num'] = '0000'
59#pd['resp_approved_amount'] = '10000'
60
61if pd['resp_code'] == '00' and len(pd['resp_approved_amount']) > 4:
62    pd['resp_approved_amount'] = pd['resp_approved_amount'][:-2]
63else:
64    pd['resp_approved_amount'] = '0'
65
66review_state = wftool.getInfoFor(context,'review_state',None)
67if pd['resp_code'] == '' and review_state == 'opened':
68    logger.info('%s requeried payment %s and got empty response' % (student_id,context.getId()))
69    wftool.doActionFor(context,'close')
70    return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
71context.getContent().edit(mapping = pd)
72resp = pd['resp_code']
73
74s_brain = context.students_catalog(id=student_id)[0]
75session = s_brain.session
76#next_session, next_session_str = context.getNextSessionId(session)
77
78next_info = context.getNextInfo(s_brain)
79next_session_id = next_info['next_session_id']
80next_session_str = next_info['next_session_str']
81next_level_id = next_info['next_level_id']
82next_transition = next_info['next_transition']
83next_verdict = next_info['next_verdict']
84next_previous_verdict = next_info['next_previous_verdict']
85
86if  resp == '00':
87    if context.getStudentReviewState() == "school_fee_paid":
88        logger.info('%s paid school_fee in state school_fee_paid' % (student_id))
89    else:
90        study_course = getattr(student,'study_course')
91        try:
92            wftool.doActionFor(study_course,'open')
93        except:
94            pass
95        verdict = s_brain.verdict
96        if next_previous_verdict == 'N/A':
97            next_previous_verdict = ''
98        study_course.getContent().edit(mapping= {'current_level': next_level_id,
99                                                 'current_session': next_session_id,
100                                                 'current_verdict': next_verdict,
101                                                 'previous_verdict': next_previous_verdict,
102                                                 })
103        if next_transition:
104            wftool.doActionFor(student,next_transition)
105
106    logger.info('%s received valid callback' % student_id)
107    referer = request.get('HTTP_REFERER','none')
108    logger.info('%s valid callback referer = %s' % (student_id,referer))
109    real_ip = request.get('HTTP_X_REAL_IP',"none")
110    logger.info('%s valid callback real_ip = %s' % (student_id,real_ip))
111
112else:
113    logger.info('%s received unsuccessfull callback: %s' % (student_id,pd['resp_desc']))
114try:
115    wftool.doActionFor(context,'close')
116except:
117    logger.info('%s no workflow action close' % student_id)
118
119
120return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url())
Note: See TracBrowser for help on using the repository browser.