source: main/waeup.kofa/trunk/src/waeup/kofa/webservices.py @ 9818

Last change on this file since 9818 was 9733, checked in by Henrik Bettermann, 12 years ago

Extend webservice and return reg_number too.

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1## $Id: webservices.py 9733 2012-11-27 18:56:08Z 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
19import grok
20from zope.component import getUtility
21from zope.catalog.interfaces import ICatalog
22from waeup.kofa.payments.interfaces import IPaymentWebservice
23from waeup.kofa.interfaces import IUniversity, academic_sessions_vocab
24
25# Kofa's webservices to requery payments from outside
26
27class 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            reg_number = owner.reg_number
57            matric_number = owner.matric_number
58            faculty = owner.faculty
59            department = owner.department
60        except (TypeError, AttributeError):
61            self.output = '-3'
62            return
63        amount = results[0].amount_auth
64        payment_category = results[0].category
65        payment_item = results[0].p_item
66        academic_session = academic_sessions_vocab.getTerm(
67            results[0].p_session).title
68        self.output = (
69            'FULL_NAME=%s&' +
70            'FACULTY=%s&' +
71            'DEPARTMENT=%s&' +
72            'PAYMENT_ITEM=%s&' +
73            'PAYMENT_CATEGORY=%s&' +
74            'ACADEMIC_SESSION=%s&' +
75            'MATRIC_NUMBER=%s&' +
76            'REG_NUMBER=%s&' +
77            'FEE_AMOUNT=%s') % (full_name, faculty,
78            department, payment_item, payment_category,
79            academic_session, matric_number, reg_number, amount)
80        return
81
82    def render(self):
83        return self.output
84
85class XMLRPCPermission(grok.Permission):
86    """Permission for using XMLRPC functions.
87    """
88    grok.name('waeup.xmlrpc')
89
90class UniversityXMLRPC(grok.XMLRPC):
91    """XMLRPC webservices for KOFA portals.
92
93    Please note, that XMLRPC does not support real keyword arguments
94    but positional arguments only.
95    """
96    grok.context(IUniversity)
97
98    @grok.require('waeup.Public')
99    def xmlrpc_api_version(self):
100        """Return the current API version for XMLRPC clients.
101        """
102        return u'0.1'
103
104    @grok.require('waeup.xmlrpc')
105    def get_student_id(self, reg_number=None):
106        """Get the id of a student with registration number `reg_number`.
107
108        Returns the student id as string if successful, ``None`` else.
109        """
110        if reg_number is not None:
111            cat = getUtility(ICatalog, name='students_catalog')
112            result = list(
113                cat.searchResults(reg_number=(reg_number, reg_number),
114                                  _limit=1))
115            if not len(result):
116                return None
117            return result[0].student_id
118        return None
Note: See TracBrowser for help on using the repository browser.