1 | ## Script (Python) "request_gown" |
---|
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_gown.py 3256 2008-02-29 06:51:46Z henrik $ |
---|
11 | """ |
---|
12 | pay online |
---|
13 | """ |
---|
14 | import logging |
---|
15 | from urllib import urlencode |
---|
16 | logger = logging.getLogger('Skins.request_gown') |
---|
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 = context.getSessionId() |
---|
38 | |
---|
39 | validate = request.has_key("cpsdocument_create_button") |
---|
40 | res,psm,ds = lt.renderLayout(layout_id= 'student_gown', |
---|
41 | schema_id= 'payment', |
---|
42 | context=context, |
---|
43 | mapping=validate and request, |
---|
44 | ob={}, |
---|
45 | layout_mode="create", |
---|
46 | formaction = "request_gown", |
---|
47 | button = 'Pay', |
---|
48 | commit = False, |
---|
49 | ) |
---|
50 | if psm == 'invalid': |
---|
51 | psm = 'Please correct your errors!' |
---|
52 | return context.request_gown_form(rendered = res, |
---|
53 | psm = psm, |
---|
54 | mode = 'edit', |
---|
55 | #session_str = session[1], |
---|
56 | ds = ds, |
---|
57 | ) |
---|
58 | elif psm == '': |
---|
59 | return context.request_gown_form(rendered = res, |
---|
60 | psm = None, |
---|
61 | mode = 'edit', |
---|
62 | #session_str = session[1], |
---|
63 | ds = ds, |
---|
64 | ) |
---|
65 | elif psm == 'valid': |
---|
66 | pass |
---|
67 | if "payments" not in student.objectIds(): |
---|
68 | student.invokeFactory('PaymentsFolder','payments') |
---|
69 | payments = getattr(student,'payments') |
---|
70 | d = {} |
---|
71 | d['Title'] = 'Payments' |
---|
72 | payments.getContent().edit(mapping=d) |
---|
73 | wftool.doActionFor(payments,'open') |
---|
74 | else: |
---|
75 | payments = getattr(student,'payments') |
---|
76 | #from Products.zdb import set_trace; set_trace() |
---|
77 | info = {} |
---|
78 | p_id = "p%s" % ds.get('pin_n') |
---|
79 | pin = str(ds.get('pin')) |
---|
80 | session = str(ds.get('session')) |
---|
81 | |
---|
82 | #from Products.zdb import set_trace; set_trace() |
---|
83 | |
---|
84 | try: |
---|
85 | cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost |
---|
86 | except: |
---|
87 | cost = "n/a" |
---|
88 | try: |
---|
89 | x = float(cost) |
---|
90 | except: |
---|
91 | cost = "n/a" |
---|
92 | |
---|
93 | if not hasattr(payments,p_id): |
---|
94 | now = DateTime.DateTime() |
---|
95 | info['date'] = now |
---|
96 | info['amount'] = cost |
---|
97 | pin = info['order_id'] = "%s" % pin |
---|
98 | #info['type_code'] = "%s" % pin #type_code is redundant and will be removed soon |
---|
99 | info['type_description'] = 'Gown Hire' |
---|
100 | info['type'] = 'sc' |
---|
101 | info['status'] = 'paid' |
---|
102 | #info['session_id'] = session[0] |
---|
103 | info['session_id'] = session |
---|
104 | info['item'] = '' |
---|
105 | info['category'] = 'gown' |
---|
106 | info['resp_code'] = "SC" |
---|
107 | info['resp_desc'] = "SC Payment Successful" |
---|
108 | payments.invokeFactory('Payment', p_id) |
---|
109 | payment = getattr(payments,p_id) |
---|
110 | wftool = context.portal_workflow |
---|
111 | wftool.doActionFor(payment,'open') |
---|
112 | payment.getContent().edit(mapping=info) |
---|
113 | wftool.doActionFor(payment,'close') |
---|
114 | |
---|
115 | |
---|
116 | logger.info('%s paid gown by scratch card' % student_id) |
---|
117 | else: |
---|
118 | logger.info('%s repeatedly paid gown by scratch card' % student_id) |
---|
119 | url = "%s/payments" % (student.absolute_url()) |
---|
120 | request.RESPONSE.redirect(url) |
---|
121 | |
---|