source: WAeUP_SRP/trunk/skins/waeup_epayment/request_gown.py @ 3739

Last change on this file since 3739 was 3736, checked in by Henrik Bettermann, 16 years ago

implement gown hiring

File size: 3.5 KB
Line 
1## Script (Python) "request_gown"
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: request_gown.py 3256 2008-02-29 06:51:46Z henrik $
11"""
12pay online
13"""
14import logging
15from urllib import urlencode
16logger = logging.getLogger('Skins.request_gown')
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)
36session = context.getSessionId()
37
38validate = request.has_key("cpsdocument_create_button")
39res,psm,ds = lt.renderLayout(layout_id= 'student_gown',
40                      schema_id= 'payment',
41                      context=context,
42                      mapping=validate and request,
43                      ob={},
44                      layout_mode="create",
45                      formaction = "request_gown",
46                      button = 'Pay',
47                      commit = False,
48                      )
49if psm == 'invalid':
50    psm = 'Please correct your errors!'
51    return context.request_gown_form(rendered = res,
52                                 psm = psm,
53                                 mode = 'edit',
54                                 #session_str = session[1],
55                                 ds = ds,
56                                 )
57elif psm == '':
58    return context.request_gown_form(rendered = res,
59                                 psm = None,
60                                 mode = 'edit',
61                                 #session_str = session[1],
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 = {}
77p_id = "p%s" % ds.get('pin_n')
78pin = str(ds.get('pin'))
79try:
80    cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost
81except:
82    cost = "n/a"
83try:
84    x = float(cost)
85except:
86    cost = "n/a"
87
88if not hasattr(payments,p_id):
89    now = DateTime.DateTime()
90    info['date'] = now
91    info['amount'] = cost
92    pin = info['order_id'] = "%s" % pin
93    #info['type_code'] = "%s" % pin  #type_code is redundant and will be removed soon
94    info['type_description'] = 'Gown Hire'
95    info['type'] = 'sc'
96    info['status'] = 'paid'
97    info['session_id'] = session[0]
98    info['item'] = ''
99    info['category'] = 'gown'
100    info['resp_code'] = "SC"
101    info['resp_desc'] = "SC Payment Successful"
102    payments.invokeFactory('Payment', p_id)
103    payment = getattr(payments,p_id)
104    wftool = context.portal_workflow
105    wftool.doActionFor(payment,'open')
106    payment.getContent().edit(mapping=info)
107    wftool.doActionFor(payment,'close')
108
109
110    logger.info('%s paid gown by scratch card' % student_id)
111else:
112    logger.info('%s repeatedly paid gown by scratch card' % student_id)
113url = "%s/payments" % (student.absolute_url())
114request.RESPONSE.redirect(url)
115
Note: See TracBrowser for help on using the repository browser.