source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/interswitch/browser.py @ 18332

Last change on this file since 18332 was 18332, checked in by Henrik Bettermann, 3 months ago

Set provider_amt attribute.

  • Property svn:keywords set to Id
File size: 15.6 KB
Line 
1## $Id: browser.py 18332 2026-09-15 13:50:57Z 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##
18import httplib
19import hashlib
20import grok
21from waeup.kofa.students.interfaces import IStudentsUtils
22from zope.component import getUtility
23from kofacustom.nigeria.interswitch.browser import (
24    module_activated,
25    InterswitchPaymentRequestWebservicePageApplicant,
26    InterswitchPaymentRequestWebservicePageStudent,
27    InterswitchPaymentVerifyWebservicePageApplicant,
28    InterswitchPaymentVerifyWebservicePageStudent,
29    InterswitchPageStudent, InterswitchPageApplicant,
30    )
31from kofacustom.iuokada.students.interfaces import ICustomStudentOnlinePayment
32from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment
33from kofacustom.iuokada.interfaces import MessageFactory as _
34
35PRODUCT_ID = '7922'
36SITE_NAME = 'iuokada.waeup.org'
37PROVIDER_ACCT = '0773411069'
38PROVIDER_BANK_ID = '31'
39PROVIDER_ITEM_NAME = 'WAeAC'
40INSTITUTION_NAME = 'IUOkada'
41CURRENCY = '566'
42GATEWAY_AMT = 800.0
43#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch
44MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA'
45
46POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
47#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
48HOST = 'webpay.interswitchng.com'
49#HOST = 'sandbox.interswitchng.com'
50URL = '/paydirect/api/v1/gettransaction.json'
51#URL = '/webpay/api/v1/gettransaction.json'
52
53httplib.HTTPSConnection.debuglevel = 0
54HTTPS = True
55
56BANK_ACCOUNTS = {
57    'access':               ('1228744877','117'),
58    'parentsconsult':       ('1012355544','117'),
59    'health_insurance':     ('1228744884','117'),
60    'municipal_returning':  ('0040621193','31'),
61    'clearance':            ('0040621193','31'),
62    'develop':              ('0040621193','31'),
63    'medical_screening':    ('1311220657','117'),
64    'conv':                 ('0040621193','31'),
65    'registration_fresh':   ('0040621193','31'),
66    'science':              ('0040621193','31'),
67    'id_card':              ('0040621193','31'),
68    'alumni':               ('1311974981','117'),
69    'pharmlab':             ('0040621193','31'),
70    'registration_return':  ('0040621193','31'),
71    'book':                 ('1228744877','117'),
72    'waecneco':             ('0040621193','31'),
73    'jambver':              ('0040621193','31'),
74    'pg_other':             ('0040621193','31'),
75    'municipal_fresh':      ('0040621193','31'),
76    'matric':               ('0040621193','31'),
77    'endowment':            ('1312373440','31'),
78    }
79
80class CustomInterswitchPageStudent(InterswitchPageStudent):
81    """ View which sends a POST request to the Interswitch
82    CollegePAY payment gateway.
83    """
84    grok.context(ICustomStudentOnlinePayment)
85    action = POST_ACTION
86    site_name = SITE_NAME
87    currency = CURRENCY
88    product_id = PRODUCT_ID
89    mac = MAC 
90    gateway_amt = GATEWAY_AMT
91
92    def update(self):
93        student_utils = getUtility(IStudentsUtils)
94        if not module_activated(
95            self.context.student.current_session, self.context):
96            self.flash(_('Forbidden'), type='danger')
97            self.redirect(self.url(self.context, '@@index'))
98            return
99        error = self.init_update()
100        if error:
101            self.flash(error, type='danger')
102            self.redirect(self.url(self.context, '@@index'))
103            return
104        # Already now it becomes an Interswitch 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'interswitch'
111        student = self.student
112        xmldict = self.xmldict
113        # Provider data
114        xmldict['detail_ref'] = self.context.p_id
115        xmldict['provider_acct'] = PROVIDER_ACCT
116        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
117        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
118        xmldict['institution_acct'] = ''
119        xmldict['institution_bank_id'] = ''
120        provider_amt = 0.0
121        self.pay_item_id = ''
122        # Institution data
123        if self.context.p_category in (
124            'schoolfee', 'schoolfee40', 'secondinstal'):
125            self.pay_item_id = '101'
126        else:
127            # we use the same item_id for all sundry payments
128            self.pay_item_id = '102'
129        if self.context.p_category in (
130            'registration', 'registration_fresh', 'registration_return',
131            'required_combi', 'pg_other', 'jupeb_reg'):
132            provider_amt = 10000.0
133        if self.context.p_category in (
134            'schoolfee', 'schoolfee40') and student.is_jupeb:
135            provider_amt = 10000.0
136        if self.context.p_category.startswith('jupeb'):
137            self.pay_item_id = '102'
138        xmldict['provider_amt'] = 100 * provider_amt
139        xmldict['institution_item_name'] = self.context.category
140        xmldict['institution_name'] = INSTITUTION_NAME
141        xmldict['institution_amt'] = 100 * self.context.net_amt - (
142            100 * provider_amt)
143        self.context.provider_amt = provider_amt
144
145        if grok.getSite().__name__ == 'iuokada-cdl':
146            xmldict['institution_acct'] = '1229771245'
147            xmldict['institution_bank_id'] = '117'
148            if self.context.p_category.startswith('schoolfee'):
149                xmldict['institution_acct'] = '1828332878'
150                xmldict['institution_bank_id'] = '31'
151        else:
152            if self.context.p_option == 'access':
153                xmldict['institution_acct'] = '0040484781'
154                xmldict['institution_bank_id'] = '31'
155            elif self.context.p_option == 'first':
156                xmldict['institution_acct'] = '2021420049'
157                xmldict['institution_bank_id'] = '8'
158            elif self.context.p_option == 'zenith':
159                xmldict['institution_acct'] = '1011005811'
160                xmldict['institution_bank_id'] = '117'
161            else:
162                xmldict['institution_acct'] = '0040484781'
163                xmldict['institution_bank_id'] = '31'
164
165            # Overwrite above selection
166            sundry_acct = BANK_ACCOUNTS.get(self.context.p_category, None)
167            if sundry_acct is True:
168                xmldict['institution_acct'] = sundry_acct[0]
169                xmldict['institution_bank_id'] = sundry_acct[0]
170
171        if provider_amt == 0:
172            xmltext = """<payment_item_detail>
173<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
174<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
175</item_details>
176</payment_item_detail>""" % xmldict
177        else:
178            xmltext = """<payment_item_detail>
179<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
180<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
181<item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
182</item_details>
183</payment_item_detail>""" % xmldict
184
185        # Overwrite xmltext above because we have to split required combi
186        if self.context.p_category == 'required_combi':
187            rp = student_utils._collect_required_payment_items(self.context.student)
188            academic_session = student_utils._getSessionConfiguration(self.context.p_session)
189            xmltext = """<payment_item_detail>
190<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
191<item_detail item_id="1" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />""" % xmldict
192            item_id = 2
193            for cat in rp:
194                fee_name = cat + '_fee'
195                item_name = cat
196                item_amt = 100 * getattr(academic_session, fee_name, 0.0)
197                if item_name.startswith('registration'):
198                    item_amt -= 100 * provider_amt
199                bank_id = BANK_ACCOUNTS[cat][1]
200                acct_num = BANK_ACCOUNTS[cat][0]
201                xmltext += """
202<item_detail item_id="%s" item_name="%s" item_amt="%d" bank_id="%s" acct_num="%s" />""" % (item_id, item_name, item_amt, bank_id, acct_num)
203                item_id += 1
204            xmltext += """
205</item_details>
206</payment_item_detail>""" % xmldict
207
208        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
209        self.amount_auth = int(100 * self.context.amount_auth)
210        hashargs = (
211            self.context.p_id +
212            PRODUCT_ID +
213            self.pay_item_id +
214            str(int(self.amount_auth)) +
215            self.site_redirect_url +
216            self.mac)
217        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
218        return
219
220class CustomInterswitchPageApplicant(InterswitchPageApplicant):
221    """ View which sends a POST request to the Interswitch
222    CollegePAY payment gateway.
223    """
224    grok.context(ICustomApplicantOnlinePayment)
225    action = POST_ACTION
226    site_name = SITE_NAME
227    currency = CURRENCY
228    product_id = PRODUCT_ID
229    mac = MAC
230    gateway_amt = GATEWAY_AMT
231
232    def update(self):
233        if not module_activated(
234            self.context.__parent__.__parent__.year, self.context):
235            self.flash(_('Forbidden'), type='danger')
236            self.redirect(self.url(self.context, '@@index'))
237            return
238        error = self.init_update()
239        if error:
240            self.flash(error, type='danger')
241            self.redirect(self.url(self.context, '@@index'))
242            return
243        # Already now it becomes an Interswitch payment. We set the net amount
244        # and add the gateway amount.
245        if not self.context.r_company:
246            self.context.net_amt = self.context.amount_auth
247            self.context.amount_auth += self.gateway_amt
248            self.context.gateway_amt = self.gateway_amt
249            self.context.r_company = u'interswitch'
250        self.amount_auth = int(100 * self.context.amount_auth)
251        xmldict = {}
252        provider_amt = 0.0
253        self.pay_item_id = '101'
254        xmldict['institution_acct'] = '1011005811'
255        xmldict['institution_bank_id'] = '117'
256        if grok.getSite().__name__ == 'iuokada-cdl':
257            xmldict['institution_acct'] = '1229774710'
258            xmldict['institution_bank_id'] = '117'
259        xmldict['detail_ref'] = self.context.p_id
260        xmldict['provider_amt'] = 100 * provider_amt
261        xmldict['provider_acct'] = PROVIDER_ACCT
262        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
263        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
264        xmldict['institution_item_name'] = self.context.category
265        xmldict['institution_name'] = INSTITUTION_NAME
266        xmldict['institution_amt'] = 100 * self.context.net_amt
267        if not self.context.provider_amt:
268            self.context.provider_amt = provider_amt
269            self.context.amount_auth += provider_amt
270        if provider_amt == 0:
271            xmltext = """<payment_item_detail>
272<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
273<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
274</item_details>
275</payment_item_detail>""" % xmldict
276        else:
277            xmltext = """<payment_item_detail>
278<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
279<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
280<item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
281</item_details>
282</payment_item_detail>""" % xmldict
283        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
284        self.amount_auth = int(100 * self.context.amount_auth)
285        hashargs = (
286            self.context.p_id +
287            PRODUCT_ID +
288            self.pay_item_id +
289            str(int(self.amount_auth)) +
290            self.site_redirect_url +
291            self.mac)
292        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
293        return
294
295class CustomInterswitchPaymentRequestWebservicePageStudent(
296    InterswitchPaymentRequestWebservicePageStudent):
297    """Request webservice view for the CollegePAY gateway
298    """
299    grok.context(ICustomStudentOnlinePayment)
300    product_id = PRODUCT_ID
301    gateway_host = HOST
302    gateway_url = URL
303    mac = MAC
304
305class CustomInterswitchPaymentVerifyWebservicePageStudent(
306    InterswitchPaymentVerifyWebservicePageStudent):
307    """Payment verify view for the CollegePAY gateway
308    """
309    grok.context(ICustomStudentOnlinePayment)
310    product_id = PRODUCT_ID
311    gateway_host = HOST
312    gateway_url = URL
313    mac = MAC
314
315class CustomInterswitchPaymentRequestWebservicePageApplicant(
316    InterswitchPaymentRequestWebservicePageApplicant):
317    """Request webservice view for the CollegePAY gateway
318    """
319    grok.context(ICustomApplicantOnlinePayment)
320    product_id = PRODUCT_ID
321    gateway_host = HOST
322    gateway_url = URL
323    mac = MAC
324
325class CustomInterswitchPaymentVerifyWebservicePageApplicant(
326    InterswitchPaymentVerifyWebservicePageApplicant):
327    """Payment verify view for the CollegePAY gateway
328    """
329    grok.context(ICustomApplicantOnlinePayment)
330    product_id = PRODUCT_ID
331    gateway_host = HOST
332    gateway_url = URL
333    mac = MAC
334
335
336# PAYDirect added on 19/05/2021
337
338from kofacustom.nigeria.interswitch.paydirectbrowser import (
339    PAYDirectPageStudent, PAYDirectPageApplicant,
340    StudentRefNumberSlip, ApplicantRefNumberSlip,
341    )
342
343PAYDIRECT_HOST = 'orion.interswitchng.com'
344PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
345MERCHANT_ID = '8124'
346
347class CustomPAYDirectPageStudent(PAYDirectPageStudent):
348    """Inform student how to proceed
349    """
350    grok.context(ICustomStudentOnlinePayment)
351    gateway_amt = GATEWAY_AMT
352    merchant_id = MERCHANT_ID
353    gateway_url = PAYDIRECT_URL
354    gateway_host = PAYDIRECT_HOST
355    https = True
356
357class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
358    """ Inform applicant how to proceed.
359    """
360    grok.context(ICustomApplicantOnlinePayment)
361    gateway_amt = GATEWAY_AMT
362    merchant_id = MERCHANT_ID
363    gateway_url = PAYDIRECT_URL
364    gateway_host = PAYDIRECT_HOST
365    https = True
366
367class CustomStudentRefNumberSlip(StudentRefNumberSlip):
368    """Deliver a PDF slip of the context.
369    """
370    merchant_id = MERCHANT_ID
371
372class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
373    """Deliver a PDF slip of the context.
374    """
375    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.