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