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