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