[1885] | 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: interswitch_cb.py 1937 2007-06-19 17:12:59Z joachim $ |
---|
| 11 | """ |
---|
| 12 | payment callback |
---|
| 13 | """ |
---|
[1937] | 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
[1885] | 19 | import logging |
---|
| 20 | logger = logging.getLogger('Skins.epayment_cb') |
---|
| 21 | from AccessControl import Unauthorized |
---|
| 22 | import DateTime |
---|
| 23 | if context.portal_membership.isAnonymousUser(): |
---|
| 24 | return None |
---|
| 25 | |
---|
| 26 | request = context.REQUEST |
---|
| 27 | students = context.portal_url.getPortalObject().campus.students |
---|
| 28 | wftool = context.portal_workflow |
---|
| 29 | mtool = context.portal_membership |
---|
| 30 | member = mtool.getAuthenticatedMember() |
---|
| 31 | member_id = str(member) |
---|
| 32 | student_id = context.getStudentId() |
---|
| 33 | if 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 | |
---|
| 41 | student = getattr(students,student_id) |
---|
| 42 | |
---|
| 43 | resp_codes = (("desc","resp_desc"), |
---|
| 44 | ("resp","resp_code"), |
---|
| 45 | ("txnref","pay_reference"), |
---|
| 46 | ("payRet","resp_pay_reference"), |
---|
| 47 | ("retRef","retRef"), |
---|
| 48 | ("CardNum","resp_card_num"), |
---|
| 49 | ("apprAmt","resp_approved_amount"), |
---|
| 50 | ) |
---|
| 51 | pd = {} |
---|
| 52 | #from Products.zdb import set_trace;set_trace() |
---|
| 53 | for rc,pdk in resp_codes: |
---|
[1937] | 54 | pd[pdk] = request.get(rc,'') |
---|
| 55 | if pd['resp_code'] == '00' and len(pd['resp_approved_amount']) > 4: |
---|
| 56 | pd['resp_approved_amount'] = pd['resp_approved_amount'][:-2] |
---|
| 57 | else: |
---|
| 58 | pd['resp_approved_amount'] = '0' |
---|
[1885] | 59 | try: |
---|
| 60 | context.getContent().edit(mapping=pd) |
---|
| 61 | except UnAuthorized,E: |
---|
| 62 | logger.info('%s ' % student_id) |
---|
| 63 | |
---|
| 64 | #resp = pd['resp_desc'] |
---|
| 65 | #if resp.startswith('Appro') and resp.endswith('essful'): |
---|
| 66 | resp = pd['resp_code'] |
---|
| 67 | if resp == '00': |
---|
[1892] | 68 | if context.getStudentReviewState() == "school_fee_paid": |
---|
| 69 | logger.info('%s paid school_fee in state school_fee_paid' % (student_id)) |
---|
| 70 | else: |
---|
| 71 | wftool.doActionFor(student,'pay_school_fee') |
---|
[1885] | 72 | logger.info('%s received valid callback' % student_id) |
---|
| 73 | referer = request.get('HTTP_REFERER','none') |
---|
| 74 | logger.info('%s valid callback referer = %s' % (student_id,referer)) |
---|
| 75 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
| 76 | logger.info('%s valid callback real_ip = %s' % (student_id,real_ip)) |
---|
| 77 | |
---|
| 78 | else: |
---|
| 79 | logger.info('%s received unsuccessfull callback' % student_id) |
---|
| 80 | try: |
---|
| 81 | wftool.doActionFor(context,'close') |
---|
| 82 | except: |
---|
| 83 | logger.info('%s no workflow action close' % student_id) |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|