source: WAeUP_SRP/branches/regebro-noskins/skins/waeup_epayment/pay_by_sc.py @ 9817

Last change on this file since 9817 was 1390, checked in by joachim, 18 years ago

check for mulitple invocation (in custom)

  • Property svn:keywords set to Id
File size: 3.0 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 1390 2007-02-05 09:02:07Z joachim $
11"""
12pay online
13"""
14import logging
15from urllib import urlencode
16logger = logging.getLogger('EPayment.PayBySC')
17import DateTime
18
19if context.portal_membership.isAnonymousUser():
20    return None
21
22lt = context.portal_layouts
23request = context.REQUEST
24students = context.portal_url.getPortalObject().campus.students
25student_id = context.getStudentId()
26if student_id is None:
27    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
28
29student = getattr(students,student_id)
30sbrain = context.students_catalog(id=student_id)[0]
31amount,description = context.getSchoolFee(sbrain.faculty)
32
33validate = request.has_key("cpsdocument_create_button")
34res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee',
35                      schema_id= 'payment',
36                      context=context,
37                      mapping=validate and request,
38                      ob={},
39                      layout_mode="create",
40                      formaction = "pay_by_sc",
41                      button = 'Pay'
42                      )
43if psm == 'invalid':
44    psm = 'Please correct your errors!'
45    return context.pay_by_sc_form(rendered = res,
46                                 psm = psm,
47                                 mode = 'edit',
48                                 ds = ds,
49                                 )
50elif psm == '':
51    return context.pay_by_sc_form(rendered = res,
52                                 psm = None,
53                                 mode = 'edit',
54                                 ds = ds,
55                                 )
56elif psm == 'valid':
57    pass
58if "payments" not in student.objectIds():
59    student.invokeFactory('PaymentsFolder','payments')
60    payments = getattr(student,'payments')
61    d = {}
62    d['Title'] = 'Payments'
63    payments.getContent().edit(mapping=d)
64    wftool.doActionFor(payments,'open')
65else:
66    payments = getattr(student,'payments')
67#from Products.zdb import set_trace; set_trace()
68info = {}
69order_id = ds.get('pin_n')
70p_id = "p%s" % order_id
71if not hasattr(payments,p_id):
72    now = DateTime.DateTime()
73    info['date'] = now
74    info['amount'] = "n/a"
75    pin = info['order_id'] = ds.get('pin')
76    info['type_code'] = "%s" % pin
77    info['type_description'] = 'School Fee for Session 2006/2007'
78    info['resp_code'] = "SC"
79    info['resp_desc'] = "SC Payment Successful"
80    payments.invokeFactory('Payment', p_id)
81    payment = getattr(payments,p_id)
82    wftool = context.portal_workflow
83    wftool.doActionFor(payment,'open')
84    payment.getContent().edit(mapping=info)
85    wftool.doActionFor(payment,'close')
86    wftool.doActionFor(student,'pay_school_fee')
87    logger.info('"%s", "paid school fee by scratch card"' % student_id)
88else:
89    logger.info('"%s", "repeatedly paid school fee by scratch card"' % student_id)
90url = "%s/payments" % (student.absolute_url())
91request.RESPONSE.redirect(url)
92
Note: See TracBrowser for help on using the repository browser.