source: WAeUP_SRP/branches/joachim-azax-branch/skins/waeup_epayment/pay_by_sc.py @ 16827

Last change on this file since 16827 was 1856, checked in by joachim, 17 years ago

aviod conflict errors (in custom)

  • Property svn:keywords set to Id
File size: 3.8 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 1856 2007-06-05 13:06:23Z joachim $
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
26
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]
36session = s_brain.session
37next_session, next_session_str = context.getNextSessionId(session)
38amount,description = context.getSchoolFee(s_brain.faculty)
39validate = request.has_key("cpsdocument_create_button")
40res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee',
41                      schema_id= 'payment',
42                      context=context,
43                      mapping=validate and request,
44                      ob={},
45                      layout_mode="create",
46                      formaction = "pay_by_sc",
47                      button = 'Pay',
48                      commit = False,
49                      )
50if psm == 'invalid':
51    psm = 'Please correct your errors!'
52    return context.pay_by_sc_form(rendered = res,
53                                 psm = psm,
54                                 mode = 'edit',
55                                 next_session_str = next_session_str,
56                                 ds = ds,
57                                 )
58elif psm == '':
59    return context.pay_by_sc_form(rendered = res,
60                                 psm = None,
61                                 mode = 'edit',
62                                 next_session_str = next_session_str,
63                                 ds = ds,
64                                 )
65elif psm == 'valid':
66    pass
67if "payments" not in student.objectIds():
68    student.invokeFactory('PaymentsFolder','payments')
69    payments = getattr(student,'payments')
70    d = {}
71    d['Title'] = 'Payments'
72    payments.getContent().edit(mapping=d)
73    wftool.doActionFor(payments,'open')
74else:
75    payments = getattr(student,'payments')
76#from Products.zdb import set_trace; set_trace()
77info = {}
78order_id = ds.get('pin_n')
79p_id = "p%s" % order_id
80if not hasattr(payments,p_id):
81    now = DateTime.DateTime()
82    info['date'] = now
83    info['amount'] = "n/a"
84    pin = info['order_id'] = "%s" % (ds.get('pin'))
85    info['type_code'] = "%s" % pin
86    info['type_description'] = 'School Fee for Session %s' % next_session_str
87    info['resp_code'] = "SC"
88    info['resp_desc'] = "SC Payment Successful"
89    payments.invokeFactory('Payment', p_id)
90    payment = getattr(payments,p_id)
91    wftool = context.portal_workflow
92    wftool.doActionFor(payment,'open')
93    payment.getContent().edit(mapping=info)
94    wftool.doActionFor(payment,'close')
95    if next_session == context.getSessionId()[-2:]:
96        wftool.doActionFor(student,'pay_school_fee')
97    else:
98        study_course = getattr(student,'study_course')
99        #wftool.doActionFor(study_course,'open')
100        study_course_doc = study_course.getContent()
101        next_level = "%s" % (int(s_brain.level) + 100)
102        study_course_doc.edit(mapping= {'current_level': next_level,
103                                        'current_session': next_session,})
104    logger.info('%s paid school fee by scratch card' % student_id)
105else:
106    logger.info('%s repeatedly paid school fee by scratch card' % student_id)
107url = "%s/payments" % (student.absolute_url())
108request.RESPONSE.redirect(url)
109
Note: See TracBrowser for help on using the repository browser.