source: WAeUP_SRP/trunk/skins/waeup_epayment/interswitch_cb.py @ 3846

Last change on this file since 3846 was 3816, checked in by Henrik Bettermann, 16 years ago

resolve ticket FUTMinna #18

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