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

Last change on this file since 18354 was 18354, checked in by Henrik Bettermann, 4 weeks ago

Addpayment category late_registration.

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