source: WAeUP_SRP/trunk_not_used/skins/waeup_epayment/pay_by_sc.py @ 2576

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

payment conditions fixed

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