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

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

Implement Credo payments.

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