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

Last change on this file since 18143 was 18143, checked in by Henrik Bettermann, 3 days ago

New fees.

  • Property svn:keywords set to Id
File size: 16.0 KB
RevLine 
[16717]1## $Id: browser.py 18143 2025-07-30 09:52:58Z henrik $
[15614]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 (
[16592]22    module_activated,
[15614]23    InterswitchPaymentRequestWebservicePageApplicant,
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
[16721]29from kofacustom.unidel.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.unidel.interfaces import MessageFactory as _
[15614]32
[16736]33PRODUCT_ID = '22153701' # must be provided by Interswitch
[16723]34SITE_NAME = 'unidel.waeup.org'
[16732]35PROVIDER_ACCT = '0213065415'
36PROVIDER_BANK_ID = '47'
[16592]37PROVIDER_ITEM_NAME = 'WAeAC'
[16723]38INSTITUTION_NAME = 'UNIDEL'
[15614]39CURRENCY = '566'
[17998]40GATEWAY_AMT = 300.0
[16736]41#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
42MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi'
[15614]43
[16736]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'
[15614]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
[15756]63    mac = MAC
64    gateway_amt = GATEWAY_AMT
[15614]65
66    def update(self):
[16592]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
[15614]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
[16869]85        xmldict['institution_acct'] = '000000000'
[17330]86        xmldict['institution_bank_id'] = '117'
[15614]87        provider_amt = 0.0
[16850]88        tech_fee = 0.0
[17935]89        union_due = 0.0
[16790]90        if self.context.p_category == 'clearance':
[17913]91            provider_amt = 2000.0
[17599]92            if student.current_mode in ('ug_ft', 'de_ft'):
93                xmldict['institution_acct'] = '1216063205'
[17620]94                tech_fee = 18000.0
[17599]95                xmldict['tech_acct'] = '0092304647'
96                xmldict['tech_bank_id'] = '121'
[17682]97            elif student.current_mode.startswith('dp'):
98                xmldict['institution_acct'] = '1011431799'
[17613]99            if student.faccode in ('PRE', 'JUPEB'):
100                xmldict['institution_acct'] = '1011431799'
[17682]101            elif student.faccode == 'IJMB':
[17613]102                xmldict['institution_acct'] = '0093658062'
[17646]103                xmldict['institution_bank_id'] = '121'
[17620]104            if self.context.p_item == 'Balance':
105                provider_amt = 0.0
106                tech_fee = 0.0
[17330]107        elif self.context.p_category == 'schoolfee':
[17938]108            provider_amt = 7000.0
109            tech_fee = 3000.0
[16869]110            xmldict['institution_acct'] = '1011739172'
[18106]111            xmldict['tech_acct'] = '1130003817'
112            xmldict['tech_bank_id'] = '117'
[17935]113            xmldict['union_acct'] = '1011438901'
114            xmldict['union_bank_id'] = '117'
[17960]115            if student.current_mode == 'ug_ft':
116                union_due = 1500.0
[17682]117            if student.current_mode.startswith('dp'):
118                xmldict['institution_acct'] = '2001627961'
119                xmldict['institution_bank_id'] = '8'
[17952]120            elif student.current_mode in ('pde', 'trc'):
[17949]121                xmldict['institution_acct'] = '1010957205'
122                xmldict['institution_bank_id'] = '117'
123            elif student.faccode in ('PRE', 'JUPEB'):
[17117]124                xmldict['institution_acct'] = '2001627961'
125                xmldict['institution_bank_id'] = '8'
[17682]126            elif student.faccode == 'DELSU':
[17459]127                xmldict['institution_acct'] = '1011036493'
[17682]128            elif student.faccode == 'NCE':
[17399]129                xmldict['institution_acct'] = '1011274462'
[17347]130                provider_amt = 4000.0
131                tech_fee = 0.0
[17682]132            elif student.faccode == 'IJMB':
[17478]133                xmldict['institution_acct'] = '0093658062'
[17646]134                xmldict['institution_bank_id'] = '121'
[17931]135            elif student.faccode in ('FMED', 'FBM', 'FLW'):
[17682]136                xmldict['institution_acct'] = '1011274462'
[17715]137            elif student.certcode == 'DFFPA':
138                xmldict['institution_acct'] = '2001627961'
139                xmldict['institution_bank_id'] = '8'
140                provider_amt = 4000.0
141                tech_fee = 0.0
[17620]142            if self.context.p_item == 'Balance':
143                provider_amt = 0.0
144                tech_fee = 0.0
[18026]145                union_due = 0.0
[17839]146        elif self.context.p_category.startswith('ijmb'):
147                xmldict['institution_acct'] = '0093658062'
148                xmldict['institution_bank_id'] = '121'
[17330]149        elif self.context.p_category == 'hostel_maintenance':
[16869]150            xmldict['institution_acct'] = '1012551384'
[17330]151        elif self.context.p_category == 'med_reg':
152            xmldict['institution_acct'] = '1011265606'
[17698]153        elif self.context.p_category == 'teaching_practice':
154            xmldict['institution_acct'] = '1005399320'
155            xmldict['institution_bank_id'] = '8'
[18046]156        elif self.context.p_category == 'siwes':
157            xmldict['institution_acct'] = '2000092025'
158            xmldict['institution_bank_id'] = '8'
[17894]159        elif self.context.p_category.startswith('transcript'):
[17891]160            xmldict['institution_acct'] = '0010494552'
161            xmldict['institution_bank_id'] = '129'
162            provider_amt = 2000.0
[18143]163        elif self.context.p_category.startswith('trcn'):
164            xmldict['institution_acct'] = '1010957205'
165            xmldict['institution_bank_id'] = '117'
166            provider_amt = 500.0
[17933]167        elif self.context.p_category.startswith('union'):
168            xmldict['institution_acct'] = '1011438901'
[16736]169        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
[16850]170        # Already now it becomes an Interswitch payment. We set the net amount
171        # and add gateway amount and other surcharges.
172        if not self.context.r_company:
173            self.context.r_company = u'interswitch'
174            self.context.net_amt = self.context.amount_auth
175            self.context.gateway_amt = self.gateway_amt
176            self.context.amount_auth += self.gateway_amt
177            self.context.provider_amt = provider_amt
178            self.context.amount_auth += provider_amt
179            self.context.amount_auth += tech_fee
[17935]180            self.context.amount_auth += union_due
[15614]181        xmldict['provider_amt'] = 100 * provider_amt
[16849]182        xmldict['tech_fee'] = 100 * tech_fee
[17935]183        xmldict['union_due'] = 100 * union_due
[15614]184        xmldict['institution_item_name'] = self.context.category
185        xmldict['institution_name'] = INSTITUTION_NAME
[15756]186        xmldict['institution_amt'] = 100 * self.context.net_amt
[17935]187        xmldict['item_id'] = 1
[17937]188        xmltext = """
189<payment_item_detail>
[15614]190<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
[17935]191<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" />
192""" % xmldict
193        if provider_amt:
194            xmldict['item_id'] += 1
[17937]195            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" />
[17935]196""" % xmldict
197        if tech_fee:
198            xmldict['item_id'] += 1
[17937]199            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" />
[17935]200""" % xmldict
201        if union_due:
202            xmldict['item_id'] += 1
[17937]203            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" />
204""" % xmldict
205        xmltext +="""</item_details>
206</payment_item_detail>
207"""
208        self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext
[15614]209        self.context.provider_amt = provider_amt
[15756]210        self.amount_auth = int(100 * self.context.amount_auth)
[15614]211        hashargs = (
212            self.context.p_id +
213            PRODUCT_ID +
214            self.pay_item_id +
215            str(int(self.amount_auth)) +
216            self.site_redirect_url +
217            self.mac)
218        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
219        return
220
221class CustomInterswitchPageApplicant(InterswitchPageApplicant):
222    """ View which sends a POST request to the Interswitch
223    CollegePAY payment gateway.
224    """
225    grok.context(ICustomApplicantOnlinePayment)
226    action = POST_ACTION
227    site_name = SITE_NAME
228    currency = CURRENCY
[16736]229    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
[15614]230    product_id = PRODUCT_ID
231    mac = MAC
[15756]232    gateway_amt = GATEWAY_AMT
[15614]233
234    def update(self):
[16592]235        if not 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
[15614]240        error = self.init_update()
241        if error:
242            self.flash(error, type='danger')
243            self.redirect(self.url(self.context, '@@index'))
244            return
[15756]245        # Already now it becomes an Interswitch payment. We set the net amount
246        # and add the gateway amount.
247        if not self.context.r_company:
248            self.context.net_amt = self.context.amount_auth
249            self.context.amount_auth += self.gateway_amt
250            self.context.gateway_amt = self.gateway_amt
251            self.context.r_company = u'interswitch'
[15614]252        xmldict = {}
[16733]253        provider_amt = 250.0
[16731]254        xmldict['institution_acct'] = '1216063205'
255        xmldict['institution_bank_id'] = '117'
[17114]256        if self.context.__parent__.__parent__.prefix in (
[17278]257                                    'pre', 'jupeb', 'dpft', 'dppt',
[17506]258                                    'ugpt', 'ijmb', 'df'):
[17059]259            xmldict['institution_acct'] = '1011431799'
260            xmldict['institution_bank_id'] = '117'
261            provider_amt = 500.0           
[17478]262        if self.context.__parent__.__parent__.prefix in ('ijmb',):
263            xmldict['institution_acct'] = '0093658062'
264            xmldict['institution_bank_id'] = '121'
[17952]265        if self.context.__parent__.__parent__.prefix in ('pde', 'trcdeg', 'trcnce'):
[17949]266            xmldict['institution_acct'] = '1010957205'
267            xmldict['institution_bank_id'] = '117'
268            provider_amt = 500.0
[15614]269        xmldict['detail_ref'] = self.context.p_id
270        xmldict['provider_amt'] = 100 * provider_amt
271        xmldict['provider_acct'] = PROVIDER_ACCT
272        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
273        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
274        xmldict['institution_item_name'] = self.context.category
275        xmldict['institution_name'] = INSTITUTION_NAME
[15756]276        xmldict['institution_amt'] = 100 * self.context.net_amt
277        if not self.context.provider_amt:
278            self.context.provider_amt = provider_amt
279            self.context.amount_auth += provider_amt
[15614]280        xmltext = """<payment_item_detail>
281<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
282<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" />
283<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" />
284</item_details>
285</payment_item_detail>""" % xmldict
286        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[15756]287        self.amount_auth = int(100 * self.context.amount_auth)
[15614]288        hashargs = (
289            self.context.p_id +
290            PRODUCT_ID +
291            self.pay_item_id +
292            str(int(self.amount_auth)) +
293            self.site_redirect_url +
294            self.mac)
295        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
296        return
297
298class CustomInterswitchPaymentRequestWebservicePageStudent(
299    InterswitchPaymentRequestWebservicePageStudent):
300    """Request webservice view for the CollegePAY gateway
301    """
302    grok.context(ICustomStudentOnlinePayment)
303    product_id = PRODUCT_ID
304    gateway_host = HOST
305    gateway_url = URL
306    mac = MAC
307
308class CustomInterswitchPaymentVerifyWebservicePageStudent(
309    InterswitchPaymentVerifyWebservicePageStudent):
310    """Payment verify view for the CollegePAY gateway
311    """
312    grok.context(ICustomStudentOnlinePayment)
313    product_id = PRODUCT_ID
314    gateway_host = HOST
315    gateway_url = URL
316    mac = MAC
317
318class CustomInterswitchPaymentRequestWebservicePageApplicant(
319    InterswitchPaymentRequestWebservicePageApplicant):
320    """Request webservice view for the CollegePAY gateway
321    """
322    grok.context(ICustomApplicantOnlinePayment)
323    product_id = PRODUCT_ID
324    gateway_host = HOST
325    gateway_url = URL
326    mac = MAC
327
328class CustomInterswitchPaymentVerifyWebservicePageApplicant(
329    InterswitchPaymentVerifyWebservicePageApplicant):
330    """Payment verify view for the CollegePAY gateway
331    """
332    grok.context(ICustomApplicantOnlinePayment)
333    product_id = PRODUCT_ID
334    gateway_host = HOST
335    gateway_url = URL
[16723]336    mac = MAC
337
338# PAYDirect
339
340from kofacustom.nigeria.interswitch.paydirectbrowser import (
341    PAYDirectPageStudent, PAYDirectPageApplicant,
342    StudentRefNumberSlip, ApplicantRefNumberSlip,
343    )
344
345from kofacustom.nigeria.interswitch.tests import (
346    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
347
348#PAYDIRECT_HOST = 'orion.interswitchng.com'
349#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
350#MERCHANT_ID = ''
351
352class CustomPAYDirectPageStudent(PAYDirectPageStudent):
353    """Inform student how to proceed
354    """
355    grok.context(ICustomStudentOnlinePayment)
356    gateway_amt = GATEWAY_AMT
357    merchant_id = MERCHANT_ID
358    gateway_url = PAYDIRECT_URL
359    gateway_host = PAYDIRECT_HOST
360    https = True
361
362class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
363    """ Inform applicant how to proceed.
364    """
365    grok.context(ICustomApplicantOnlinePayment)
366    gateway_amt = GATEWAY_AMT
367    merchant_id = MERCHANT_ID
368    gateway_url = PAYDIRECT_URL
369    gateway_host = PAYDIRECT_HOST
370    https = True
371
372class CustomStudentRefNumberSlip(StudentRefNumberSlip):
373    """Deliver a PDF slip of the context.
374    """
375    merchant_id = MERCHANT_ID
376
377class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
378    """Deliver a PDF slip of the context.
379    """
380    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.