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

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

Add payment categories.

  • Property svn:keywords set to Id
File size: 17.4 KB
Line 
1## $Id: browser.py 18365 2026-11-19 09:51:31Z 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.is_postgrad:
99                xmldict['institution_acct'] = '2007464113'
100                xmldict['institution_bank_id'] = '3721'
101            if student.current_mode.startswith('dp'):
102                xmldict['institution_acct'] = '1011431799'
103            if student.faccode in ('PRE', 'JUPEB'):
104                xmldict['institution_acct'] = '1011431799'
105            elif student.faccode == 'IJMB':
106                xmldict['institution_acct'] = '2000092025'
107                xmldict['institution_bank_id'] = '8'
108            if self.context.p_item == 'Balance':
109                provider_amt = 0.0
110                tech_fee = 0.0
111        elif self.context.p_category == 'schoolfee':
112            provider_amt = 7000.0
113            tech_fee = 3000.0
114            xmldict['institution_acct'] = '1011739172'
115            #xmldict['tech_acct'] = '1130003817'
116            #xmldict['tech_bank_id'] = '117'
117            xmldict['union_acct'] = '1011438901'
118            xmldict['union_bank_id'] = '117'
119            if student.current_mode == 'ug_ft':
120                union_due = 1500.0
121            if student.is_postgrad:
122                xmldict['institution_acct'] = '2007464113'
123                xmldict['institution_bank_id'] = '3721'
124            elif student.current_mode.startswith('dp'):
125                xmldict['institution_acct'] = '2000092025'
126                xmldict['institution_bank_id'] = '8'
127            elif student.current_mode in ('pde', 'trc'):
128                xmldict['institution_acct'] = '2000092025'
129                xmldict['institution_bank_id'] = '8'
130            elif student.faccode in ('PRE', 'JUPEB'):
131                xmldict['institution_acct'] = '2000092025'
132                xmldict['institution_bank_id'] = '8'
133            elif student.faccode == 'DELSU':
134                xmldict['institution_acct'] = '2000092025'
135            elif student.faccode == 'NCE':
136                xmldict['institution_acct'] = '1011274462'
137                provider_amt = 4000.0
138                tech_fee = 0.0
139            elif student.faccode == 'IJMB':
140                xmldict['institution_acct'] = '2000092025'
141                xmldict['institution_bank_id'] = '8'
142            elif student.faccode in ('FMED', 'FBM', 'FLW'):
143                xmldict['institution_acct'] = '1011739172'
144            elif student.certcode == 'DFFPA':
145                xmldict['institution_acct'] = '2000092025'
146                xmldict['institution_bank_id'] = '8'
147                provider_amt = 4000.0
148                tech_fee = 0.0
149            if self.context.p_item == 'Balance':
150                provider_amt = 0.0
151                tech_fee = 0.0
152                union_due = 0.0
153            xmldict['tech_acct'] = xmldict['institution_acct']
154            xmldict['tech_bank_id'] = xmldict['institution_bank_id']
155        elif self.context.p_category.startswith('ijmb'):
156                xmldict['institution_acct'] = '2000092025'
157                xmldict['institution_bank_id'] = '8'
158        elif self.context.p_category == 'hostel_maintenance':
159            xmldict['institution_acct'] = '1012551384'
160        elif self.context.p_category == 'med_reg':
161            xmldict['institution_acct'] = '1011265606'
162        elif self.context.p_category in ('teaching_practice',
163                                         'grad_clear',
164                                         'convocation',
165                                         'siwes',
166                                         'marine_1',
167                                         'marine_2',
168                                         ):
169            xmldict['institution_acct'] = '2000092025'
170            xmldict['institution_bank_id'] = '8'
171        elif self.context.p_category.startswith('plagtest'):
172            xmldict['institution_acct'] = '2000092025'
173            xmldict['institution_bank_id'] = '8'
174        elif self.context.p_category.startswith('transcript'):
175            xmldict['institution_acct'] = '2000092025'
176            xmldict['institution_bank_id'] = '8'
177            provider_amt = 2000.0
178        elif self.context.p_category.startswith('trcn'):
179            xmldict['institution_acct'] = '2000092025'
180            xmldict['institution_bank_id'] = '8'
181            provider_amt = 500.0
182        elif self.context.p_category.endswith('_ced'):
183            xmldict['institution_acct'] = '2000092025'
184            xmldict['institution_bank_id'] = '8'
185        elif self.context.p_category.startswith('union'):
186            xmldict['institution_acct'] = '1011438901'
187        elif self.context.p_category.startswith('late_reg'):
188            xmldict['institution_acct'] = '2000092025'
189            xmldict['institution_bank_id'] = '8'
190        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
191        # Already now it becomes an Interswitch payment. We set the net amount
192        # and add gateway amount and other surcharges.
193        if not self.context.r_company:
194            self.context.r_company = u'interswitch'
195            self.context.net_amt = self.context.amount_auth
196            self.context.gateway_amt = self.gateway_amt
197            self.context.amount_auth += self.gateway_amt
198            self.context.provider_amt = provider_amt
199            self.context.amount_auth += provider_amt
200            self.context.amount_auth += tech_fee
201            self.context.amount_auth += union_due
202        xmldict['provider_amt'] = 100 * provider_amt
203        xmldict['tech_fee'] = 100 * tech_fee
204        xmldict['union_due'] = 100 * union_due
205        xmldict['institution_item_name'] = self.context.category
206        xmldict['institution_name'] = INSTITUTION_NAME
207        xmldict['institution_amt'] = 100 * self.context.net_amt
208        xmldict['item_id'] = 1
209        xmltext = """
210<payment_item_detail>
211<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
212<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" />
213""" % xmldict
214        if provider_amt:
215            xmldict['item_id'] += 1
216            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" />
217""" % xmldict
218        if tech_fee:
219            xmldict['item_id'] += 1
220            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" />
221""" % xmldict
222        if union_due:
223            xmldict['item_id'] += 1
224            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" />
225""" % xmldict
226        xmltext +="""</item_details>
227</payment_item_detail>
228"""
229        self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext
230        self.context.provider_amt = provider_amt
231        self.amount_auth = int(100 * self.context.amount_auth)
232        hashargs = (
233            self.context.p_id +
234            PRODUCT_ID +
235            self.pay_item_id +
236            str(int(self.amount_auth)) +
237            self.site_redirect_url +
238            self.mac)
239        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
240        return
241
242class CustomInterswitchPageApplicant(InterswitchPageApplicant):
243    """ View which sends a POST request to the Interswitch
244    CollegePAY payment gateway.
245    """
246    grok.context(ICustomApplicantOnlinePayment)
247    action = POST_ACTION
248    site_name = SITE_NAME
249    currency = CURRENCY
250    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
251    product_id = PRODUCT_ID
252    mac = MAC
253    gateway_amt = GATEWAY_AMT
254
255    def update(self):
256        if not module_activated(
257            self.context.__parent__.__parent__.year, self.context):
258            self.flash(_('Forbidden'), type='danger')
259            self.redirect(self.url(self.context, '@@index'))
260            return
261        error = self.init_update()
262        if error:
263            self.flash(error, type='danger')
264            self.redirect(self.url(self.context, '@@index'))
265            return
266        # Already now it becomes an Interswitch payment. We set the net amount
267        # and add the gateway amount.
268        if not self.context.r_company:
269            self.context.net_amt = self.context.amount_auth
270            self.context.amount_auth += self.gateway_amt
271            self.context.gateway_amt = self.gateway_amt
272            self.context.r_company = u'interswitch'
273        xmldict = {}
274        provider_amt = 500.0
275        xmldict['institution_acct'] = '2000092025'
276        xmldict['institution_bank_id'] = '8'
277        if self.context.__parent__.__parent__.prefix in (
278                                    'pre', 'jupeb', 'dpft', 'dppt',
279                                    'ugpt', 'ijmb', 'df'):
280            xmldict['institution_acct'] = '2000092025'
281            xmldict['institution_bank_id'] = '8'
282        if self.context.__parent__.__parent__.prefix in ('ijmb',):
283            xmldict['institution_acct'] = '2000092025'
284            xmldict['institution_bank_id'] = '8'
285        if self.context.__parent__.__parent__.prefix in ('pde', 'trcdeg', 'trcnce'):
286            xmldict['institution_acct'] = '2000092025'
287            xmldict['institution_bank_id'] = '8'
288        if self.context.__parent__.__parent__.prefix in ('dsb',):
289            xmldict['institution_acct'] = '2000092025'
290            xmldict['institution_bank_id'] = '8'
291        if self.context.__parent__.__parent__.prefix.startswith('pg'):
292            xmldict['institution_acct'] = '2007464113'
293            xmldict['institution_bank_id'] = '3721'
294        xmldict['detail_ref'] = self.context.p_id
295        xmldict['provider_amt'] = 100 * provider_amt
296        xmldict['provider_acct'] = PROVIDER_ACCT
297        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
298        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
299        xmldict['institution_item_name'] = self.context.category
300        xmldict['institution_name'] = INSTITUTION_NAME
301        xmldict['institution_amt'] = 100 * self.context.net_amt
302        if not self.context.provider_amt:
303            self.context.provider_amt = provider_amt
304            self.context.amount_auth += provider_amt
305        xmltext = """<payment_item_detail>
306<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
307<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" />
308<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" />
309</item_details>
310</payment_item_detail>""" % xmldict
311        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
312        self.amount_auth = int(100 * self.context.amount_auth)
313        hashargs = (
314            self.context.p_id +
315            PRODUCT_ID +
316            self.pay_item_id +
317            str(int(self.amount_auth)) +
318            self.site_redirect_url +
319            self.mac)
320        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
321        return
322
323class CustomInterswitchPaymentRequestWebservicePageStudent(
324    InterswitchPaymentRequestWebservicePageStudent):
325    """Request webservice view for the CollegePAY gateway
326    """
327    grok.context(ICustomStudentOnlinePayment)
328    product_id = PRODUCT_ID
329    gateway_host = HOST
330    gateway_url = URL
331    mac = MAC
332
333class CustomInterswitchPaymentVerifyWebservicePageStudent(
334    InterswitchPaymentVerifyWebservicePageStudent):
335    """Payment verify view for the CollegePAY gateway
336    """
337    grok.context(ICustomStudentOnlinePayment)
338    product_id = PRODUCT_ID
339    gateway_host = HOST
340    gateway_url = URL
341    mac = MAC
342
343class CustomInterswitchPaymentRequestWebservicePageApplicant(
344    InterswitchPaymentRequestWebservicePageApplicant):
345    """Request webservice view for the CollegePAY gateway
346    """
347    grok.context(ICustomApplicantOnlinePayment)
348    product_id = PRODUCT_ID
349    gateway_host = HOST
350    gateway_url = URL
351    mac = MAC
352
353class CustomInterswitchPaymentVerifyWebservicePageApplicant(
354    InterswitchPaymentVerifyWebservicePageApplicant):
355    """Payment verify view for the CollegePAY gateway
356    """
357    grok.context(ICustomApplicantOnlinePayment)
358    product_id = PRODUCT_ID
359    gateway_host = HOST
360    gateway_url = URL
361    mac = MAC
362
363# PAYDirect
364
365from kofacustom.nigeria.interswitch.paydirectbrowser import (
366    PAYDirectPageStudent, PAYDirectPageApplicant,
367    StudentRefNumberSlip, ApplicantRefNumberSlip,
368    )
369
370from kofacustom.nigeria.interswitch.tests import (
371    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
372
373#PAYDIRECT_HOST = 'orion.interswitchng.com'
374#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
375#MERCHANT_ID = ''
376
377class CustomPAYDirectPageStudent(PAYDirectPageStudent):
378    """Inform student how to proceed
379    """
380    grok.context(ICustomStudentOnlinePayment)
381    gateway_amt = GATEWAY_AMT
382    merchant_id = MERCHANT_ID
383    gateway_url = PAYDIRECT_URL
384    gateway_host = PAYDIRECT_HOST
385    https = True
386
387class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
388    """ Inform applicant how to proceed.
389    """
390    grok.context(ICustomApplicantOnlinePayment)
391    gateway_amt = GATEWAY_AMT
392    merchant_id = MERCHANT_ID
393    gateway_url = PAYDIRECT_URL
394    gateway_host = PAYDIRECT_HOST
395    https = True
396
397class CustomStudentRefNumberSlip(StudentRefNumberSlip):
398    """Deliver a PDF slip of the context.
399    """
400    merchant_id = MERCHANT_ID
401
402class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
403    """Deliver a PDF slip of the context.
404    """
405    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.