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