1 | ## $Id: webservices.py 9507 2012-11-02 10:46:22Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | |
---|
19 | import grok |
---|
20 | from zope.component import getUtility |
---|
21 | from zope.catalog.interfaces import ICatalog |
---|
22 | from waeup.kofa.payments.interfaces import IPaymentWebservice |
---|
23 | from waeup.kofa.interfaces import IUniversity, academic_sessions_vocab |
---|
24 | |
---|
25 | # Kofa's webservices to requery payments from outside |
---|
26 | |
---|
27 | class KofaPaymentRequest(grok.View): |
---|
28 | |
---|
29 | grok.context(IUniversity) |
---|
30 | grok.name('paymentrequest') |
---|
31 | grok.require('waeup.Public') |
---|
32 | |
---|
33 | #ACCEPTED_IP = ('174.36.230.28', ) |
---|
34 | ACCEPTED_IP = ('127.0.0.1', ) |
---|
35 | |
---|
36 | def update(self, P_ID=None): |
---|
37 | if P_ID == None: |
---|
38 | self.output = '-1' |
---|
39 | return |
---|
40 | real_ip = self.request.get('HTTP_X_FORWARDED_FOR', None) |
---|
41 | if real_ip: |
---|
42 | self.context.logger.info('KofaPaymentRequest called: %s' % real_ip) |
---|
43 | if real_ip and self.ACCEPTED_IP: |
---|
44 | if real_ip not in self.ACCEPTED_IP: |
---|
45 | self.output = '-4' |
---|
46 | return |
---|
47 | cat = getUtility(ICatalog, name='payments_catalog') |
---|
48 | results = list( |
---|
49 | cat.searchResults(p_id=(P_ID, P_ID), p_state=('paid', 'paid'))) |
---|
50 | if len(results) != 1: |
---|
51 | self.output = '-1' |
---|
52 | return |
---|
53 | try: |
---|
54 | owner = IPaymentWebservice(results[0]) |
---|
55 | full_name = owner.display_fullname |
---|
56 | matric_number = owner.reg_or_matric_number |
---|
57 | faculty = owner.faculty |
---|
58 | department = owner.department |
---|
59 | except (TypeError, AttributeError): |
---|
60 | self.output = '-3' |
---|
61 | return |
---|
62 | amount = results[0].amount_auth |
---|
63 | payment_category = results[0].category |
---|
64 | payment_item = results[0].p_item |
---|
65 | academic_session = academic_sessions_vocab.getTerm( |
---|
66 | results[0].p_session).title |
---|
67 | self.output = ( |
---|
68 | 'FULL_NAME=%s&' + |
---|
69 | 'FACULTY=%s&' + |
---|
70 | 'DEPARTMENT=%s&' + |
---|
71 | 'PAYMENT_ITEM=%s&' + |
---|
72 | 'PAYMENT_CATEGORY=%s&' + |
---|
73 | 'ACADEMIC_SESSION=%s&' + |
---|
74 | 'MATRIC_NUMBER=%s&' + |
---|
75 | 'FEE_AMOUNT=%s') % (full_name, faculty, |
---|
76 | department, payment_item, payment_category, |
---|
77 | academic_session, matric_number, amount) |
---|
78 | return |
---|
79 | |
---|
80 | def render(self): |
---|
81 | return self.output |
---|