1 | ## Script (Python) "request_transfer" |
---|
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: request_transfer.py 1327 2007-01-19 18:14:23Z joachim $ |
---|
11 | """ |
---|
12 | pay online |
---|
13 | """ |
---|
14 | import logging |
---|
15 | from urllib import urlencode |
---|
16 | logger = logging.getLogger('EPayment.') |
---|
17 | import DateTime |
---|
18 | lt = context.portal_layouts |
---|
19 | request = context.REQUEST |
---|
20 | students = context.portal_url.getPortalObject().campus.students |
---|
21 | |
---|
22 | student_id = context.getStudentId() |
---|
23 | if student_id is None: |
---|
24 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
25 | |
---|
26 | student = getattr(students,student_id) |
---|
27 | sbrain = context.students_catalog(id=student_id)[0] |
---|
28 | payments = getattr(student,'payments').objectIds() |
---|
29 | payed = False |
---|
30 | for payment in payments: |
---|
31 | if payment.startswith('transfer'): |
---|
32 | payed = True |
---|
33 | break |
---|
34 | if payed: |
---|
35 | return context.request_transfer_form(rendered = None, |
---|
36 | psm = None, |
---|
37 | payed = True, |
---|
38 | ) |
---|
39 | |
---|
40 | validate = request.has_key("cpsdocument_create_button") |
---|
41 | res,psm,ds = lt.renderLayout(layout_id= 'student_transfer', |
---|
42 | schema_id= 'epayment', |
---|
43 | context=context, |
---|
44 | mapping=validate and request, |
---|
45 | ob={}, |
---|
46 | layout_mode="create", |
---|
47 | formaction = "request_transfer", |
---|
48 | button = 'Start' |
---|
49 | ) |
---|
50 | if psm == 'invalid': |
---|
51 | psm = 'Please correct your errors!' |
---|
52 | return context.request_transfer_form(rendered = res, |
---|
53 | psm = psm, |
---|
54 | mode = 'edit', |
---|
55 | ds = ds, |
---|
56 | ) |
---|
57 | elif psm == '': |
---|
58 | return context.request_transfer_form(rendered = res, |
---|
59 | psm = None, |
---|
60 | mode = 'edit', |
---|
61 | ds = ds, |
---|
62 | ) |
---|
63 | elif psm == 'valid': |
---|
64 | pass |
---|
65 | if "payments" not in student.objectIds(): |
---|
66 | student.invokeFactory('PaymentsFolder','payments') |
---|
67 | payments = getattr(student,'payments') |
---|
68 | d = {} |
---|
69 | d['Title'] = 'Payments' |
---|
70 | payments.getContent().edit(mapping=d) |
---|
71 | wftool.doActionFor(payments,'open') |
---|
72 | else: |
---|
73 | payments = getattr(student,'payments') |
---|
74 | #from Products.zdb import set_trace; set_trace() |
---|
75 | info = {} |
---|
76 | order_id = ds.get('pin_n') |
---|
77 | p_id = "transfer_%s" % order_id |
---|
78 | now = DateTime.DateTime() |
---|
79 | info['date'] = now |
---|
80 | info['amount'] = "n/a" |
---|
81 | pin = info['order_id'] = ds.get('pin') |
---|
82 | info['type_code'] = "transfer_%s" % pin |
---|
83 | info['type_description'] = 'Transfer Form SC %s' % pin |
---|
84 | payments.invokeFactory('Payment', p_id) |
---|
85 | payment = getattr(payments,p_id) |
---|
86 | wftool = context.portal_workflow |
---|
87 | wftool.doActionFor(payment,'open') |
---|
88 | payment.getContent().edit(mapping=info) |
---|
89 | wftool.doActionFor(payment,'close') |
---|
90 | return context.request_transfer_form(rendered = None, |
---|
91 | psm = None, |
---|
92 | payed = True, |
---|
93 | ) |
---|
94 | |
---|