source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser.py @ 11768

Last change on this file since 11768 was 11768, checked in by Henrik Bettermann, 10 years ago

If the total amount (amount authorized) is less than 2000 Nairas gateway_amt is 1.5% of the amount authorized.

  • Property svn:keywords set to Id
File size: 19.9 KB
Line 
1## $Id: browser.py 11768 2014-07-23 15:42:39Z 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 zope.interface import Interface
22from zope.component import queryAdapter
23from kofacustom.nigeria.interswitch.browser import (
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentRequestWebservicePageApplicant,
26    InterswitchPageStudent, InterswitchPageApplicant,
27    )
28from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment
29from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment
30from waeup.kwarapoly.interfaces import MessageFactory as _
31
32PRODUCT_ID = '3930'
33SITE_NAME = 'kwarapoly.waeup.org'
34PROVIDER_ACCT = '1010764827'
35PROVIDER_BANK_ID = '117'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'KwaraPoly'
38CURRENCY = '566'
39GATEWAY_AMT = 300.0
40#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
41#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
42
43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
44#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
45
46HOST = 'webpay.interswitchng.com'
47#HOST = 'testwebpay.interswitchng.com'
48
49URL = '/paydirect/services/TransactionQueryWs.asmx'
50#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
51httplib.HTTPConnection.debuglevel = 0
52
53class CustomInterswitchPageStudent(InterswitchPageStudent):
54    """ View which sends a POST request to the Interswitch
55    CollegePAY payment gateway.
56    """
57    grok.context(ICustomStudentOnlinePayment)
58    grok.template('student_goto_interswitch')
59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
63    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
64
65    def interswitch_img_url(self):
66        return interswitch_img_url(self)
67
68    def update(self):
69        error = self.init_update()
70        if error:
71            self.flash(error, type='danger')
72            self.redirect(self.url(self.context, '@@index'))
73            return
74        student = self.student
75        xmldict = self.xmldict
76        # Provider data
77        xmldict['detail_ref'] = self.context.p_id
78        xmldict['provider_acct'] = PROVIDER_ACCT
79        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
80        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
81        # Institution data
82        xmldict['institution_item_name'] = self.category
83        xmldict['institution_name'] = INSTITUTION_NAME
84        xmldict['institution_amt'] = 0.0
85        dalash_amt = 200.0
86        provider_amt = 300.0
87        gateway_amt = GATEWAY_AMT
88        self.pay_item_id = '000'
89        xmldict['institution_acct'] = "7000016724"
90        xmldict['institution_bank_id'] = "9"
91        if self.context.p_category == 'schoolfee':
92            self.pay_item_id = '101'
93            dalash_amt = 1800.0
94            provider_amt = 1200.0
95            if xmldict['faculty'] in ('CPGS',):
96                xmldict['institution_acct'] = "1771586608"    #changed account no. from 1771180233
97                xmldict['institution_bank_id'] = '120'
98            elif xmldict['faculty'] in ('IBAS',):
99                xmldict['institution_acct'] = "2013910271"
100                xmldict['institution_bank_id'] = '8'
101                self.pay_item_id = '107'
102            elif xmldict['faculty'] in ('IETS',):
103                xmldict['institution_acct'] = "2013910271"
104                xmldict['institution_bank_id'] = '8'
105                self.pay_item_id = '109'
106            elif xmldict['faculty'] in ('IFMS',):
107                xmldict['institution_acct'] = "0106259811"
108                xmldict['institution_bank_id'] = '10'
109                self.pay_item_id = '106'
110            elif xmldict['faculty'] in ('ITCH',):
111                xmldict['institution_acct'] = "1771586608"    #changed account no. from 1771180233
112                xmldict['institution_bank_id'] = '120'
113                self.pay_item_id = '110'
114            elif xmldict['faculty'] in ('IICT',):
115                xmldict['institution_acct'] = "2013910271"
116                xmldict['institution_bank_id'] = '8'
117                self.pay_item_id = '108'
118        elif self.context.p_category == 'certificate':
119            self.pay_item_id = '111'
120        elif self.context.p_category == 'state_result':
121            self.pay_item_id = '112'
122        elif self.context.p_category == 'transcript_local':
123            self.pay_item_id = '113'
124        elif self.context.p_category == 'transcript_foreign':
125            self.pay_item_id = '114'
126        elif self.context.p_category == 'ver_result':
127            self.pay_item_id = '115'
128        elif self.context.p_category == 'change_course':
129            self.pay_item_id = '116'
130        elif self.context.p_category == 'change_inst':
131            self.pay_item_id = '117'
132        elif self.context.p_category == 'jamb_reject':
133            self.pay_item_id = '118'
134        elif self.context.p_category == 'cert_of_cert':
135            self.pay_item_id = '119'
136        elif self.context.p_category == 'ref_let':
137            self.pay_item_id = '120'
138        elif self.context.p_category == 'proc_cert':
139            self.pay_item_id = '121'
140        elif self.context.p_category == 'loss_idcard':
141            self.pay_item_id = '122'
142            dalash_amt = 6.0
143            provider_amt = 9.0
144            #gateway_amt = 15.0
145            gateway_amt = round(0.015 * self.context.amount_auth, 2)
146        elif self.context.p_category == 'loss_examcard':
147            self.pay_item_id = '123'
148            dalash_amt = 3.0
149            provider_amt = 4.5
150            #gateway_amt = 7.5
151            gateway_amt = round(0.015 * self.context.amount_auth, 2)
152        elif self.context.p_category == 'loss_result':
153            self.pay_item_id = '124'
154        elif self.context.p_category == 'loss_receipt':
155            self.pay_item_id = '125'
156        elif self.context.p_category == 'loss_clearance':
157            self.pay_item_id = '126'
158        elif self.context.p_category == 'conv_brochure':
159            self.pay_item_id = '127'
160        elif self.context.p_category == 'hnd_certificate':
161            self.pay_item_id = '128'
162        elif self.context.p_category == 'hnd_state_result':
163            self.pay_item_id = '129'
164        elif self.context.p_category == 'hnd_transcript_local':
165            self.pay_item_id = '130'
166        elif self.context.p_category == 'hnd_transcript_foreign':
167            self.pay_item_id = '131'
168        elif self.context.p_category == 'staff_loss_idcard':
169            self.pay_item_id = '132'
170            dalash_amt = 6.0
171            provider_amt = 9.0
172            #gateway_amt = 15.0
173            gateway_amt = round(0.015 * self.context.amount_auth, 2)
174        elif self.context.p_category == 'hnd_conv_brochure':
175            self.pay_item_id = '133'
176        elif self.context.p_category == 'pgd_state_result':
177            self.pay_item_id = '134'
178        elif self.context.p_category == 'pgd_conv_brochure':
179            self.pay_item_id = '135'
180        elif self.context.p_category == 'pgd_certificate':
181            self.pay_item_id = '136'
182        elif self.context.p_category == 'log_book':
183            self.pay_item_id = '137'
184            dalash_amt = 3.0
185            provider_amt = 4.5
186            #gateway_amt = 7.5
187            gateway_amt = round(0.015 * self.context.amount_auth, 2)
188            xmldict['institution_acct'] = "1010508401"
189            xmldict['institution_bank_id'] = '117'
190        elif self.context.p_category == 'pgd_transcript_foreign':
191            self.pay_item_id = '138'
192        elif self.context.p_category == 'pgd_transcript_local':
193            self.pay_item_id = '139'
194        elif self.context.p_category == 'jamb_regularization':
195            self.pay_item_id = '140'
196            xmldict['institution_acct'] = "0838798020"
197            xmldict['institution_bank_id'] = '76'
198        elif 'maintenance' in self.context.p_category:
199            self.pay_item_id = '102'
200            xmldict['institution_acct'] = "0039050937"
201            xmldict['institution_bank_id'] = '31'
202            dalash_amt = 0.0
203            provider_amt = 0.0
204        else:
205            xmldict['institution_acct'] = "0000000000000"
206            xmldict['institution_bank_id'] = '0'
207
208        xmldict['dalash_amt'] = 100 * dalash_amt
209        xmldict['provider_amt'] = 100 * provider_amt
210        xmldict['institution_amt'] = 100 * (
211                self.context.amount_auth - provider_amt -
212                gateway_amt - dalash_amt)
213
214        hashargs = (
215            self.context.p_id +
216            PRODUCT_ID +
217            self.pay_item_id +
218            str(int(self.amount_auth)) +
219            self.site_redirect_url +
220            self.mac)
221        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
222
223        # Interswitch amount is not part of the xml data
224
225        if 'maintenance' in self.context.p_category:
226            xmltext = """<payment_item_detail>
227<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
228<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" />
229</item_details>
230</payment_item_detail>""" % xmldict
231
232        else:
233            xmltext = """<payment_item_detail>
234<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
235<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" />
236<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
237<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
238</item_details>
239</payment_item_detail>""" % xmldict
240
241        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
242        self.context.provider_amt = provider_amt
243        self.context.gateway_amt = gateway_amt
244        self.context.thirdparty_amt = dalash_amt
245        return
246
247class CustomInterswitchPageApplicant(InterswitchPageApplicant):
248    """ View which sends a POST request to the Interswitch
249    CollegePAY payment gateway.
250    """
251    grok.context(ICustomApplicantOnlinePayment)
252    grok.template('applicant_goto_interswitch')
253    action = POST_ACTION
254    site_name = SITE_NAME
255    currency = CURRENCY
256    pay_item_id = '103'
257    product_id = PRODUCT_ID
258    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
259
260    def interswitch_img_url(self):
261        return interswitch_img_url(self)
262
263    def update(self):
264        super(CustomInterswitchPageApplicant, self).update()
265        xmldict = {}
266        provider_amt = 300.0
267        dalash_amt = 200.0
268        gateway_amt = GATEWAY_AMT
269        if self.applicant.applicant_id.startswith('hnd'):
270            xmldict['institution_acct'] = '1771440667'
271            xmldict['institution_bank_id'] = '120'
272        elif self.applicant.applicant_id.startswith('nd'):
273            xmldict['institution_acct'] = '1771440667'
274            xmldict['institution_bank_id'] = '120'
275        elif self.applicant.applicant_id.startswith('rmd'):
276            xmldict['institution_acct'] = '1771440667'
277            xmldict['institution_bank_id'] = '120'
278        elif self.applicant.applicant_id.startswith('pgft'):
279            xmldict['institution_acct'] = '7000016724'
280            xmldict['institution_bank_id'] = '9'
281        elif self.applicant.applicant_id.startswith('prejambites'):
282            xmldict['institution_acct'] = '0106259811'
283            xmldict['institution_bank_id'] = '10'
284            self.pay_item_id = '104'
285            provider_amt = 0.0
286            dalash_amt = 0.0
287        elif self.applicant.applicant_id.startswith('pre'):
288            xmldict['institution_acct'] = '2013910271'
289            xmldict['institution_bank_id'] = '8'
290            provider_amt = 0.0
291            dalash_amt = 0.0
292        elif self.applicant.applicant_id.startswith('special'):
293            xmldict['institution_acct'] = "7000016724"
294            xmldict['institution_bank_id'] = '9'
295            if self.applicant.special_application == 'certificate':
296                self.pay_item_id = '111'
297            elif self.applicant.special_application == 'state_result':
298                self.pay_item_id = '112'
299            elif self.applicant.special_application == 'transcript_local':
300                self.pay_item_id = '113'
301            elif self.applicant.special_application == 'transcript_foreign':
302                self.pay_item_id = '114'
303            elif self.applicant.special_application == 'ver_result':
304                self.pay_item_id = '115'
305            elif self.applicant.special_application == 'change_course':
306                self.pay_item_id = '116'
307            elif self.applicant.special_application == 'change_inst':
308                self.pay_item_id = '117'
309            elif self.applicant.special_application == 'jamb_reject':
310                self.pay_item_id = '118'
311            elif self.applicant.special_application == 'cert_of_cert':
312                self.pay_item_id = '119'
313            elif self.applicant.special_application == 'ref_let':
314                self.pay_item_id = '120'
315            elif self.applicant.special_application == 'proc_cert':
316                self.pay_item_id = '121'
317            elif self.applicant.special_application == 'loss_idcard':
318                self.pay_item_id = '122'
319                dalash_amt = 6.0
320                provider_amt = 9.0
321                #gateway_amt = 15.0
322                gateway_amt = round(0.015 * self.context.amount_auth, 2)
323            elif self.applicant.special_application == 'loss_examcard':
324                self.pay_item_id = '123'
325                dalash_amt = 3.0
326                provider_amt = 4.5
327                #gateway_amt = 7.5
328                gateway_amt = round(0.015 * self.context.amount_auth, 2)
329            elif self.applicant.special_application == 'loss_result':
330                self.pay_item_id = '124'
331            elif self.applicant.special_application == 'loss_receipt':
332                self.pay_item_id = '125'
333            elif self.applicant.special_application == 'loss_clearance':
334                self.pay_item_id = '126'
335            elif self.applicant.special_application == 'conv_brochure':
336                self.pay_item_id = '127'
337            elif self.applicant.special_application == 'hnd_certificate':
338                self.pay_item_id = '128'
339            elif self.applicant.special_application == 'hnd_state_result':
340                self.pay_item_id = '129'
341            elif self.applicant.special_application == 'hnd_transcript_local':
342                self.pay_item_id = '130'
343            elif self.applicant.special_application == 'hnd_transcript_foreign':
344                self.pay_item_id = '131'
345            elif self.applicant.special_application == 'staff_loss_idcard':
346                self.pay_item_id = '132'
347                dalash_amt = 6.0
348                provider_amt = 9.0
349                #gateway_amt = 15.0
350                gateway_amt = round(0.015 * self.context.amount_auth, 2)
351            elif self.context.p_category == 'hnd_conv_brochure':
352                self.pay_item_id = '133'
353            elif self.context.p_category == 'pgd_state_result':
354                self.pay_item_id = '134'
355            elif self.context.p_category == 'pgd_conv_brochure':
356                self.pay_item_id = '135'
357            elif self.context.p_category == 'pgd_certificate':
358                self.pay_item_id = '136'
359            elif self.context.p_category == 'log_book':
360                self.pay_item_id = '137'
361                dalash_amt = 3.0
362                provider_amt = 4.5
363                #gateway_amt = 7.5
364                gateway_amt = round(0.015 * self.context.amount_auth, 2)
365                xmldict['institution_acct'] = "1010508401"
366                xmldict['institution_bank_id'] = '117'
367            elif self.context.p_category == 'pgd_transcript_foreign':
368                self.pay_item_id = '138'
369            elif self.context.p_category == 'pgd_transcript_local':
370                self.pay_item_id = '139'
371            elif self.context.p_category == 'jamb_regularization':
372                self.pay_item_id = '140'
373                xmldict['institution_acct'] = "0838798020"
374                xmldict['institution_bank_id'] = '76'
375            else:
376                xmldict['institution_acct'] = '00000000000'
377                xmldict['institution_bank_id'] = '00'
378        else:
379            xmldict['institution_acct'] = '00000000000'
380            xmldict['institution_bank_id'] = '00'
381        xmldict['dalash_amt'] = 100 * dalash_amt
382        xmldict['detail_ref'] = self.context.p_id
383        xmldict['provider_amt'] = 100 * provider_amt
384        xmldict['provider_acct'] = PROVIDER_ACCT
385        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
386        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
387        xmldict['institution_amt'] = 100 * (
388            self.context.amount_auth - provider_amt - gateway_amt - dalash_amt)
389        xmldict['institution_item_name'] = self.category
390        xmldict['institution_name'] = INSTITUTION_NAME
391
392        hashargs = (
393            self.context.p_id +
394            PRODUCT_ID +
395            self.pay_item_id +
396            str(int(self.amount_auth)) +
397            self.site_redirect_url +
398            self.mac)
399        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
400
401        # Interswitch amount is not part of the xml data
402
403        if not self.applicant.applicant_id.startswith('pre'):
404            xmltext = """<payment_item_detail>
405<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
406<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" />
407<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
408<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
409</item_details>
410</payment_item_detail>""" % xmldict
411
412        else:
413            xmltext = """<payment_item_detail>
414<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
415<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" />
416</item_details>
417</payment_item_detail>""" % xmldict
418
419        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
420        self.context.provider_amt = provider_amt
421        self.context.gateway_amt = gateway_amt
422        self.context.thirdparty_amt = dalash_amt
423        return
424
425class CustomInterswitchPaymentRequestWebservicePageStudent(
426    InterswitchPaymentRequestWebservicePageStudent):
427    """ Request webservice view for the CollegePAY gateway
428    """
429    grok.context(ICustomStudentOnlinePayment)
430    product_id = PRODUCT_ID
431    gateway_host = HOST
432    gateway_url = URL
433
434class CustomInterswitchPaymentRequestWebservicePageApplicant(
435    InterswitchPaymentRequestWebservicePageApplicant):
436    """ Request webservice view for the CollegePAY gateway
437    """
438    grok.context(ICustomApplicantOnlinePayment)
439    product_id = PRODUCT_ID
440    gateway_host = HOST
441    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.