source: WAeUP_SRP/base/skins/waeup_epayment/pay_by_sc.py @ 2454

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

rebuild getNextInfo.py completely
fetch session from portal properties.xml
change all scripts using getSessionId
remove StudentCourseResult? relevant code from event services
make pay_by_sc.py and interswitch_cb.py work (rebuild both)

  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1## Script (Python) "pay_by_sc"
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: pay_by_sc.py 2454 2007-10-27 21:53:04Z henrik $
11"""
12pay online
13"""
14import logging
15from urllib import urlencode
16logger = logging.getLogger('Skins.pay_by_sc')
17import DateTime
18try:
19    from Products.zdb import set_trace
20except:
21    def set_trace():
22        pass
23
24if context.portal_membership.isAnonymousUser():
25    return None
26wftool = context.portal_workflow
27lt = context.portal_layouts
28request = context.REQUEST
29students = context.portal_url.getPortalObject().campus.students
30student_id = context.getStudentId()
31if student_id is None:
32    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
33
34student = getattr(students,student_id)
35s_brain = context.students_catalog(id=student_id)[0]
36
37# session = s_brain.session
38# next_session, next_session_str = context.getNextSessionId(session)
39
40next_info = context.getNextInfo(s_brain)
41next_session_id = next_info['next_session_id']
42next_session_str = next_info['next_session_str']
43next_level_id = next_info['next_level_id']
44next_transition = next_info['next_transition']
45
46validate = request.has_key("cpsdocument_create_button")
47res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee',
48                      schema_id= 'payment',
49                      context=context,
50                      mapping=validate and request,
51                      ob={},
52                      layout_mode="create",
53                      formaction = "pay_by_sc",
54                      button = 'Pay',
55                      commit = False,
56                      )
57if psm == 'invalid':
58    psm = 'Please correct your errors!'
59    return context.pay_by_sc_form(rendered = res,
60                                 psm = psm,
61                                 mode = 'edit',
62                                 next_session_str = next_session_str,
63                                 ds = ds,
64                                 )
65elif psm == '':
66    return context.pay_by_sc_form(rendered = res,
67                                 psm = None,
68                                 mode = 'edit',
69                                 next_session_str = next_session_str,
70                                 ds = ds,
71                                 )
72elif psm == 'valid':
73    pass
74if "payments" not in student.objectIds():
75    student.invokeFactory('PaymentsFolder','payments')
76    payments = getattr(student,'payments')
77    d = {}
78    d['Title'] = 'Payments'
79    payments.getContent().edit(mapping=d)
80    wftool.doActionFor(payments,'open')
81else:
82    payments = getattr(student,'payments')
83#from Products.zdb import set_trace; set_trace()
84info = {}
85order_id = ds.get('pin_n')
86p_id = "p%s" % order_id
87pin = str(ds.get('pin'))
88try:
89    cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost
90except:
91    cost = "n/a"
92try:
93    x = float(cost)
94except:
95    cost = "n/a"
96
97if not hasattr(payments,p_id):
98    now = DateTime.DateTime()
99    info['date'] = now
100    info['amount'] = cost
101    pin = info['order_id'] = "%s" % (pin)
102    info['type_code'] = "%s" % pin
103    info['type_description'] = 'School Fee for Session %s' % next_session_str
104    info['resp_code'] = "SC"
105    info['resp_desc'] = "SC Payment Successful"
106    payments.invokeFactory('Payment', p_id)
107    payment = getattr(payments,p_id)
108    wftool = context.portal_workflow
109    wftool.doActionFor(payment,'open')
110    payment.getContent().edit(mapping=info)
111    wftool.doActionFor(payment,'close')
112
113    study_course = getattr(student,'study_course')
114    study_course.getContent().edit(mapping= {'current_level': next_level_id,
115                                             'current_session': next_session_id,})
116    if next_transition:
117        wftool.doActionFor(student,next_transition)   
118   
119    #if next_session == context.getSessionId()[-2:]:
120    #    wftool.doActionFor(student,'pay_school_fee')
121    #else:
122    #    study_course = getattr(student,'study_course')
123    #    #wftool.doActionFor(study_course,'open')
124    #    study_course_doc = study_course.getContent()
125    #    next_level = "%s" % (int(s_brain.level) + 100)
126    #    study_course_doc.edit(mapping= {'current_level': next_level,
127    #                                    'current_session': next_session,})
128   
129    logger.info('%s paid school fee by scratch card' % student_id)
130else:
131    logger.info('%s repeatedly paid school fee by scratch card' % student_id)
132url = "%s/payments" % (student.absolute_url())
133request.RESPONSE.redirect(url)
134
Note: See TracBrowser for help on using the repository browser.