source: WAeUP_SRP/trunk/skins/waeup_epayment/getPaymentsFolderInfo.py @ 2162

Last change on this file since 2162 was 2154, checked in by Henrik Bettermann, 17 years ago

the logic was wrong

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