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

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

see #493

  • Property svn:keywords set to Id
File size: 4.5 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 3256 2008-02-29 06:51:46Z 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)
35student_record = context.students_catalog.getRecordByKey(student_id)
36
37# session = student_record.session
38# next_session, next_session_str = context.getNextSessionId(session)
39
40next_info = context.getNextInfo(student_record)
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']
45next_verdict = next_info['next_verdict']
46next_previous_verdict = next_info['next_previous_verdict']
47
48validate = request.has_key("cpsdocument_create_button")
49res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee',
50                      schema_id= 'payment',
51                      context=context,
52                      mapping=validate and request,
53                      ob={},
54                      layout_mode="create",
55                      formaction = "pay_by_sc",
56                      button = 'Pay',
57                      commit = False,
58                      )
59if psm == 'invalid':
60    psm = 'Please correct your errors!'
61    return context.pay_by_sc_form(rendered = res,
62                                 psm = psm,
63                                 mode = 'edit',
64                                 next_session_str = next_session_str,
65                                 ds = ds,
66                                 )
67elif psm == '':
68    return context.pay_by_sc_form(rendered = res,
69                                 psm = None,
70                                 mode = 'edit',
71                                 next_session_str = next_session_str,
72                                 ds = ds,
73                                 )
74elif psm == 'valid':
75    pass
76if "payments" not in student.objectIds():
77    student.invokeFactory('PaymentsFolder','payments')
78    payments = getattr(student,'payments')
79    d = {}
80    d['Title'] = 'Payments'
81    payments.getContent().edit(mapping=d)
82    wftool.doActionFor(payments,'open')
83else:
84    payments = getattr(student,'payments')
85#from Products.zdb import set_trace; set_trace()
86info = {}
87p_id = "p%s" % ds.get('pin_n')
88pin = str(ds.get('pin'))
89try:
90    cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost
91except:
92    cost = "n/a"
93try:
94    x = float(cost)
95except:
96    cost = "n/a"
97
98if not hasattr(payments,p_id):
99    now = DateTime.DateTime()
100    info['date'] = now
101    info['amount'] = cost
102    pin = info['order_id'] = "%s" % pin
103    #info['type_code'] = "%s" % pin  #type_code is redundant and will be removed soon
104    info['type_description'] = 'School Fee for Session %s' % next_session_str
105    info['type'] = 'sc'
106    info['status'] = 'paid'
107    info['session_id'] = next_session_id
108    info['item'] = student_record.course
109    info['category'] = 'schoolfee'
110    info['resp_code'] = "SC"
111    info['resp_desc'] = "SC Payment Successful"
112    payments.invokeFactory('Payment', p_id)
113    payment = getattr(payments,p_id)
114    wftool = context.portal_workflow
115    wftool.doActionFor(payment,'open')
116    payment.getContent().edit(mapping=info)
117    wftool.doActionFor(payment,'close')
118
119    study_course = getattr(student,'study_course')
120    try:
121        wftool.doActionFor(study_course,'open')
122    except:
123        pass
124    study_course.getContent().edit(mapping= {'current_level': next_level_id,
125                                             'current_session': next_session_id,
126                                             'current_verdict': next_verdict,
127                                             'previous_verdict': next_previous_verdict,
128                                             })
129    if next_transition:
130        wftool.doActionFor(student,next_transition)
131
132    logger.info('%s paid school fee by scratch card' % student_id)
133else:
134    logger.info('%s repeatedly paid school fee by scratch card' % student_id)
135url = "%s/payments" % (student.absolute_url())
136request.RESPONSE.redirect(url)
137
Note: See TracBrowser for help on using the repository browser.