source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/interswitch/browser.py @ 18329

Last change on this file since 18329 was 18329, checked in by Henrik Bettermann, 2 months ago

Change tech_fee account.

  • Property svn:keywords set to Id
File size: 16.8 KB
Line 
1## $Id: browser.py 18329 2026-09-11 16:31:13Z 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 kofacustom.nigeria.interswitch.browser import (
22    module_activated,
23    InterswitchPaymentRequestWebservicePageApplicant,
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
29from kofacustom.unidel.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.unidel.interfaces import MessageFactory as _
32
33PRODUCT_ID = '22153701' # must be provided by Interswitch
34SITE_NAME = 'unidel.waeup.org'
35PROVIDER_ACCT = '1000327878'
36PROVIDER_BANK_ID = '4298'
37PROVIDER_ITEM_NAME = 'WAeAC'
38INSTITUTION_NAME = 'UNIDEL'
39CURRENCY = '566'
40GATEWAY_AMT = 300.0
41#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
42MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi'
43
44POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay'
45#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
46HOST = 'webpay.interswitchng.com'
47#HOST = 'sandbox.interswitchng.com'
48URL = '/collections/api/v1/gettransaction.json'
49#URL = '/webpay/api/v1/gettransaction.json'
50
51httplib.HTTPSConnection.debuglevel = 0
52HTTPS = True
53
54class CustomInterswitchPageStudent(InterswitchPageStudent):
55    """ View which sends a POST request to the Interswitch
56    CollegePAY payment gateway.
57    """
58    grok.context(ICustomStudentOnlinePayment)
59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
63    mac = MAC
64    gateway_amt = GATEWAY_AMT
65
66    def update(self):
67        if not module_activated(
68            self.context.student.current_session, self.context):
69            self.flash(_('Forbidden'), type='danger')
70            self.redirect(self.url(self.context, '@@index'))
71            return
72        error = self.init_update()
73        if error:
74            self.flash(error, type='danger')
75            self.redirect(self.url(self.context, '@@index'))
76            return
77        student = self.student
78        xmldict = self.xmldict
79        # Provider data
80        xmldict['detail_ref'] = self.context.p_id
81        xmldict['provider_acct'] = PROVIDER_ACCT
82        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
83        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
84        # Institution data
85        xmldict['institution_acct'] = '000000000'
86        xmldict['institution_bank_id'] = '117'
87        provider_amt = 0.0
88        tech_fee = 0.0
89        union_due = 0.0
90        if self.context.p_category == 'clearance':
91            provider_amt = 2000.0
92            if student.current_mode in ('ug_ft', 'de_ft'):
93                xmldict['institution_acct'] = '2000092025'
94                xmldict['institution_bank_id'] = '8'
95            #    tech_fee = 18000.0
96            #    xmldict['tech_acct'] = xmldict['institution_acct']
97            #    xmldict['tech_bank_id'] = xmldict['institution_bank_id']
98            if student.current_mode.startswith('dp'):
99                xmldict['institution_acct'] = '1011431799'
100            if student.faccode in ('PRE', 'JUPEB'):
101                xmldict['institution_acct'] = '1011431799'
102            elif student.faccode == 'IJMB':
103                xmldict['institution_acct'] = '2000092025'
104                xmldict['institution_bank_id'] = '8'
105            if self.context.p_item == 'Balance':
106                provider_amt = 0.0
107                tech_fee = 0.0
108        elif self.context.p_category == 'schoolfee':
109            provider_amt = 7000.0
110            tech_fee = 3000.0
111            xmldict['institution_acct'] = '1011739172'
112            #xmldict['tech_acct'] = '1130003817'
113            #xmldict['tech_bank_id'] = '117'
114            xmldict['union_acct'] = '1011438901'
115            xmldict['union_bank_id'] = '117'
116            if student.current_mode == 'ug_ft':
117                union_due = 1500.0
118            if student.current_mode.startswith('dp'):
119                xmldict['institution_acct'] = '2000092025'
120                xmldict['institution_bank_id'] = '8'
121            elif student.current_mode in ('pde', 'trc'):
122                xmldict['institution_acct'] = '2000092025'
123                xmldict['institution_bank_id'] = '8'
124            elif student.faccode in ('PRE', 'JUPEB'):
125                xmldict['institution_acct'] = '2000092025'
126                xmldict['institution_bank_id'] = '8'
127            elif student.faccode == 'DELSU':
128                xmldict['institution_acct'] = '2000092025'
129            elif student.faccode == 'NCE':
130                xmldict['institution_acct'] = '1011274462'
131                provider_amt = 4000.0
132                tech_fee = 0.0
133            elif student.faccode == 'IJMB':
134                xmldict['institution_acct'] = '2000092025'
135                xmldict['institution_bank_id'] = '8'
136            elif student.faccode in ('FMED', 'FBM', 'FLW'):
137                xmldict['institution_acct'] = '1011739172'
138            elif student.certcode == 'DFFPA':
139                xmldict['institution_acct'] = '2000092025'
140                xmldict['institution_bank_id'] = '8'
141                provider_amt = 4000.0
142                tech_fee = 0.0
143            if self.context.p_item == 'Balance':
144                provider_amt = 0.0
145                tech_fee = 0.0
146                union_due = 0.0
147            xmldict['tech_acct'] = xmldict['institution_acct']
148            xmldict['tech_bank_id'] = xmldict['institution_bank_id']
149        elif self.context.p_category.startswith('ijmb'):
150                xmldict['institution_acct'] = '2000092025'
151                xmldict['institution_bank_id'] = '8'
152        elif self.context.p_category == 'hostel_maintenance':
153            xmldict['institution_acct'] = '1012551384'
154        elif self.context.p_category == 'med_reg':
155            xmldict['institution_acct'] = '1011265606'
156        elif self.context.p_category == 'teaching_practice':
157            xmldict['institution_acct'] = '2000092025'
158            xmldict['institution_bank_id'] = '8'
159        elif self.context.p_category == 'siwes':
160            xmldict['institution_acct'] = '2000092025'
161            xmldict['institution_bank_id'] = '8'
162        elif self.context.p_category == 'convocation':
163            xmldict['institution_acct'] = '2000092025'
164            xmldict['institution_bank_id'] = '8'
165        elif self.context.p_category.startswith('plagtest'):
166            xmldict['institution_acct'] = '2000092025'
167            xmldict['institution_bank_id'] = '8'
168        elif self.context.p_category.startswith('transcript'):
169            xmldict['institution_acct'] = '2000092025'
170            xmldict['institution_bank_id'] = '8'
171            provider_amt = 2000.0
172        elif self.context.p_category.startswith('trcn'):
173            xmldict['institution_acct'] = '2000092025'
174            xmldict['institution_bank_id'] = '8'
175            provider_amt = 500.0
176        elif self.context.p_category.endswith('_ced'):
177            xmldict['institution_acct'] = '2000092025'
178            xmldict['institution_bank_id'] = '8'
179        elif self.context.p_category.startswith('union'):
180            xmldict['institution_acct'] = '1011438901'
181        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
182        # Already now it becomes an Interswitch payment. We set the net amount
183        # and add gateway amount and other surcharges.
184        if not self.context.r_company:
185            self.context.r_company = u'interswitch'
186            self.context.net_amt = self.context.amount_auth
187            self.context.gateway_amt = self.gateway_amt
188            self.context.amount_auth += self.gateway_amt
189            self.context.provider_amt = provider_amt
190            self.context.amount_auth += provider_amt
191            self.context.amount_auth += tech_fee
192            self.context.amount_auth += union_due
193        xmldict['provider_amt'] = 100 * provider_amt
194        xmldict['tech_fee'] = 100 * tech_fee
195        xmldict['union_due'] = 100 * union_due
196        xmldict['institution_item_name'] = self.context.category
197        xmldict['institution_name'] = INSTITUTION_NAME
198        xmldict['institution_amt'] = 100 * self.context.net_amt
199        xmldict['item_id'] = 1
200        xmltext = """
201<payment_item_detail>
202<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
203<item_detail item_id="%(item_id)s" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
204""" % xmldict
205        if provider_amt:
206            xmldict['item_id'] += 1
207            xmltext += """<item_detail item_id="%(item_id)s" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
208""" % xmldict
209        if tech_fee:
210            xmldict['item_id'] += 1
211            xmltext += """<item_detail item_id="%(item_id)s" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="%(tech_bank_id)s" acct_num="%(tech_acct)s" />
212""" % xmldict
213        if union_due:
214            xmldict['item_id'] += 1
215            xmltext += """<item_detail item_id="%(item_id)s" item_name="Student Union Due" item_amt="%(union_due)d" bank_id="%(union_bank_id)s" acct_num="%(union_acct)s" />
216""" % xmldict
217        xmltext +="""</item_details>
218</payment_item_detail>
219"""
220        self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext
221        self.context.provider_amt = provider_amt
222        self.amount_auth = int(100 * self.context.amount_auth)
223        hashargs = (
224            self.context.p_id +
225            PRODUCT_ID +
226            self.pay_item_id +
227            str(int(self.amount_auth)) +
228            self.site_redirect_url +
229            self.mac)
230        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
231        return
232
233class CustomInterswitchPageApplicant(InterswitchPageApplicant):
234    """ View which sends a POST request to the Interswitch
235    CollegePAY payment gateway.
236    """
237    grok.context(ICustomApplicantOnlinePayment)
238    action = POST_ACTION
239    site_name = SITE_NAME
240    currency = CURRENCY
241    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
242    product_id = PRODUCT_ID
243    mac = MAC
244    gateway_amt = GATEWAY_AMT
245
246    def update(self):
247        if not module_activated(
248            self.context.__parent__.__parent__.year, self.context):
249            self.flash(_('Forbidden'), type='danger')
250            self.redirect(self.url(self.context, '@@index'))
251            return
252        error = self.init_update()
253        if error:
254            self.flash(error, type='danger')
255            self.redirect(self.url(self.context, '@@index'))
256            return
257        # Already now it becomes an Interswitch payment. We set the net amount
258        # and add the gateway amount.
259        if not self.context.r_company:
260            self.context.net_amt = self.context.amount_auth
261            self.context.amount_auth += self.gateway_amt
262            self.context.gateway_amt = self.gateway_amt
263            self.context.r_company = u'interswitch'
264        xmldict = {}
265        provider_amt = 500.0
266        xmldict['institution_acct'] = '2000092025'
267        xmldict['institution_bank_id'] = '8'
268        if self.context.__parent__.__parent__.prefix in (
269                                    'pre', 'jupeb', 'dpft', 'dppt',
270                                    'ugpt', 'ijmb', 'df'):
271            xmldict['institution_acct'] = '2000092025'
272            xmldict['institution_bank_id'] = '8'
273            provider_amt = 500.0           
274        if self.context.__parent__.__parent__.prefix in ('ijmb',):
275            xmldict['institution_acct'] = '2000092025'
276            xmldict['institution_bank_id'] = '8'
277        if self.context.__parent__.__parent__.prefix in ('pde', 'trcdeg', 'trcnce'):
278            xmldict['institution_acct'] = '2000092025'
279            xmldict['institution_bank_id'] = '8'
280            provider_amt = 500.0
281        if self.context.__parent__.__parent__.prefix in ('dsb',):
282            xmldict['institution_acct'] = '2000092025'
283            xmldict['institution_bank_id'] = '8'
284            provider_amt = 500.0
285        xmldict['detail_ref'] = self.context.p_id
286        xmldict['provider_amt'] = 100 * provider_amt
287        xmldict['provider_acct'] = PROVIDER_ACCT
288        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
289        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
290        xmldict['institution_item_name'] = self.context.category
291        xmldict['institution_name'] = INSTITUTION_NAME
292        xmldict['institution_amt'] = 100 * self.context.net_amt
293        if not self.context.provider_amt:
294            self.context.provider_amt = provider_amt
295            self.context.amount_auth += provider_amt
296        xmltext = """<payment_item_detail>
297<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
298<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" />
299<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" />
300</item_details>
301</payment_item_detail>""" % xmldict
302        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
303        self.amount_auth = int(100 * self.context.amount_auth)
304        hashargs = (
305            self.context.p_id +
306            PRODUCT_ID +
307            self.pay_item_id +
308            str(int(self.amount_auth)) +
309            self.site_redirect_url +
310            self.mac)
311        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
312        return
313
314class CustomInterswitchPaymentRequestWebservicePageStudent(
315    InterswitchPaymentRequestWebservicePageStudent):
316    """Request webservice view for the CollegePAY gateway
317    """
318    grok.context(ICustomStudentOnlinePayment)
319    product_id = PRODUCT_ID
320    gateway_host = HOST
321    gateway_url = URL
322    mac = MAC
323
324class CustomInterswitchPaymentVerifyWebservicePageStudent(
325    InterswitchPaymentVerifyWebservicePageStudent):
326    """Payment verify view for the CollegePAY gateway
327    """
328    grok.context(ICustomStudentOnlinePayment)
329    product_id = PRODUCT_ID
330    gateway_host = HOST
331    gateway_url = URL
332    mac = MAC
333
334class CustomInterswitchPaymentRequestWebservicePageApplicant(
335    InterswitchPaymentRequestWebservicePageApplicant):
336    """Request webservice view for the CollegePAY gateway
337    """
338    grok.context(ICustomApplicantOnlinePayment)
339    product_id = PRODUCT_ID
340    gateway_host = HOST
341    gateway_url = URL
342    mac = MAC
343
344class CustomInterswitchPaymentVerifyWebservicePageApplicant(
345    InterswitchPaymentVerifyWebservicePageApplicant):
346    """Payment verify view for the CollegePAY gateway
347    """
348    grok.context(ICustomApplicantOnlinePayment)
349    product_id = PRODUCT_ID
350    gateway_host = HOST
351    gateway_url = URL
352    mac = MAC
353
354# PAYDirect
355
356from kofacustom.nigeria.interswitch.paydirectbrowser import (
357    PAYDirectPageStudent, PAYDirectPageApplicant,
358    StudentRefNumberSlip, ApplicantRefNumberSlip,
359    )
360
361from kofacustom.nigeria.interswitch.tests import (
362    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
363
364#PAYDIRECT_HOST = 'orion.interswitchng.com'
365#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
366#MERCHANT_ID = ''
367
368class CustomPAYDirectPageStudent(PAYDirectPageStudent):
369    """Inform student how to proceed
370    """
371    grok.context(ICustomStudentOnlinePayment)
372    gateway_amt = GATEWAY_AMT
373    merchant_id = MERCHANT_ID
374    gateway_url = PAYDIRECT_URL
375    gateway_host = PAYDIRECT_HOST
376    https = True
377
378class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
379    """ Inform applicant how to proceed.
380    """
381    grok.context(ICustomApplicantOnlinePayment)
382    gateway_amt = GATEWAY_AMT
383    merchant_id = MERCHANT_ID
384    gateway_url = PAYDIRECT_URL
385    gateway_host = PAYDIRECT_HOST
386    https = True
387
388class CustomStudentRefNumberSlip(StudentRefNumberSlip):
389    """Deliver a PDF slip of the context.
390    """
391    merchant_id = MERCHANT_ID
392
393class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
394    """Deliver a PDF slip of the context.
395    """
396    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.