source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/payoutletwebservice.py @ 15730

Last change on this file since 15730 was 15702, checked in by Henrik Bettermann, 5 years ago

Add first Payoutlet components. Not yet tested.
Rename eTranzact.

File size: 5.1 KB
Line 
1## $Id: browser.py 15346 2019-03-06 22:19:56Z 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.interfaces import academic_sessions_vocab, IKofaUtils
23from waeup.kofa.payments.interfaces import IPayer
24from waeup.kofa.webservices import PaymentDataWebservice
25
26ERROR_PART1 = (
27        'PayeeName=N/A~'
28        + 'Faculty=N/A~'
29        + 'Department=N/A~'
30        + 'Level=N/A~'
31        + 'ProgrammeType=N/A~'
32        + 'StudyType=N/A~'
33        + 'Session=N/A~'
34        + 'PayeeID=N/A~'
35        + 'Amount=N/A~'
36        + 'FeeStatus=')
37ERROR_PART2 = (
38        '~Semester=N/A~'
39        + 'PaymentType=N/A~'
40        + 'MatricNumber=N/A~'
41        + 'Email=N/A~'
42        + 'PhoneNumber=N/A')
43
44class NigeriaPaymentDataWebservice(PaymentDataWebservice):
45    """A simple webservice to publish payment and payer details on request from
46    accepted IP addresses without authentication.
47
48    Etranzact is asking for the PAYEE_ID which is indeed misleading.
49    These are not the data of the payee but of the payer. And it's
50    not the id of the payer but of the payment.
51    """
52    grok.name('feerequest')
53
54    #ACCEPTED_IP = ('195.219.3.181', '195.219.3.184')
55    ACCEPTED_IP = None
56
57    CATEGORY_MAPPING = {
58        'SCHOOLFEE': ('schoolfee',),
59         }
60
61    def update(self, PAYEE_ID=None, PAYMENT_TYPE=None):
62
63        if PAYEE_ID == None:
64            self.output = ERROR_PART1 + 'Missing PAYEE_ID' + ERROR_PART2
65            return
66        real_ip = self.request.get('HTTP_X_FORWARDED_FOR', None)
67        # We can forego the logging once eTranzact payments run smoothly
68        # and the accepted IP addresses are used.
69        if real_ip:
70            self.context.logger.info('PaymentDataWebservice called: %s' % real_ip)
71        if real_ip  and self.ACCEPTED_IP:
72            if real_ip not in  self.ACCEPTED_IP:
73                self.output = ERROR_PART1 + 'Wrong IP address' + ERROR_PART2
74                return
75        payment_cats_dict = getUtility(IKofaUtils).PAYMENT_CATEGORIES
76        if PAYMENT_TYPE not in self.CATEGORY_MAPPING.keys() \
77            and PAYMENT_TYPE.lower() not in payment_cats_dict.keys():
78            self.output = ERROR_PART1 + 'Invalid PAYMENT_TYPE' + ERROR_PART2
79            return
80        cat = getUtility(ICatalog, name='payments_catalog')
81        results = list(cat.searchResults(p_id=(PAYEE_ID, PAYEE_ID)))
82        if len(results) != 1:
83            self.output = ERROR_PART1 + 'Invalid PAYEE_ID' + ERROR_PART2
84            return
85        amount = results[0].amount_auth
86        payment_type = results[0].category
87        p_category = results[0].p_category
88        programme_type = results[0].p_item
89        if not programme_type:
90            programme_type = 'N/A'
91        academic_session = academic_sessions_vocab.getTerm(
92            results[0].p_session).title
93        status = results[0].p_state
94        if status == 'paid':
95            self.output = ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2
96            return
97        if p_category not in self.CATEGORY_MAPPING.get('PAYMENT_TYPE', []) \
98            and p_category != PAYMENT_TYPE.lower():
99            self.output = ERROR_PART1 + 'Wrong PAYMENT_TYPE' + ERROR_PART2
100            return
101        try:
102            owner = IPayer(results[0])
103            full_name = owner.display_fullname
104            matric_no = owner.matric_number
105            faculty = owner.faculty
106            department = owner.department
107            study_type = owner.current_mode
108            email = owner.email
109            phone = owner.phone
110            level = owner.current_level
111        except (TypeError, AttributeError):
112            self.output = ERROR_PART1 +  'Unknown error' + ERROR_PART2
113            return
114        self.output = (
115            'PayeeName=%s~' +
116            'Faculty=%s~' +
117            'Department=%s~' +
118            'Level=%s~' +
119            'ProgrammeType=%s~' +
120            'StudyType=%s~' +
121            'Session=%s~' +
122            'PayeeID=%s~' +
123            'Amount=%s~' +
124            'FeeStatus=%s~' +
125            'Semester=N/A~' +
126            'PaymentType=%s~' +
127            'MatricNumber=%s~' +
128            'Email=%s~' +
129            'PhoneNumber=%s'
130
131            ) % (full_name, faculty,
132            department, level, programme_type, study_type,
133            academic_session, PAYEE_ID, amount, status, payment_type,
134            matric_no, email, phone)
135        return
Note: See TracBrowser for help on using the repository browser.