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 1758 2007-05-08 20:43:37Z joachim $ |
---|
11 | """ |
---|
12 | pay online |
---|
13 | """ |
---|
14 | import logging |
---|
15 | from urllib import urlencode |
---|
16 | logger = logging.getLogger('Skins.pay_by_sc') |
---|
17 | import DateTime |
---|
18 | try: |
---|
19 | from Products.zdb import set_trace |
---|
20 | except: |
---|
21 | def set_trace(): |
---|
22 | pass |
---|
23 | |
---|
24 | if context.portal_membership.isAnonymousUser(): |
---|
25 | return None |
---|
26 | |
---|
27 | lt = context.portal_layouts |
---|
28 | request = context.REQUEST |
---|
29 | students = context.portal_url.getPortalObject().campus.students |
---|
30 | student_id = context.getStudentId() |
---|
31 | if student_id is None: |
---|
32 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
33 | |
---|
34 | student = getattr(students,student_id) |
---|
35 | s_brain = context.students_catalog(id=student_id)[0] |
---|
36 | session = s_brain.session |
---|
37 | next_session, next_session_str = context.getNextSessionId(session) |
---|
38 | amount,description = context.getSchoolFee(s_brain.faculty) |
---|
39 | validate = request.has_key("cpsdocument_create_button") |
---|
40 | res,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 | ) |
---|
49 | if 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 | ) |
---|
57 | elif 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 | ) |
---|
64 | elif psm == 'valid': |
---|
65 | pass |
---|
66 | if "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') |
---|
73 | else: |
---|
74 | payments = getattr(student,'payments') |
---|
75 | #from Products.zdb import set_trace; set_trace() |
---|
76 | info = {} |
---|
77 | order_id = ds.get('pin_n') |
---|
78 | p_id = "p%s" % order_id |
---|
79 | if not hasattr(payments,p_id): |
---|
80 | now = DateTime.DateTime() |
---|
81 | info['date'] = now |
---|
82 | info['amount'] = "n/a" |
---|
83 | pin = info['order_id'] = "%s__%s" % (ds.get('pin'),next_session) |
---|
84 | info['type_code'] = "%s" % pin |
---|
85 | info['type_description'] = 'School Fee for Session %s' % next_session_str |
---|
86 | info['resp_code'] = "SC" |
---|
87 | info['resp_desc'] = "SC Payment Successful" |
---|
88 | payments.invokeFactory('Payment', p_id) |
---|
89 | payment = getattr(payments,p_id) |
---|
90 | wftool = context.portal_workflow |
---|
91 | wftool.doActionFor(payment,'open') |
---|
92 | payment.getContent().edit(mapping=info) |
---|
93 | wftool.doActionFor(payment,'close') |
---|
94 | if next_session == context.getSessionId(): |
---|
95 | wftool.doActionFor(student,'pay_school_fee') |
---|
96 | else: |
---|
97 | study_course = getattr(student,'study_course') |
---|
98 | wftool.doActionFor(study_course,'open') |
---|
99 | study_course_doc = study_course.getContent() |
---|
100 | next_level = "%s" % (int(s_brain.level) + 100) |
---|
101 | study_course_doc.edit(mapping= {'current_level': next_level, |
---|
102 | 'current_session': next_session,}) |
---|
103 | logger.info('%s paid school fee by scratch card' % student_id) |
---|
104 | else: |
---|
105 | logger.info('%s repeatedly paid school fee by scratch card' % student_id) |
---|
106 | url = "%s/payments" % (student.absolute_url()) |
---|
107 | request.RESPONSE.redirect(url) |
---|
108 | |
---|