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 1376 2007-01-30 16:53:16Z joachim $ |
---|
11 | """ |
---|
12 | pay online |
---|
13 | """ |
---|
14 | import logging |
---|
15 | from urllib import urlencode |
---|
16 | logger = logging.getLogger('EPayment.PayBySC') |
---|
17 | import DateTime |
---|
18 | |
---|
19 | if context.portal_membership.isAnonymousUser(): |
---|
20 | return None |
---|
21 | |
---|
22 | lt = context.portal_layouts |
---|
23 | request = context.REQUEST |
---|
24 | students = context.portal_url.getPortalObject().campus.students |
---|
25 | student_id = context.getStudentId() |
---|
26 | if student_id is None: |
---|
27 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
28 | |
---|
29 | student = getattr(students,student_id) |
---|
30 | sbrain = context.students_catalog(id=student_id)[0] |
---|
31 | amount,description = context.getSchoolFee(sbrain.faculty) |
---|
32 | |
---|
33 | validate = request.has_key("cpsdocument_create_button") |
---|
34 | res,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 | ) |
---|
43 | if 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 | ) |
---|
50 | elif psm == '': |
---|
51 | return context.pay_by_sc_form(rendered = res, |
---|
52 | psm = None, |
---|
53 | mode = 'edit', |
---|
54 | ds = ds, |
---|
55 | ) |
---|
56 | elif psm == 'valid': |
---|
57 | pass |
---|
58 | if "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') |
---|
65 | else: |
---|
66 | payments = getattr(student,'payments') |
---|
67 | #from Products.zdb import set_trace; set_trace() |
---|
68 | info = {} |
---|
69 | order_id = ds.get('pin_n') |
---|
70 | p_id = "p%s" % order_id |
---|
71 | now = DateTime.DateTime() |
---|
72 | info['date'] = now |
---|
73 | info['amount'] = "n/a" |
---|
74 | pin = info['order_id'] = ds.get('pin') |
---|
75 | info['type_code'] = "%s" % pin |
---|
76 | info['type_description'] = 'School Fee for Session 2006/2007' |
---|
77 | info['resp_code'] = "SC" |
---|
78 | info['resp_desc'] = "SC Payment Successful" |
---|
79 | payments.invokeFactory('Payment', p_id) |
---|
80 | payment = getattr(payments,p_id) |
---|
81 | wftool = context.portal_workflow |
---|
82 | wftool.doActionFor(payment,'open') |
---|
83 | payment.getContent().edit(mapping=info) |
---|
84 | wftool.doActionFor(payment,'close') |
---|
85 | wftool.doActionFor(student,'pay_school_fee') |
---|
86 | logger.info('"%s", "paid school fee by scratch card"' % student_id) |
---|
87 | url = "%s/payments" % (student.absolute_url()) |
---|
88 | request.RESPONSE.redirect(url) |
---|
89 | |
---|