[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 2940 2007-12-13 09:08:24Z henrik $ |
---|
| 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 |
---|
[1948] | 20 | logger = logging.getLogger('Skins.interswitch_cb') |
---|
[1885] | 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() |
---|
[1973] | 33 | if student_id is None: # or student_id != member_id: |
---|
[1885] | 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 | resp_codes = (("desc","resp_desc"), |
---|
| 43 | ("resp","resp_code"), |
---|
[1944] | 44 | ("txnRef","pay_reference"), |
---|
| 45 | ("payRef","resp_pay_reference"), |
---|
[1885] | 46 | ("retRef","retRef"), |
---|
[1944] | 47 | ("cardNum","resp_card_num"), |
---|
[1885] | 48 | ("apprAmt","resp_approved_amount"), |
---|
| 49 | ) |
---|
| 50 | pd = {} |
---|
| 51 | for rc,pdk in resp_codes: |
---|
[1937] | 52 | pd[pdk] = request.get(rc,'') |
---|
[1992] | 53 | |
---|
[2454] | 54 | ## for testing purposes |
---|
[1992] | 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 | |
---|
[1948] | 61 | if pd['resp_code'] == '00' and len(pd['resp_approved_amount']) > 4: |
---|
[1937] | 62 | pd['resp_approved_amount'] = pd['resp_approved_amount'][:-2] |
---|
[2859] | 63 | pd['status'] = 'paid' |
---|
[1937] | 64 | else: |
---|
| 65 | pd['resp_approved_amount'] = '0' |
---|
[2859] | 66 | pd['status'] = 'failed' |
---|
[1948] | 67 | |
---|
[1944] | 68 | review_state = wftool.getInfoFor(context,'review_state',None) |
---|
[2940] | 69 | if pd['resp_code'] == '': |
---|
| 70 | logger.info('%s requeried payment %s for %s and got empty response' % (member,context.getId(),student_id)) |
---|
| 71 | if review_state == 'opened': |
---|
| 72 | wftool.doActionFor(context,'close') |
---|
[1944] | 73 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
[2856] | 74 | try: |
---|
| 75 | context.getContent().edit(mapping = pd) |
---|
| 76 | except: |
---|
| 77 | logger.info('%s tried to edit payment %s in state %s' % (student_id, |
---|
| 78 | context.getId(), |
---|
| 79 | review_state)) |
---|
| 80 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
[2877] | 81 | |
---|
[1885] | 82 | resp = pd['resp_code'] |
---|
[1992] | 83 | |
---|
| 84 | s_brain = context.students_catalog(id=student_id)[0] |
---|
| 85 | session = s_brain.session |
---|
[2454] | 86 | #next_session, next_session_str = context.getNextSessionId(session) |
---|
[1992] | 87 | |
---|
[2454] | 88 | next_info = context.getNextInfo(s_brain) |
---|
| 89 | next_session_id = next_info['next_session_id'] |
---|
| 90 | next_session_str = next_info['next_session_str'] |
---|
| 91 | next_level_id = next_info['next_level_id'] |
---|
| 92 | next_transition = next_info['next_transition'] |
---|
[2475] | 93 | next_verdict = next_info['next_verdict'] |
---|
[2679] | 94 | next_previous_verdict = next_info['next_previous_verdict'] |
---|
[2454] | 95 | |
---|
[1885] | 96 | if resp == '00': |
---|
[1892] | 97 | if context.getStudentReviewState() == "school_fee_paid": |
---|
| 98 | logger.info('%s paid school_fee in state school_fee_paid' % (student_id)) |
---|
| 99 | else: |
---|
[2454] | 100 | study_course = getattr(student,'study_course') |
---|
| 101 | try: |
---|
| 102 | wftool.doActionFor(study_course,'open') |
---|
| 103 | except: |
---|
| 104 | pass |
---|
[2475] | 105 | verdict = s_brain.verdict |
---|
[2679] | 106 | if next_previous_verdict == 'N/A': |
---|
| 107 | next_previous_verdict = '' |
---|
[2454] | 108 | study_course.getContent().edit(mapping= {'current_level': next_level_id, |
---|
[2475] | 109 | 'current_session': next_session_id, |
---|
[2476] | 110 | 'current_verdict': next_verdict, |
---|
[2679] | 111 | 'previous_verdict': next_previous_verdict, |
---|
[2475] | 112 | }) |
---|
[2454] | 113 | if next_transition: |
---|
[2475] | 114 | wftool.doActionFor(student,next_transition) |
---|
[2454] | 115 | |
---|
[1885] | 116 | logger.info('%s received valid callback' % student_id) |
---|
| 117 | referer = request.get('HTTP_REFERER','none') |
---|
| 118 | logger.info('%s valid callback referer = %s' % (student_id,referer)) |
---|
| 119 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
| 120 | logger.info('%s valid callback real_ip = %s' % (student_id,real_ip)) |
---|
| 121 | |
---|
| 122 | else: |
---|
[1956] | 123 | logger.info('%s received unsuccessfull callback: %s' % (student_id,pd['resp_desc'])) |
---|
[1885] | 124 | try: |
---|
| 125 | wftool.doActionFor(context,'close') |
---|
| 126 | except: |
---|
| 127 | logger.info('%s no workflow action close' % student_id) |
---|
| 128 | |
---|
[1948] | 129 | |
---|
[1885] | 130 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
[2940] | 131 | |
---|