1 | ## Script (Python) "epayment_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: epayment_cb.py 1653 2007-03-28 02:35:25Z uli $ |
---|
11 | """ |
---|
12 | payment callback |
---|
13 | """ |
---|
14 | import logging |
---|
15 | logger = logging.getLogger('Skins.epayment_cb') |
---|
16 | from AccessControl import Unauthorized |
---|
17 | import DateTime |
---|
18 | if context.portal_membership.isAnonymousUser(): |
---|
19 | return None |
---|
20 | |
---|
21 | request = context.REQUEST |
---|
22 | students = context.portal_url.getPortalObject().campus.students |
---|
23 | wftool = context.portal_workflow |
---|
24 | mtool = context.portal_membership |
---|
25 | member = mtool.getAuthenticatedMember() |
---|
26 | member_id = str(member) |
---|
27 | student_id = context.getStudentId() |
---|
28 | if student_id is None or student_id != member_id: |
---|
29 | logger.info('%s tried to access payment object of %s' % (member_id,student_id)) |
---|
30 | referer = request.get('HTTP_REFERER','none') |
---|
31 | logger.info('%s:%s illegal access, referer = %s' % (member_id,student_id,referer)) |
---|
32 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
33 | logger.info('%s:%s illegal access, real_x_ip = %s' % (member_id,student_id,real_ip)) |
---|
34 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
35 | |
---|
36 | student = getattr(students,student_id) |
---|
37 | |
---|
38 | resp_codes = (("x_RespDesc","resp_desc"), |
---|
39 | ("x_RespPayRef","resp_pay_reference"), |
---|
40 | ("x_RespCode","resp_code"), |
---|
41 | ("x_CardNum","resp_card_num"), |
---|
42 | ("x_ApprAmt","resp_approved_amount"), |
---|
43 | ) |
---|
44 | pd = {} |
---|
45 | #from Products.zdb import set_trace;set_trace() |
---|
46 | for rc,pdk in resp_codes: |
---|
47 | pd[pdk] = request.get(rc) |
---|
48 | try: |
---|
49 | context.getContent().edit(mapping=pd) |
---|
50 | except UnAuthorized,E: |
---|
51 | logger.info('%s ' % student_id) |
---|
52 | |
---|
53 | #resp = pd['resp_desc'] |
---|
54 | #if resp.startswith('Appro') and resp.endswith('essful'): |
---|
55 | resp = pd['resp_code'] |
---|
56 | if resp == '00': |
---|
57 | wftool.doActionFor(student,'pay_school_fee') |
---|
58 | logger.info('%s received valid callback' % student_id) |
---|
59 | referer = request.get('HTTP_REFERER','none') |
---|
60 | logger.info('%s valid callback referer = %s' % (student_id,referer)) |
---|
61 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
62 | logger.info('%s valid callback real_ip = %s' % (student_id,real_ip)) |
---|
63 | |
---|
64 | elif len(resp) < 3: |
---|
65 | logger.info('%s received no callback' % student_id) |
---|
66 | else: |
---|
67 | logger.info('%s received unsuccessfull callback' % student_id) |
---|
68 | wftool.doActionFor(context,'close') |
---|
69 | |
---|
70 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|