[7901] | 1 | ## Script (Python) "tranzact_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: etranzact_cb.py 8235 2012-04-20 11:48:31Z henrik $ |
---|
| 11 | """ |
---|
| 12 | payment callback |
---|
| 13 | """ |
---|
| 14 | import logging |
---|
| 15 | logger = logging.getLogger('Skins.etranzact_cb') |
---|
| 16 | from AccessControl import Unauthorized |
---|
| 17 | import DateTime |
---|
| 18 | |
---|
| 19 | if context.portal_membership.isAnonymousUser(): |
---|
| 20 | return None |
---|
| 21 | |
---|
| 22 | request = context.REQUEST |
---|
| 23 | students = context.portal_url.getPortalObject().campus.students |
---|
| 24 | wftool = context.portal_workflow |
---|
| 25 | mtool = context.portal_membership |
---|
| 26 | member = mtool.getAuthenticatedMember() |
---|
| 27 | member_id = str(member) |
---|
| 28 | #student_id = context.getStudentId() |
---|
| 29 | access_info = context.waeup_tool.getAccessInfo(context) |
---|
| 30 | student_id = access_info['student_id'] |
---|
| 31 | if not context.isSectionOfficer() and (student_id is None or student_id != member_id): |
---|
| 32 | logger.info('%s tried to access payment object of %s' % (member_id,student_id)) |
---|
| 33 | referer = request.get('HTTP_REFERER','none') |
---|
| 34 | logger.info('%s:%s illegal access, referer = %s' % (member_id,student_id,referer)) |
---|
| 35 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
| 36 | logger.info('%s:%s illegal access, real_x_ip = %s' % (member_id,student_id,real_ip)) |
---|
| 37 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 38 | |
---|
| 39 | referer = request.get('HTTP_REFERER','none') |
---|
| 40 | real_ip = request.get('HTTP_X_REAL_IP',"none") |
---|
| 41 | logger.info('%s, callback referer = %s, IP = %s' % (student_id,referer,real_ip)) |
---|
| 42 | |
---|
[8131] | 43 | ontest = False |
---|
[7901] | 44 | |
---|
[8131] | 45 | if not ontest and not 'etranzact' in referer and not 'waeup.org' in referer: |
---|
[7901] | 46 | logger.info('%s, wrong callback referer %s, callback rejected, IP = %s' % (student_id,referer,real_ip)) |
---|
| 47 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
| 48 | |
---|
| 49 | student = getattr(students,student_id) |
---|
| 50 | |
---|
| 51 | success = request.get('SUCCESS') |
---|
| 52 | |
---|
[8235] | 53 | logger.info('%s, SUCCESS: %s' % (member,success)) |
---|
[7901] | 54 | |
---|
[8212] | 55 | if not 'COL1' in success: |
---|
[7901] | 56 | logger.info('%s requeried payment %s for %s without success' % (member,context.getId(),student_id)) |
---|
| 57 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
| 58 | |
---|
| 59 | success = request.get('SUCCESS').split('&') |
---|
| 60 | success_dict = dict([tuple(i.split('=')) for i in success]) |
---|
| 61 | |
---|
| 62 | pay_doc = context.getContent() |
---|
| 63 | |
---|
[8212] | 64 | oid = pay_doc['order_id'] |
---|
| 65 | col1 = success_dict['COL1'] |
---|
| 66 | |
---|
| 67 | if oid[len(oid)-8:len(oid)] != col1[len(col1)-8:len(col1)] and not ontest : |
---|
[8145] | 68 | logger.info('%s requeried payment %s for %s but wrong COL1 %s returned' % (member,context.getId(),student_id,success_dict['COL1'])) |
---|
[7901] | 69 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
| 70 | |
---|
[8131] | 71 | if float(pay_doc['amount']) != float(success_dict['TRANS_AMOUNT']) and not ontest : |
---|
[7901] | 72 | logger.info('%s requeried payment %s for %s but wrong amount %s returned' % (member,context.getId(),student_id,success_dict['TRANS_AMOUNT'])) |
---|
| 73 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|
| 74 | |
---|
[7902] | 75 | pd = {} |
---|
| 76 | pd['resp_desc'] = success_dict['TRANS_DESCR'].replace('%20',' ') |
---|
[7901] | 77 | pd['resp_pay_reference'] = success_dict['RECEIPT_NO'] |
---|
[7902] | 78 | pd['resp_code'] = 'ET' |
---|
[7901] | 79 | pd['resp_approved_amount'] = success_dict['TRANS_AMOUNT'] |
---|
[7902] | 80 | pd['status'] = 'paid' |
---|
[7901] | 81 | |
---|
| 82 | pay_doc.edit(mapping = pd) |
---|
| 83 | |
---|
| 84 | s_brain = context.students_catalog(id=student_id)[0] |
---|
| 85 | session = s_brain.session |
---|
| 86 | |
---|
[7902] | 87 | if pay_doc.category == 'schoolfee': |
---|
[8028] | 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'] |
---|
| 93 | next_verdict = next_info['next_verdict'] |
---|
| 94 | next_previous_verdict = next_info['next_previous_verdict'] |
---|
[7902] | 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) |
---|
[7901] | 113 | |
---|
| 114 | |
---|
[7902] | 115 | elif pay_doc.category == 'hostel_maintenance': |
---|
[7901] | 116 | |
---|
[7902] | 117 | ## callback function for accommodation_catalog method |
---|
| 118 | data={} |
---|
| 119 | data['acco_maint_date'] = pay_doc.date |
---|
| 120 | data['catkey'] =student_id + '|' + pay_doc.session_id |
---|
| 121 | data['acco_maint_fee'] = pay_doc.amount |
---|
| 122 | data['acco_maint_pay_id'] = context.getId() |
---|
| 123 | data['reservation_status'] = 'maintenance_fee_paid' |
---|
| 124 | context.accommodation_catalog.modifyRecord(**data) |
---|
[7901] | 125 | |
---|
[7902] | 126 | ## callback function for accommodation object method (deactivated since March 2011) |
---|
| 127 | #acco_info = context.getAccommodationInfo() |
---|
| 128 | #d = {} |
---|
| 129 | #d['acco_maint_date'] = pay_doc.date |
---|
| 130 | #d['acco_maint_fee'] = pay_doc.amount |
---|
| 131 | #d['acco_maint_pay_id'] = context.getId() |
---|
| 132 | #try: |
---|
| 133 | # acco_info['acco_doc'].edit(mapping=d) |
---|
| 134 | #except: |
---|
| 135 | # logger.info('%s requeried payment though maintenance already paid' % student_id) |
---|
| 136 | #try: |
---|
| 137 | # wftool.doActionFor(acco_info['acco'],'pay_maintenance_fee',dest_container=acco_info['acco']) |
---|
| 138 | #except: |
---|
| 139 | # logger.info('%s no workflow action pay_maintenance_fee' % student_id) |
---|
[7901] | 140 | |
---|
[7902] | 141 | elif pay_doc.category == 'acceptance': |
---|
| 142 | if context.getStudentReviewState() in ('admitted', 'objection_raised'): |
---|
| 143 | logger.info('%s paid acceptance fee' % (student_id)) |
---|
| 144 | current = DateTime.DateTime() |
---|
| 145 | wf = context.portal_workflow |
---|
| 146 | info = context.getClearanceInfo() |
---|
| 147 | wftool.doActionFor(student,'enter_clearance_pin') |
---|
| 148 | context.waeup_tool.changeWorkflowState(info['clear'], 'opened') |
---|
| 149 | context.waeup_tool.changeWorkflowState(info['app'], 'closed') |
---|
| 150 | dc = {} |
---|
| 151 | app_doc = info['app_doc'] |
---|
| 152 | #dc['clr_ac_pin'] = pay_doc.order_id |
---|
| 153 | dc['clr_ac_date'] = current |
---|
| 154 | dc['entry_date'] = current |
---|
| 155 | info['clear_doc'].edit(mapping = dc) |
---|
| 156 | if info['penalty']: |
---|
| 157 | logger.info('%s started late clearance' % (info['id'])) |
---|
| 158 | #return redirect("%s/clearance_edit_form" % info['clear'].absolute_url()) |
---|
[7901] | 159 | |
---|
[7902] | 160 | logger.info('%s received valid callback' % student_id) |
---|
[7901] | 161 | |
---|
| 162 | #review_state = wftool.getInfoFor(context,'review_state',None) |
---|
| 163 | #if review_state == 'opened': |
---|
| 164 | # wftool.doActionFor(context,'close') |
---|
| 165 | context.waeup_tool.changeWorkflowState(context, 'closed') |
---|
| 166 | |
---|
| 167 | return request.RESPONSE.redirect("%s/waeup_document_view" % context.absolute_url()) |
---|