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

Last change on this file since 18362 was 18362, checked in by Henrik Bettermann, 10 days ago

New payment category.

  • Property svn:keywords set to Id
File size: 17.2 KB
Line 
1## $Id: browser.py 18362 2026-11-13 08:43:06Z 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                                         ):
167            xmldict['institution_acct'] = '2000092025'
168            xmldict['institution_bank_id'] = '8'
169        elif self.context.p_category.startswith('plagtest'):
170            xmldict['institution_acct'] = '2000092025'
171            xmldict['institution_bank_id'] = '8'
172        elif self.context.p_category.startswith('transcript'):
173            xmldict['institution_acct'] = '2000092025'
174            xmldict['institution_bank_id'] = '8'
175            provider_amt = 2000.0
176        elif self.context.p_category.startswith('trcn'):
177            xmldict['institution_acct'] = '2000092025'
178            xmldict['institution_bank_id'] = '8'
179            provider_amt = 500.0
180        elif self.context.p_category.endswith('_ced'):
181            xmldict['institution_acct'] = '2000092025'
182            xmldict['institution_bank_id'] = '8'
183        elif self.context.p_category.startswith('union'):
184            xmldict['institution_acct'] = '1011438901'
185        elif self.context.p_category.startswith('late_reg'):
186            xmldict['institution_acct'] = '2000092025'
187            xmldict['institution_bank_id'] = '8'
188        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
189        # Already now it becomes an Interswitch payment. We set the net amount
190        # and add gateway amount and other surcharges.
191        if not self.context.r_company:
192            self.context.r_company = u'interswitch'
193            self.context.net_amt = self.context.amount_auth
194            self.context.gateway_amt = self.gateway_amt
195            self.context.amount_auth += self.gateway_amt
196            self.context.provider_amt = provider_amt
197            self.context.amount_auth += provider_amt
198            self.context.amount_auth += tech_fee
199            self.context.amount_auth += union_due
200        xmldict['provider_amt'] = 100 * provider_amt
201        xmldict['tech_fee'] = 100 * tech_fee
202        xmldict['union_due'] = 100 * union_due
203        xmldict['institution_item_name'] = self.context.category
204        xmldict['institution_name'] = INSTITUTION_NAME
205        xmldict['institution_amt'] = 100 * self.context.net_amt
206        xmldict['item_id'] = 1
207        xmltext = """
208<payment_item_detail>
209<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
210<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" />
211""" % xmldict
212        if provider_amt:
213            xmldict['item_id'] += 1
214            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" />
215""" % xmldict
216        if tech_fee:
217            xmldict['item_id'] += 1
218            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" />
219""" % xmldict
220        if union_due:
221            xmldict['item_id'] += 1
222            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" />
223""" % xmldict
224        xmltext +="""</item_details>
225</payment_item_detail>
226"""
227        self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext
228        self.context.provider_amt = provider_amt
229        self.amount_auth = int(100 * self.context.amount_auth)
230        hashargs = (
231            self.context.p_id +
232            PRODUCT_ID +
233            self.pay_item_id +
234            str(int(self.amount_auth)) +
235            self.site_redirect_url +
236            self.mac)
237        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
238        return
239
240class CustomInterswitchPageApplicant(InterswitchPageApplicant):
241    """ View which sends a POST request to the Interswitch
242    CollegePAY payment gateway.
243    """
244    grok.context(ICustomApplicantOnlinePayment)
245    action = POST_ACTION
246    site_name = SITE_NAME
247    currency = CURRENCY
248    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
249    product_id = PRODUCT_ID
250    mac = MAC
251    gateway_amt = GATEWAY_AMT
252
253    def update(self):
254        if not module_activated(
255            self.context.__parent__.__parent__.year, self.context):
256            self.flash(_('Forbidden'), type='danger')
257            self.redirect(self.url(self.context, '@@index'))
258            return
259        error = self.init_update()
260        if error:
261            self.flash(error, type='danger')
262            self.redirect(self.url(self.context, '@@index'))
263            return
264        # Already now it becomes an Interswitch payment. We set the net amount
265        # and add the gateway amount.
266        if not self.context.r_company:
267            self.context.net_amt = self.context.amount_auth
268            self.context.amount_auth += self.gateway_amt
269            self.context.gateway_amt = self.gateway_amt
270            self.context.r_company = u'interswitch'
271        xmldict = {}
272        provider_amt = 500.0
273        xmldict['institution_acct'] = '2000092025'
274        xmldict['institution_bank_id'] = '8'
275        if self.context.__parent__.__parent__.prefix in (
276                                    'pre', 'jupeb', 'dpft', 'dppt',
277                                    'ugpt', 'ijmb', 'df'):
278            xmldict['institution_acct'] = '2000092025'
279            xmldict['institution_bank_id'] = '8'
280        if self.context.__parent__.__parent__.prefix in ('ijmb',):
281            xmldict['institution_acct'] = '2000092025'
282            xmldict['institution_bank_id'] = '8'
283        if self.context.__parent__.__parent__.prefix in ('pde', 'trcdeg', 'trcnce'):
284            xmldict['institution_acct'] = '2000092025'
285            xmldict['institution_bank_id'] = '8'
286        if self.context.__parent__.__parent__.prefix in ('dsb',):
287            xmldict['institution_acct'] = '2000092025'
288            xmldict['institution_bank_id'] = '8'
289        if self.context.__parent__.__parent__.prefix.startswith('pg'):
290            xmldict['institution_acct'] = '2007464113'
291            xmldict['institution_bank_id'] = '3721'
292        xmldict['detail_ref'] = self.context.p_id
293        xmldict['provider_amt'] = 100 * provider_amt
294        xmldict['provider_acct'] = PROVIDER_ACCT
295        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
296        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
297        xmldict['institution_item_name'] = self.context.category
298        xmldict['institution_name'] = INSTITUTION_NAME
299        xmldict['institution_amt'] = 100 * self.context.net_amt
300        if not self.context.provider_amt:
301            self.context.provider_amt = provider_amt
302            self.context.amount_auth += provider_amt
303        xmltext = """<payment_item_detail>
304<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
305<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" />
306<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" />
307</item_details>
308</payment_item_detail>""" % xmldict
309        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
310        self.amount_auth = int(100 * self.context.amount_auth)
311        hashargs = (
312            self.context.p_id +
313            PRODUCT_ID +
314            self.pay_item_id +
315            str(int(self.amount_auth)) +
316            self.site_redirect_url +
317            self.mac)
318        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
319        return
320
321class CustomInterswitchPaymentRequestWebservicePageStudent(
322    InterswitchPaymentRequestWebservicePageStudent):
323    """Request webservice view for the CollegePAY gateway
324    """
325    grok.context(ICustomStudentOnlinePayment)
326    product_id = PRODUCT_ID
327    gateway_host = HOST
328    gateway_url = URL
329    mac = MAC
330
331class CustomInterswitchPaymentVerifyWebservicePageStudent(
332    InterswitchPaymentVerifyWebservicePageStudent):
333    """Payment verify view for the CollegePAY gateway
334    """
335    grok.context(ICustomStudentOnlinePayment)
336    product_id = PRODUCT_ID
337    gateway_host = HOST
338    gateway_url = URL
339    mac = MAC
340
341class CustomInterswitchPaymentRequestWebservicePageApplicant(
342    InterswitchPaymentRequestWebservicePageApplicant):
343    """Request webservice view for the CollegePAY gateway
344    """
345    grok.context(ICustomApplicantOnlinePayment)
346    product_id = PRODUCT_ID
347    gateway_host = HOST
348    gateway_url = URL
349    mac = MAC
350
351class CustomInterswitchPaymentVerifyWebservicePageApplicant(
352    InterswitchPaymentVerifyWebservicePageApplicant):
353    """Payment verify view for the CollegePAY gateway
354    """
355    grok.context(ICustomApplicantOnlinePayment)
356    product_id = PRODUCT_ID
357    gateway_host = HOST
358    gateway_url = URL
359    mac = MAC
360
361# PAYDirect
362
363from kofacustom.nigeria.interswitch.paydirectbrowser import (
364    PAYDirectPageStudent, PAYDirectPageApplicant,
365    StudentRefNumberSlip, ApplicantRefNumberSlip,
366    )
367
368from kofacustom.nigeria.interswitch.tests import (
369    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
370
371#PAYDIRECT_HOST = 'orion.interswitchng.com'
372#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
373#MERCHANT_ID = ''
374
375class CustomPAYDirectPageStudent(PAYDirectPageStudent):
376    """Inform student how to proceed
377    """
378    grok.context(ICustomStudentOnlinePayment)
379    gateway_amt = GATEWAY_AMT
380    merchant_id = MERCHANT_ID
381    gateway_url = PAYDIRECT_URL
382    gateway_host = PAYDIRECT_HOST
383    https = True
384
385class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
386    """ Inform applicant how to proceed.
387    """
388    grok.context(ICustomApplicantOnlinePayment)
389    gateway_amt = GATEWAY_AMT
390    merchant_id = MERCHANT_ID
391    gateway_url = PAYDIRECT_URL
392    gateway_host = PAYDIRECT_HOST
393    https = True
394
395class CustomStudentRefNumberSlip(StudentRefNumberSlip):
396    """Deliver a PDF slip of the context.
397    """
398    merchant_id = MERCHANT_ID
399
400class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
401    """Deliver a PDF slip of the context.
402    """
403    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.