1 | ## Script (Python) "getPaymentsFolderInfo" |
---|
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 2761 2007-11-26 09:45:58Z henrik $ |
---|
11 | """ |
---|
12 | Info for the PaymentsFolder |
---|
13 | try: |
---|
14 | from Products.zdb import set_trace |
---|
15 | except: |
---|
16 | def set_trace(): |
---|
17 | pass |
---|
18 | """ |
---|
19 | |
---|
20 | mtool = context.portal_membership |
---|
21 | member = mtool.getAuthenticatedMember() |
---|
22 | if mtool.isAnonymousUser(): |
---|
23 | return None |
---|
24 | |
---|
25 | #import logging |
---|
26 | #logger = logging.getLogger('Skins.getPaymentsFolderInfo') |
---|
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 |
---|
35 | |
---|
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()) |
---|
42 | student = getattr(students,student_id) |
---|
43 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
44 | #context['updatePayments']() |
---|
45 | payments = [] |
---|
46 | |
---|
47 | info = {} |
---|
48 | is_so = info['is_so'] = context.isSectionOfficer() |
---|
49 | is_student = info['is_student'] = context.isStudent() |
---|
50 | info['student_name'] = student_record.name |
---|
51 | info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx" |
---|
52 | review_state = info['review_state'] = student_record.review_state |
---|
53 | parttime = student_record.mode and student_record.mode.endswith('_pt') |
---|
54 | fulltime = student_record.mode and student_record.mode.endswith('_ft') |
---|
55 | |
---|
56 | #if review_state == 'cleared_and_validated' or (parttime and review_state == 'returning'): |
---|
57 | # online_payment = True |
---|
58 | #elif fulltime and review_state == 'returning': |
---|
59 | # sc_payment = True |
---|
60 | |
---|
61 | session = student_record.session |
---|
62 | next_info = context.getNextInfo(student_record) |
---|
63 | info['next_session'] = next_info['next_session_id'] |
---|
64 | info['next_session_str'] = next_info['next_session_str'] |
---|
65 | info['payment_method'] = "" |
---|
66 | info['reasons'] = next_info['reasons'] |
---|
67 | |
---|
68 | if review_state == 'cleared_and_validated' and session != '07': |
---|
69 | info['payment_method'] = "online_payment" |
---|
70 | #elif review_state == 'cleared_and_validated' and session == '07': |
---|
71 | # info['payment_method'] = "sc_payment" |
---|
72 | elif review_state == 'returning' and info['next_session'] != session: |
---|
73 | info['payment_method'] = "sc_payment" |
---|
74 | info['prod_id'] = '61' |
---|
75 | |
---|
76 | info['student_name'] = student_record.name |
---|
77 | payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id) |
---|
78 | sos = context.portal_catalog(container_path=payments_path) |
---|
79 | info['is_so'] = is_so |
---|
80 | |
---|
81 | for so in sos: |
---|
82 | row = {} |
---|
83 | row['id'] = so.getId |
---|
84 | row['title'] = so.Title |
---|
85 | url = row['url'] = "%s/%s" % (payments_path,so.getId) |
---|
86 | so_doc = context.restrictedTraverse(url,default=None).getContent() |
---|
87 | row['type'] = so.portal_type |
---|
88 | review_state = row['review_state'] = so.review_state |
---|
89 | if so_doc.type_description.startswith('School Fee'): |
---|
90 | row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] == 'cleared_and_validated' |
---|
91 | else: |
---|
92 | row['is_approvable'] = is_so and (review_state == "opened") |
---|
93 | row['is_requeryable'] = False |
---|
94 | #set_trace() |
---|
95 | row['resp_desc'] = getattr(so_doc,'resp_desc','no response') |
---|
96 | row['trans_ref'] = getattr(so_doc,'order_id','') |
---|
97 | if so_doc.type_description.startswith('School Fee'): |
---|
98 | if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated',) and \ |
---|
99 | hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin',): |
---|
100 | row['is_requeryable'] = True |
---|
101 | row['callback_url'] = "%s/payments/%s/interswitch_cb" % (student.absolute_url(), |
---|
102 | so.getId) |
---|
103 | href = '%(query_url)s' % info |
---|
104 | href += '?transRef=%(trans_ref)s' % row |
---|
105 | href += '&prodID=%(prod_id)s' % info |
---|
106 | href += '&redirectURL=%(callback_url)s' % row |
---|
107 | row['href'] = href |
---|
108 | if (review_state == "closed") and so_doc.resp_code in ('SC','00','AP','IP',): |
---|
109 | row['confirmed'] = 'active' |
---|
110 | else: |
---|
111 | row['confirmed'] = 'unsuccessful' |
---|
112 | row['is_editable'] = is_so and (row['confirmed'] == 'active') |
---|
113 | |
---|
114 | payments.append(row) |
---|
115 | |
---|
116 | payments.sort(cmp_id) |
---|
117 | info['payments'] = payments |
---|
118 | return info |
---|
119 | |
---|