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 2664 2007-11-15 14:35:05Z henrik $ |
---|
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 | wftool = context.portal_workflow |
---|
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 | |
---|
37 | # session = s_brain.session |
---|
38 | # next_session, next_session_str = context.getNextSessionId(session) |
---|
39 | |
---|
40 | next_info = context.getNextInfo(s_brain) |
---|
41 | next_session_id = next_info['next_session_id'] |
---|
42 | next_session_str = next_info['next_session_str'] |
---|
43 | next_level_id = next_info['next_level_id'] |
---|
44 | next_transition = next_info['next_transition'] |
---|
45 | next_verdict = next_info['next_verdict'] |
---|
46 | |
---|
47 | validate = request.has_key("cpsdocument_create_button") |
---|
48 | res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee', |
---|
49 | schema_id= 'payment', |
---|
50 | context=context, |
---|
51 | mapping=validate and request, |
---|
52 | ob={}, |
---|
53 | layout_mode="create", |
---|
54 | formaction = "pay_by_sc", |
---|
55 | button = 'Pay', |
---|
56 | commit = False, |
---|
57 | ) |
---|
58 | if psm == 'invalid': |
---|
59 | psm = 'Please correct your errors!' |
---|
60 | return context.pay_by_sc_form(rendered = res, |
---|
61 | psm = psm, |
---|
62 | mode = 'edit', |
---|
63 | next_session_str = next_session_str, |
---|
64 | ds = ds, |
---|
65 | ) |
---|
66 | elif psm == '': |
---|
67 | return context.pay_by_sc_form(rendered = res, |
---|
68 | psm = None, |
---|
69 | mode = 'edit', |
---|
70 | next_session_str = next_session_str, |
---|
71 | ds = ds, |
---|
72 | ) |
---|
73 | elif psm == 'valid': |
---|
74 | pass |
---|
75 | if "payments" not in student.objectIds(): |
---|
76 | student.invokeFactory('PaymentsFolder','payments') |
---|
77 | payments = getattr(student,'payments') |
---|
78 | d = {} |
---|
79 | d['Title'] = 'Payments' |
---|
80 | payments.getContent().edit(mapping=d) |
---|
81 | wftool.doActionFor(payments,'open') |
---|
82 | else: |
---|
83 | payments = getattr(student,'payments') |
---|
84 | #from Products.zdb import set_trace; set_trace() |
---|
85 | info = {} |
---|
86 | p_id = "p%s" % ds.get('pin_n') |
---|
87 | pin = str(ds.get('pin')) |
---|
88 | try: |
---|
89 | cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost |
---|
90 | except: |
---|
91 | cost = "n/a" |
---|
92 | try: |
---|
93 | x = float(cost) |
---|
94 | except: |
---|
95 | cost = "n/a" |
---|
96 | |
---|
97 | if not hasattr(payments,p_id): |
---|
98 | now = DateTime.DateTime() |
---|
99 | info['date'] = now |
---|
100 | info['amount'] = cost |
---|
101 | pin = info['order_id'] = "%s" % pin |
---|
102 | info['type_code'] = "%s" % pin #type_code is redundant and will be removed soon |
---|
103 | info['type_description'] = 'School Fee for Session %s' % next_session_str |
---|
104 | info['resp_code'] = "SC" |
---|
105 | info['resp_desc'] = "SC Payment Successful" |
---|
106 | payments.invokeFactory('Payment', p_id) |
---|
107 | payment = getattr(payments,p_id) |
---|
108 | wftool = context.portal_workflow |
---|
109 | wftool.doActionFor(payment,'open') |
---|
110 | payment.getContent().edit(mapping=info) |
---|
111 | wftool.doActionFor(payment,'close') |
---|
112 | |
---|
113 | study_course = getattr(student,'study_course') |
---|
114 | try: |
---|
115 | wftool.doActionFor(study_course,'open') |
---|
116 | except: |
---|
117 | pass |
---|
118 | verdict = s_brain.verdict |
---|
119 | study_course.getContent().edit(mapping= {'current_level': next_level_id, |
---|
120 | 'current_session': next_session_id, |
---|
121 | 'current_verdict': next_verdict, |
---|
122 | 'previous_verdict': verdict, |
---|
123 | }) |
---|
124 | if next_transition: |
---|
125 | wftool.doActionFor(student,next_transition) |
---|
126 | |
---|
127 | logger.info('%s paid school fee by scratch card' % student_id) |
---|
128 | else: |
---|
129 | logger.info('%s repeatedly paid school fee by scratch card' % student_id) |
---|
130 | url = "%s/payments" % (student.absolute_url()) |
---|
131 | request.RESPONSE.redirect(url) |
---|
132 | |
---|