[1568] | 1 | ## Script (Python) "getPaymentsFolderInfo" |
---|
[1238] | 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: getPaymentsFolderInfo.py 2249 2007-09-17 06:49:57Z henrik $ |
---|
| 11 | """ |
---|
| 12 | Info for the PaymentsFolder |
---|
| 13 | """ |
---|
[1783] | 14 | |
---|
| 15 | mtool = context.portal_membership |
---|
| 16 | if mtool.isAnonymousUser(): |
---|
| 17 | return None |
---|
[1845] | 18 | try: |
---|
| 19 | from Products.zdb import set_trace |
---|
| 20 | except: |
---|
| 21 | def set_trace(): |
---|
| 22 | pass |
---|
[1783] | 23 | |
---|
| 24 | |
---|
[1568] | 25 | #import logging |
---|
| 26 | #logger = logging.getLogger('Skins.getPaymentsFolderInfo') |
---|
[1661] | 27 | def cmp_id(a,b): |
---|
| 28 | s1 = "%(id)s" % a |
---|
| 29 | s2 = "%(id)s" % b |
---|
| 30 | if s1 == s2: |
---|
| 31 | return 0 |
---|
| 32 | if s1 > s2: |
---|
| 33 | return 1 |
---|
| 34 | return -1 |
---|
[1568] | 35 | |
---|
[1238] | 36 | import DateTime |
---|
| 37 | request = context.REQUEST |
---|
| 38 | students = context.portal_url.getPortalObject().campus.students |
---|
| 39 | student_id = context.getStudentId() |
---|
| 40 | if student_id is None: |
---|
| 41 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
[1938] | 42 | student = getattr(students,student_id) |
---|
[1338] | 43 | s_brain = context.students_catalog(id = student_id)[0] |
---|
[1427] | 44 | |
---|
[1238] | 45 | payments = [] |
---|
[1283] | 46 | #from Products.zdb import set_trace;set_trace() |
---|
[1427] | 47 | |
---|
[1238] | 48 | info = {} |
---|
| 49 | is_so = info['is_so'] = context.isSectionOfficer() |
---|
[2151] | 50 | is_student = info['is_student'] = context.isStudent() |
---|
| 51 | info['student_name'] = s_brain.name |
---|
[1946] | 52 | info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx" |
---|
[2151] | 53 | review_state = info['review_state'] = s_brain.review_state |
---|
[2153] | 54 | parttime = s_brain.mode.endswith('_pt') |
---|
| 55 | fulltime = s_brain.mode.endswith('_ft') |
---|
| 56 | online_payment = False |
---|
| 57 | sc_payment = False |
---|
[2249] | 58 | |
---|
| 59 | #if review_state == 'cleared_and_validated' or (parttime and review_state == 'returning'): |
---|
| 60 | # online_payment = True |
---|
| 61 | #elif fulltime and review_state == 'returning': |
---|
| 62 | # sc_payment = True |
---|
| 63 | |
---|
| 64 | if review_state == 'cleared_and_validated': |
---|
[2151] | 65 | online_payment = True |
---|
[2249] | 66 | elif review_state == 'returning': |
---|
[2153] | 67 | sc_payment = True |
---|
[2249] | 68 | |
---|
[2151] | 69 | info['online_payment'] = online_payment |
---|
[2153] | 70 | info['sc_payment'] = sc_payment |
---|
[2165] | 71 | info['prod_id'] = '61' |
---|
[1758] | 72 | session = s_brain.session |
---|
| 73 | info['next_session'], info['next_session_str'] = context.getNextSessionId(session) |
---|
[1427] | 74 | |
---|
[1238] | 75 | info['student_name'] = s_brain.name |
---|
[1427] | 76 | payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id) |
---|
| 77 | sos = context.portal_catalog(container_path=payments_path) |
---|
| 78 | info['is_so'] = is_so |
---|
| 79 | |
---|
| 80 | for so in sos: |
---|
| 81 | row = {} |
---|
| 82 | row['id'] = so.getId |
---|
| 83 | row['title'] = so.Title |
---|
| 84 | url = row['url'] = "%s/%s" % (payments_path,so.getId) |
---|
[1944] | 85 | so_doc = context.restrictedTraverse(url,default=None).getContent() |
---|
[1427] | 86 | row['type'] = so.portal_type |
---|
| 87 | review_state = row['review_state'] = so.review_state |
---|
[1944] | 88 | if so_doc.type_description.startswith('School Fee'): |
---|
[1427] | 89 | row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] == 'cleared_and_validated' |
---|
| 90 | else: |
---|
| 91 | row['is_approvable'] = is_so and (review_state == "opened") |
---|
[1938] | 92 | row['is_requeryable'] = False |
---|
[1944] | 93 | #set_trace() |
---|
| 94 | row['resp_desc'] = getattr(so_doc,'resp_desc','no response') |
---|
| 95 | row['trans_ref'] = getattr(so_doc,'order_id','') |
---|
| 96 | if so_doc.type_description.startswith('School Fee'): |
---|
[1952] | 97 | if review_state == 'opened' and info['review_state'] == 'cleared_and_validated' and hasattr(so_doc, 'order_id') and not so_doc.resp_code: |
---|
[1938] | 98 | row['is_requeryable'] = True |
---|
[1944] | 99 | row['callback_url'] = "%s/payments/%s/interswitch_cb" % (student.absolute_url(), |
---|
| 100 | so.getId) |
---|
| 101 | href = '%(query_url)s' % info |
---|
| 102 | href += '?transRef=%(trans_ref)s' % row |
---|
| 103 | href += '&prodID=%(prod_id)s' % info |
---|
| 104 | href += '&redirectURL=%(callback_url)s' % row |
---|
| 105 | row['href'] = href |
---|
| 106 | if (review_state == "closed") and so_doc.resp_code in ('SC','00','AP','IP',): |
---|
[1427] | 107 | row['confirmed'] = 'active' |
---|
| 108 | else: |
---|
[1431] | 109 | row['confirmed'] = 'unsuccessful' |
---|
[1427] | 110 | payments.append(row) |
---|
| 111 | |
---|
[1661] | 112 | payments.sort(cmp_id) |
---|
[1238] | 113 | info['payments'] = payments |
---|
| 114 | return info |
---|
[1431] | 115 | |
---|