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

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

Change account number.

  • Property svn:keywords set to Id
File size: 19.5 KB
Line 
1## $Id: browser.py 11760 2014-07-15 10:44:16Z 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            xmldict['dalash_amt'] = 100 * dalash_amt
144            provider_amt = 9.0
145            gateway_amt = 15.0
146        elif self.context.p_category == 'loss_examcard':
147            self.pay_item_id = '123'
148            dalash_amt = 3.0
149            xmldict['dalash_amt'] = 100 * dalash_amt
150            provider_amt = 4.5
151            gateway_amt = 7.5
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            xmldict['dalash_amt'] = 100 * dalash_amt
172            provider_amt = 9.0
173            gateway_amt = 15.0
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            xmldict['institution_acct'] = "1010508401"
185            xmldict['institution_bank_id'] = '117'
186        elif self.context.p_category == 'pgd_transcript_foreign':
187            self.pay_item_id = '138'
188        elif self.context.p_category == 'pgd_transcript_local':
189            self.pay_item_id = '139'
190        elif self.context.p_category == 'jamb_regularization':
191            self.pay_item_id = '140'
192            xmldict['institution_acct'] = "0838798020"
193            xmldict['institution_bank_id'] = '76'
194        elif 'maintenance' in self.context.p_category:
195            self.pay_item_id = '102'
196            xmldict['institution_acct'] = "0039050937"
197            xmldict['institution_bank_id'] = '31'
198            dalash_amt = 0.0
199            provider_amt = 0.0
200        else:
201            xmldict['institution_acct'] = "0000000000000"
202            xmldict['institution_bank_id'] = '0'
203
204        xmldict['dalash_amt'] = 100 * dalash_amt
205        xmldict['provider_amt'] = 100 * provider_amt
206        xmldict['institution_amt'] = 100 * (
207                self.context.amount_auth - provider_amt -
208                gateway_amt - dalash_amt)
209
210        hashargs = (
211            self.context.p_id +
212            PRODUCT_ID +
213            self.pay_item_id +
214            str(int(self.amount_auth)) +
215            self.site_redirect_url +
216            self.mac)
217        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
218
219        # Interswitch amount is not part of the xml data
220
221        if 'maintenance' in self.context.p_category:
222            xmltext = """<payment_item_detail>
223<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
224<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" />
225</item_details>
226</payment_item_detail>""" % xmldict
227
228        else:
229            xmltext = """<payment_item_detail>
230<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
231<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" />
232<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
233<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" />
234</item_details>
235</payment_item_detail>""" % xmldict
236
237        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
238        self.context.provider_amt = provider_amt
239        self.context.gateway_amt = gateway_amt
240        self.context.thirdparty_amt = dalash_amt
241        return
242
243class CustomInterswitchPageApplicant(InterswitchPageApplicant):
244    """ View which sends a POST request to the Interswitch
245    CollegePAY payment gateway.
246    """
247    grok.context(ICustomApplicantOnlinePayment)
248    grok.template('applicant_goto_interswitch')
249    action = POST_ACTION
250    site_name = SITE_NAME
251    currency = CURRENCY
252    pay_item_id = '103'
253    product_id = PRODUCT_ID
254    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
255
256    def interswitch_img_url(self):
257        return interswitch_img_url(self)
258
259    def update(self):
260        super(CustomInterswitchPageApplicant, self).update()
261        xmldict = {}
262        provider_amt = 300.0
263        dalash_amt = 200.0
264        gateway_amt = GATEWAY_AMT
265        if self.applicant.applicant_id.startswith('hnd'):
266            xmldict['institution_acct'] = '1771440667'
267            xmldict['institution_bank_id'] = '120'
268        elif self.applicant.applicant_id.startswith('nd'):
269            xmldict['institution_acct'] = '1771440667'
270            xmldict['institution_bank_id'] = '120'
271        elif self.applicant.applicant_id.startswith('rmd'):
272            xmldict['institution_acct'] = '1771440667'
273            xmldict['institution_bank_id'] = '120'
274        elif self.applicant.applicant_id.startswith('pgft'):
275            xmldict['institution_acct'] = '7000016724'
276            xmldict['institution_bank_id'] = '9'
277        elif self.applicant.applicant_id.startswith('prejambites'):
278            xmldict['institution_acct'] = '0106259811'
279            xmldict['institution_bank_id'] = '10'
280            self.pay_item_id = '104'
281            provider_amt = 0.0
282            dalash_amt = 0.0
283        elif self.applicant.applicant_id.startswith('pre'):
284            xmldict['institution_acct'] = '2013910271'
285            xmldict['institution_bank_id'] = '8'
286            provider_amt = 0.0
287            dalash_amt = 0.0
288        elif self.applicant.applicant_id.startswith('special'):
289            xmldict['institution_acct'] = "7000016724"
290            xmldict['institution_bank_id'] = '9'
291            if self.applicant.special_application == 'certificate':
292                self.pay_item_id = '111'
293            elif self.applicant.special_application == 'state_result':
294                self.pay_item_id = '112'
295            elif self.applicant.special_application == 'transcript_local':
296                self.pay_item_id = '113'
297            elif self.applicant.special_application == 'transcript_foreign':
298                self.pay_item_id = '114'
299            elif self.applicant.special_application == 'ver_result':
300                self.pay_item_id = '115'
301            elif self.applicant.special_application == 'change_course':
302                self.pay_item_id = '116'
303            elif self.applicant.special_application == 'change_inst':
304                self.pay_item_id = '117'
305            elif self.applicant.special_application == 'jamb_reject':
306                self.pay_item_id = '118'
307            elif self.applicant.special_application == 'cert_of_cert':
308                self.pay_item_id = '119'
309            elif self.applicant.special_application == 'ref_let':
310                self.pay_item_id = '120'
311            elif self.applicant.special_application == 'proc_cert':
312                self.pay_item_id = '121'
313            elif self.applicant.special_application == 'loss_idcard':
314                self.pay_item_id = '122'
315                dalash_amt = 6.0
316                xmldict['dalash_amt'] = 100 * dalash_amt
317                provider_amt = 9.0
318                gateway_amt = 15.0
319            elif self.applicant.special_application == 'loss_examcard':
320                self.pay_item_id = '123'
321                dalash_amt = 3.0
322                xmldict['dalash_amt'] = 100 * dalash_amt
323                provider_amt = 4.5
324                gateway_amt = 7.5
325            elif self.applicant.special_application == 'loss_result':
326                self.pay_item_id = '124'
327            elif self.applicant.special_application == 'loss_receipt':
328                self.pay_item_id = '125'
329            elif self.applicant.special_application == 'loss_clearance':
330                self.pay_item_id = '126'
331            elif self.applicant.special_application == 'conv_brochure':
332                self.pay_item_id = '127'
333            elif self.applicant.special_application == 'hnd_certificate':
334                self.pay_item_id = '128'
335            elif self.applicant.special_application == 'hnd_state_result':
336                self.pay_item_id = '129'
337            elif self.applicant.special_application == 'hnd_transcript_local':
338                self.pay_item_id = '130'
339            elif self.applicant.special_application == 'hnd_transcript_foreign':
340                self.pay_item_id = '131'
341            elif self.applicant.special_application == 'staff_loss_idcard':
342                self.pay_item_id = '132'
343                dalash_amt = 6.0
344                xmldict['dalash_amt'] = 100 * dalash_amt
345                provider_amt = 9.0
346                gateway_amt = 15.0
347            elif self.context.p_category == 'hnd_conv_brochure':
348                self.pay_item_id = '133'
349            elif self.context.p_category == 'pgd_state_result':
350                self.pay_item_id = '134'
351            elif self.context.p_category == 'pgd_conv_brochure':
352                self.pay_item_id = '135'
353            elif self.context.p_category == 'pgd_certificate':
354                self.pay_item_id = '136'
355            elif self.context.p_category == 'log_book':
356                self.pay_item_id = '137'
357                xmldict['institution_acct'] = "1010508401"
358                xmldict['institution_bank_id'] = '117'
359            elif self.context.p_category == 'pgd_transcript_foreign':
360                self.pay_item_id = '138'
361            elif self.context.p_category == 'pgd_transcript_local':
362                self.pay_item_id = '139'
363            elif self.context.p_category == 'jamb_regularization':
364                self.pay_item_id = '140'
365                xmldict['institution_acct'] = "0838798020"
366                xmldict['institution_bank_id'] = '76'
367            else:
368                xmldict['institution_acct'] = '00000000000'
369                xmldict['institution_bank_id'] = '00'
370        else:
371            xmldict['institution_acct'] = '00000000000'
372            xmldict['institution_bank_id'] = '00'
373        xmldict['dalash_amt'] = 100 * dalash_amt
374        xmldict['detail_ref'] = self.context.p_id
375        xmldict['provider_amt'] = 100 * provider_amt
376        xmldict['provider_acct'] = PROVIDER_ACCT
377        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
378        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
379        xmldict['institution_amt'] = 100 * (
380            self.context.amount_auth - provider_amt - gateway_amt - dalash_amt)
381        xmldict['institution_item_name'] = self.category
382        xmldict['institution_name'] = INSTITUTION_NAME
383
384        hashargs = (
385            self.context.p_id +
386            PRODUCT_ID +
387            self.pay_item_id +
388            str(int(self.amount_auth)) +
389            self.site_redirect_url +
390            self.mac)
391        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
392
393        # Interswitch amount is not part of the xml data
394
395        if not self.applicant.applicant_id.startswith('pre'):
396            xmltext = """<payment_item_detail>
397<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
398<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" />
399<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
400<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" />
401</item_details>
402</payment_item_detail>""" % xmldict
403
404        else:
405            xmltext = """<payment_item_detail>
406<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
407<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" />
408</item_details>
409</payment_item_detail>""" % xmldict
410
411        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
412        self.context.provider_amt = provider_amt
413        self.context.gateway_amt = gateway_amt
414        self.context.thirdparty_amt = dalash_amt
415        return
416
417class CustomInterswitchPaymentRequestWebservicePageStudent(
418    InterswitchPaymentRequestWebservicePageStudent):
419    """ Request webservice view for the CollegePAY gateway
420    """
421    grok.context(ICustomStudentOnlinePayment)
422    product_id = PRODUCT_ID
423    gateway_host = HOST
424    gateway_url = URL
425
426class CustomInterswitchPaymentRequestWebservicePageApplicant(
427    InterswitchPaymentRequestWebservicePageApplicant):
428    """ Request webservice view for the CollegePAY gateway
429    """
430    grok.context(ICustomApplicantOnlinePayment)
431    product_id = PRODUCT_ID
432    gateway_host = HOST
433    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.