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