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

Last change on this file since 17937 was 17937, checked in by Henrik Bettermann, 5 weeks ago

Fix xml.

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