source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/etranzact/browser.py @ 17808

Last change on this file since 17808 was 17792, checked in by Henrik Bettermann, 6 months ago

Customize serviceCodes.

  • Property svn:keywords set to Id
File size: 12.5 KB
RevLine 
[15601]1## $Id: browser.py 17792 2024-05-16 11:15:56Z henrik $
2##
3## Copyright (C) 2017 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
[17792]19import os
20import csv
[15601]21from kofacustom.nigeria.etranzact.applicantsbrowser import (
22    EtranzactPageApplicant, EtranzactReceiveResponseApplicant,
23    EtranzactRequestPaymentStatusPageApplicant)
24from kofacustom.nigeria.etranzact.studentsbrowser import (
25    EtranzactPageStudent, EtranzactReceiveResponseStudent,
[15773]26    EtranzactRequestPaymentStatusPageStudent, webconnect_module_activated)
[15733]27from kofacustom.nigeria.etranzact.payoutletbrowser import (
[15773]28    EtranzactEnterPinPageStudent, EtranzactEnterPinPageApplicant,
29    EtranzactQueryHistoryPageStudent, EtranzactQueryHistoryPageApplicant,
30    payoutlet_module_activated)
31from kofacustom.nigeria.etranzact.payoutletwebservice  import NigeriaPaymentDataWebservice
[17731]32from kofacustom.nigeria.etranzact.credobrowser  import (
33    CredoPageStudent, CredoPageApplicant,
34    CredoVerifyPaymentStatusPageStudent, CredoVerifyPaymentStatusPageApplicant)
[15601]35
36# Temporarily we can use the test portal like in kofacustom.nigeria
37
38from kofacustom.nigeria.etranzact.tests import (
[16104]39    HOST, HTTPS)
[15601]40
[16637]41HOST = 'www.etranzactng.net'
[15824]42HTTPS = True
[16141]43GATEWAY_AMT = 0.0 # is beeing added by Etranzact
[15601]44LOGO_URL = 'https://iuokada.waeup.org/static_custom/iou_logo.png'
45
[16084]46WEBCONNECT_STUD_PARAMS = {
47    'schoolfee': ('7007139588','QIgl9a35R30A1RGK'),
48    'schoolfee40': ('7007139589','3coU0eolOEbEUeO3'),
49    'secondinstal': ('7007139590','zGpEjy6CdPxCHqen'),
50    'transcript_local': ('7007139592','ndgxUtzJgHRkvXlB'),
[16142]51    'transcript': ('7007139592','ndgxUtzJgHRkvXlB'),
[16084]52    'transcript_overseas': ('7007139592','ndgxUtzJgHRkvXlB'),
53    'registration': ('7007139599','KGHjZ2hRbaDJGBX8'),
54    'book': ('7007139600','rrKE2Ua7eu8TF0Is'),
55    'parentsconsult': ('7007139598','HsqjOlAB5xfQNDyo'),
56    'sundry': ('7007139591','0XkOFShPnWn8tY5O'),
[17545]57    'health_insurance':('7007140478', 'Be24m7O7iODZXcYF'),
[16084]58    }
59
60def determine_appl_params(payment):
61    terminal_id = ''
62    secret_key = ''
63    if payment.__parent__.__parent__.prefix.startswith('pg'):
64        terminal_id = '7007139606'
65        secret_key = 'E64s3IN9cXRJeltY'
66    else:
67        terminal_id = '7007139604'
68        secret_key = 'vlEEJxvJBjC468g1'
69    return terminal_id, secret_key
70
71def determine_stud_params(payment):
72    terminal_id = ''
73    secret_key = ''
74    for key in WEBCONNECT_STUD_PARAMS.keys():
75        if payment.p_category == key:
76            terminal_id = WEBCONNECT_STUD_PARAMS[key][0]
77            secret_key = WEBCONNECT_STUD_PARAMS[key][1]
78    if not terminal_id:
79        terminal_id = WEBCONNECT_STUD_PARAMS['sundry'][0]
80        secret_key = WEBCONNECT_STUD_PARAMS['sundry'][1]
81    return terminal_id, secret_key
82
[15601]83class CustomEtranzactPageApplicant(EtranzactPageApplicant):
84
85    host = HOST
86    https = HTTPS
87    logo_url = LOGO_URL
[15773]88    gateway_amt = GATEWAY_AMT
[15601]89
[16084]90    @property
91    def terminal_id(self):
92        return determine_appl_params(self.context)[0]
93
94    @property
95    def secret_key(self):
96        return determine_appl_params(self.context)[1]
97
[15773]98    def update(self):
[15999]99        if not webconnect_module_activated(
100            self.context.__parent__.__parent__.year, self.context):
[16350]101            self.flash('Forbidden', type='danger')
[15999]102            self.redirect(self.url(self.context, '@@index'))
103            return
[15773]104        # Already now it becomes an Etranzact payment. We set the net amount
105        # and add the gateway amount.
106        if not self.context.r_company:
107            self.context.net_amt = self.context.amount_auth
108            self.context.amount_auth += self.gateway_amt
109            self.context.gateway_amt = self.gateway_amt
110            self.context.r_company = u'etranzact'
111        self.amount = "%.1f" % self.context.amount_auth
112        error = self.init_update()
113        if error:
114            self.flash(error, type='danger')
115            self.redirect(self.url(self.context, '@@index'))
116            return
117        return
118
[15601]119class CustomEtranzactReceiveResponseApplicant(EtranzactReceiveResponseApplicant):
120
[16084]121    @property
122    def terminal_id(self):
123        return determine_appl_params(self.context)[0]
[15601]124
[16084]125    @property
126    def secret_key(self):
127        return determine_appl_params(self.context)[1]
128
[15601]129class CustomEtranzactRequestPaymentStatusPageApplicant(
130    EtranzactRequestPaymentStatusPageApplicant):
131
132    host = HOST
133    https = HTTPS
134    logo_url = LOGO_URL
135
[16084]136    @property
137    def terminal_id(self):
138        return determine_appl_params(self.context)[0]
139
140    @property
141    def secret_key(self):
142        return determine_appl_params(self.context)[1]
143
[15601]144class CustomEtranzactPageStudent(EtranzactPageStudent):
145
146    host = HOST
147    https = HTTPS
148    logo_url = LOGO_URL
[15773]149    gateway_amt = GATEWAY_AMT
[15601]150
[16084]151    @property
152    def terminal_id(self):
153        return determine_stud_params(self.context)[0]
154
155    @property
156    def secret_key(self):
157        return determine_stud_params(self.context)[1]
158
[15773]159    def update(self):
[15999]160        if not webconnect_module_activated(
161            self.context.student.current_session, self.context):
162            self.flash(_('Forbidden'), type='danger')
163            self.redirect(self.url(self.context, '@@index'))
164            return
[15773]165        # Already now it becomes an Etranzact payment. We set the net amount
166        # and add the gateway amount.
167        if not self.context.r_company:
168            self.context.net_amt = self.context.amount_auth
169            self.context.amount_auth += self.gateway_amt
170            self.context.gateway_amt = self.gateway_amt
171            self.context.r_company = u'etranzact'
172        self.amount = "%.1f" % self.context.amount_auth
173        error = self.init_update()
174        if error:
175            self.flash(error, type='danger')
176            self.redirect(self.url(self.context, '@@index'))
177            return
178        return
179
[15601]180class CustomEtranzactReceiveResponseStudent(EtranzactReceiveResponseStudent):
181
[16084]182    @property
183    def terminal_id(self):
184        return determine_stud_params(self.context)[0]
[15601]185
[16084]186    @property
187    def secret_key(self):
188        return determine_stud_params(self.context)[1]
189
[15601]190class CustomEtranzactRequestPaymentStatusPageStudent(
191    EtranzactRequestPaymentStatusPageStudent):
192
193    host = HOST
194    https = HTTPS
195    logo_url = LOGO_URL
196
[16084]197    @property
198    def terminal_id(self):
199        return determine_stud_params(self.context)[0]
200
201    @property
202    def secret_key(self):
203        return determine_stud_params(self.context)[1]
204
205
206
207
208
[15773]209# Payoutlet customizations
210
211class CustomEtranzactEnterPinPageStudent(EtranzactEnterPinPageStudent):
212    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageStudent`
213    """
214    gateway_amt = GATEWAY_AMT
215
216    def update(self):
217        if not payoutlet_module_activated(
218            self.context.student.current_session, self.context):
[15999]219            self.flash(_('Forbidden'), type='danger')
220            self.redirect(self.url(self.context, '@@index'))
[15773]221            return
222        # Already now it becomes an Etranzact payment. We set the net amount
223        # and add the gateway amount.
224        if not self.context.r_company:
225            self.context.net_amt = self.context.amount_auth
226            self.context.amount_auth += self.gateway_amt
227            self.context.gateway_amt = self.gateway_amt
228            self.context.r_company = u'etranzact'
229        return
230
231class CustomEtranzactEnterPinPageApplicant(EtranzactEnterPinPageApplicant):
232    """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant`
233    """
234    gateway_amt = GATEWAY_AMT
235
236    def update(self):
237        if not payoutlet_module_activated(
238            self.context.__parent__.__parent__.year, self.context):
[15999]239            self.flash(_('Forbidden'), type='danger')
240            self.redirect(self.url(self.context, '@@index'))
[15773]241            return
242        # Already now it becomes an Etranzact payment. We set the net amount
243        # and add the gateway amount.
244        if not self.context.r_company:
245            self.context.net_amt = self.context.amount_auth
246            self.context.amount_auth += self.gateway_amt
247            self.context.gateway_amt = self.gateway_amt
248            self.context.r_company = u'etranzact'
249        return
250
[15733]251class CustomEtranzactQueryHistoryPageStudent(EtranzactQueryHistoryPageStudent):
252    """ Query history of Etranzact payments
253    """
[16084]254    terminal_id = '7007134590'
[15733]255    host = HOST
256    https = HTTPS
[15601]257
[15733]258class CustomEtranzactQueryHistoryPageApplicant(EtranzactQueryHistoryPageApplicant):
259    """ Query history of Etranzact payments
260    """
[15898]261    terminal_id = '7009158847'
[15733]262    host = HOST
[15773]263    https = HTTPS
264
265class CustomPaymentDataWebservice(NigeriaPaymentDataWebservice):
266    """A simple webservice to publish payment and payer details on request from
267    accepted IP addresses without authentication.
268    """
269    #ACCEPTED_IP = ('195.219.3.181', '195.219.3.184')
270    ACCEPTED_IP = None
271
272    CATEGORY_MAPPING = {
[15781]273        'IUO_SCHOOL_FEES_FULL_PAYMENT': ('schoolfee',),
274        'IUO_SCHOOL_FEES_FIRST_INSTALLMENT': ('schoolfee40',),
275        'IUO_SCHOOL_FEES_OTHER_INSTALLMENT': ('secondinstal',),
[16111]276
277        'IUO_SUNDRY_FEES': ('combi',),
278
279        'IUO_MATRICULATION_FEE': ('matric',),
280        'IUO_LATE_REGISTRATION_FEE': ('late_registration',),
[16311]281        'IUO_WAEC/NECO_VERIFICATION_FEE': ('waecneco',),
[16111]282        'IUO_JAMB_VERIFICATION': ('jambver',),
283        'IUO_CONVOCATION_FEE': ('conv',),
284        'IUO_ALUMNI_FEE': ('alumni',),
285        'IUO_SCIENCE_BENCE_FEE': ('science',),
286        'IUO_LETTER_OF_IDENTIFICATION_FEE': ('lo_ident',),
287        'IUO_CHANGE_OF_COURSE_FEE': ('change_course',),
288        'IUO_IUITS_FEE': ('iuits',),
289        'IUO_FINES_FEE': ('fine',),
290        'IUO_PHARMACY_LAB_SUPPORT_FEE': ('pharmlab',),
291        'IUO_MAKEUP_FEE': ('resit1', 'resit2', 'resit3', 'resit4',
292                           'resit5', 'resit6', 'resit7', 'resit8',
293                           'resit9',),
294        'IUO_CLINICAL_FEE_MEDICAL_STUDENTS': ('clinical',),
295        'IUO_TRANSCRIPT_FEE_INTERNATIONAL': ('transcript_overseas',),
[16142]296        'IUO_TRANCRIPT_FEE_LOCAL': ('transcript_local', 'transcript'),
[16261]297        'IUO_ACCEPTANCE_FEE': ('clearance',),
298        'IUO_CLEARANCE_FEE': ('grad_clearance',),
[16111]299        'IUO_ID_CARD_FEE': ('id_card',),
[15781]300        'IUO_REGISTRATION_FEE': ('registration',),
[16111]301        'IUO_DEVELOPMENT_FEE': ('develop',),
302        'IUO_MUNICIPAL_FEE': ('municipal_fresh','municipal_returning'),
303        'IUO_BOOK_DEPOSIT': ('book',),
[15781]304        'IUO_PARENTS_CONSULTATIVE_FORUM_FEE': ('parentsconsult',),
[16340]305
306        'IUO_APPLICATION_FORM_UNDERGRADUATE': ('application',),
307        'IUO_APPLICATION_FORM_POSTGRADUATE': ('application',),
[16397]308
[16577]309        'IUO_MAKE_UP_REGISTRATION_FEE': ('makeup_admin',),
[17519]310        'IUO_STUDENT_HEALTH_INSURANCE': ('health_insurance',),
[16577]311
[16685]312        'IUO_COMBI_PAYMENT': ('combi',),
313
[16397]314        'JUPEB_FORM_FEE': ('jupeb_form',),
315        'JUPEB_ACCEPTANCE_FEE': ('jupeb_acc',),
316        'JUPEB_SCIENCE_COURSE': ('jupeb_sci',),
317        'JUPEB_ARTS_COURSE': ('jupeb_arts',),
318        'JUPEB_HOSTEL_FEE': ('jupeb_hostel',),
319        'JUPEB_REGISTRATION_FEE': ('jupeb_reg',),
[17731]320         }
321
322# Credo customizations
323
[17735]324SECRET_API_KEY = "1PRI1279pI28Y9kCqZs9PlvM6ZjjZx4dXBdV8a"
325API_PUBLIC_KEY = "1PUB1279tj5IbnXbUFd78YT3ew8XHeyLJP3tEm"
326CREDO_HOST = "api.credocentral.com"
[17731]327
[17792]328scodes_path = os.path.join(
329    os.path.dirname(__file__), 'servicecodes.csv')
330reader = csv.DictReader(open(scodes_path, 'rb'))
331SCODES = {line['p_category']:line['serviceCode'] for line in reader}
332
[17731]333class CustomCredoPageStudent(CredoPageStudent):
334
335    host = CREDO_HOST
336    api_public_key = API_PUBLIC_KEY
337
[17792]338    @property
339    def serviceCode(self):
340        return SCODES.get(self.context.p_category, None)
341
[17731]342class CustomCredoPageApplicant(CredoPageApplicant):
343
344    host = CREDO_HOST
345    api_public_key = API_PUBLIC_KEY
346
[17792]347    @property
348    def serviceCode(self):
349        return SCODES.get(self.context.p_category, None)
350
[17731]351class CustomCredoVerifyPaymentStatusPageStudent(CredoVerifyPaymentStatusPageStudent):
352
353    host = CREDO_HOST
354    secret_api_key = SECRET_API_KEY
355
356class CustomCredoVerifyPaymentStatusPageApplicant(CredoVerifyPaymentStatusPageApplicant):
357
358    host = CREDO_HOST
359    secret_api_key = SECRET_API_KEY
Note: See TracBrowser for help on using the repository browser.