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

Last change on this file since 14395 was 14329, checked in by Henrik Bettermann, 8 years ago

Change bank account.

  • Property svn:keywords set to Id
File size: 16.9 KB
RevLine 
[7894]1## $Id: browser.py 14329 2016-12-09 06:46:14Z 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##
[7898]18import httplib
[9392]19import hashlib
[7894]20import grok
[9464]21from zope.interface import Interface
[11636]22from zope.component import queryAdapter
[9789]23from kofacustom.nigeria.interswitch.browser import (
[10131]24    InterswitchPaymentRequestWebservicePageStudent,
[11634]25    InterswitchPaymentRequestWebservicePageApplicant,
[13591]26    InterswitchPaymentVerifyWebservicePageApplicant,
27    InterswitchPaymentVerifyWebservicePageStudent,
[11634]28    InterswitchPageStudent, InterswitchPageApplicant,
[9789]29    )
[9347]30from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment
31from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment
32from waeup.kwarapoly.interfaces import MessageFactory as _
[7894]33
[9487]34PRODUCT_ID = '3930'
[10131]35SITE_NAME = 'kwarapoly.waeup.org'
[9387]36PROVIDER_ACCT = '1010764827'
37PROVIDER_BANK_ID = '117'
[8263]38PROVIDER_ITEM_NAME = 'BT Education'
[9347]39INSTITUTION_NAME = 'KwaraPoly'
[7894]40CURRENCY = '566'
[9789]41GATEWAY_AMT = 300.0
[8401]42#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
[8293]43#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
[9392]44
[9487]45POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
46#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[7894]47
[9487]48HOST = 'webpay.interswitchng.com'
49#HOST = 'testwebpay.interswitchng.com'
[9392]50
[9487]51URL = '/paydirect/services/TransactionQueryWs.asmx'
52#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
[7898]53httplib.HTTPConnection.debuglevel = 0
54
[13329]55#All special payments moved to GTBank on 15-10-2015
[11769]56SPECIAL_PAYMENT_PARAMS = {
[14329]57    'certificate': ('111', 200.0, 300.0, '0838798044', '76'),
58    'state_result': ('112', 200.0, 300.0, '0838798044', '76'),
59    'transcript_local': ('113', 200.0, 300.0, '0838798044', '76'),
60    'transcript_foreign': ('114', 200.0, 300.0, '0838798044', '76'),
61    'ver_result': ('115', 200.0, 300.0, '0838798044', '76'),
62    'change_course': ('116', 200.0, 300.0, '0838798044', '76'),
63    'change_inst': ('117', 200.0, 300.0, '0838798044', '76'),
64    'jamb_reject': ('118', 200.0, 300.0, '0838798044', '76'),
65    'cert_of_cert': ('119', 200.0, 300.0, '0838798044', '76'),
66    'ref_let': ('120', 200.0, 300.0, '0838798044', '76'),
67    'proc_cert': ('121', 200.0, 300.0, '0838798044', '76'),
68    'loss_idcard': ('122', 6.0, 9.0, '0838798044', '76'),
69    'loss_examcard': ('123', 3.0, 4.5, '0838798044', '76'),
70    'loss_result': ('124', 200.0, 300.0, '0838798044', '76'),
71    'loss_receipt': ('125', 200.0, 300.0, '0838798044', '76'),
72    'loss_clearance': ('126', 200.0, 300.0, '0838798044', '76'),
73    'conv_brochure': ('127', 200.0, 300.0, '0838798044', '76'),
74    'hnd_certificate': ('128', 200.0, 300.0, '0838798044', '76'),
75    'hnd_state_result': ('129', 200.0, 300.0, '0838798044', '76'),
76    'hnd_transcript_local': ('130', 200.0, 300.0, '0838798044', '76'),
77    'hnd_transcript_foreign': ('131', 200.0, 300.0, '0838798044', '76'),
78    'staff_loss_idcard': ('132', 6.0, 9.0, '0838798044', '76'),
79    'hnd_conv_brochure': ('133', 200.0, 300.0, '0838798044', '76'),
80    'pgd_state_result': ('134', 200.0, 300.0, '0838798044', '76'),
81    'pgd_conv_brochure': ('135', 200.0, 300.0, '0838798044', '76'),
82    'pgd_certificate': ('136', 200.0, 300.0, '0838798044', '76'),
83    'log_book': ('137', 3.0, 4.5, '0838798044', '76'),
84    'pgd_transcript_foreign': ('138', 200.0, 300.0, '0838798044', '76'),
85    'pgd_transcript_local': ('139', 200.0, 300.0, '0838798044', '76'),
86    'jamb_regularization': ('140', 200.0, 300.0, '0838798044', '76'),
87    'utme_registration': ('142', 6.0, 9.0, '0838798044', '76'),
88    'utme_cbt': ('143', 6.0, 9.0, '0838798044', '76'),
89    'nysc_id_card': ('144', 6.0, 9.0, '0838798044', '76'),
90    'ijmb_result': ('147', 200.0, 300.0, '0838798044', '76'),
[11769]91    }
92
[11634]93class CustomInterswitchPageStudent(InterswitchPageStudent):
[7894]94    """ View which sends a POST request to the Interswitch
95    CollegePAY payment gateway.
96    """
[8255]97    grok.context(ICustomStudentOnlinePayment)
[8256]98    grok.template('student_goto_interswitch')
[7894]99    action = POST_ACTION
100    site_name = SITE_NAME
101    currency = CURRENCY
102    product_id = PRODUCT_ID
[9487]103    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
[7894]104
105    def update(self):
[11646]106        error = self.init_update()
107        if error:
108            self.flash(error, type='danger')
109            self.redirect(self.url(self.context, '@@index'))
110            return
111        student = self.student
112        xmldict = self.xmldict
[8263]113        # Provider data
114        xmldict['detail_ref'] = self.context.p_id
115        xmldict['provider_acct'] = PROVIDER_ACCT
116        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
117        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
118        # Institution data
[9616]119        xmldict['institution_item_name'] = self.category
[8263]120        xmldict['institution_name'] = INSTITUTION_NAME
[10736]121        xmldict['institution_amt'] = 0.0
122        dalash_amt = 200.0
123        provider_amt = 300.0
124        gateway_amt = GATEWAY_AMT
[9616]125        self.pay_item_id = '000'
[14329]126        xmldict['institution_acct'] = '0838798044'
127        xmldict['institution_bank_id'] = '76'
[13653]128        if self.context.p_category == 'schoolfee' \
129            or self.context.p_category.startswith('carryover'):
[9616]130            self.pay_item_id = '101'
[9789]131            dalash_amt = 1800.0
[10736]132            provider_amt = 1200.0
[13329]133            if not student.current_mode.endswith('_we'):
[11865]134                if xmldict['faculty'] in ('CPGS',):
[14329]135                    xmldict['institution_acct'] = '0838798044'
136                    xmldict['institution_bank_id'] = '76'
[11955]137                elif xmldict['faculty'] in ('IAS',):
[14329]138                    xmldict['institution_acct'] = '0838798044'
139                    xmldict['institution_bank_id'] = '76'
[11865]140                    self.pay_item_id = '107'
[11955]141                elif xmldict['faculty'] in ('IES',):
[14329]142                    xmldict['institution_acct'] = '0838798044'
143                    xmldict['institution_bank_id'] = '76'
[11865]144                    self.pay_item_id = '109'
145                elif xmldict['faculty'] in ('IFMS',):
[14329]146                    xmldict['institution_acct'] = '0838798044'
147                    xmldict['institution_bank_id'] = '76'
[11865]148                    self.pay_item_id = '106'
[11955]149                elif xmldict['faculty'] in ('IOT',):
[14329]150                    xmldict['institution_acct'] = '0838798044'
151                    xmldict['institution_bank_id'] = '76'
[11865]152                    self.pay_item_id = '110'
153                elif xmldict['faculty'] in ('IICT',):
[14329]154                    xmldict['institution_acct'] = '0838798044'
155                    xmldict['institution_bank_id'] = '76'
[11865]156                    self.pay_item_id = '108'
157            else:
[14329]158                xmldict['institution_acct'] = '0838798044'
159                xmldict['institution_bank_id'] = '76'
[12061]160                #Introduce a pay_item_id for part-time for the first time on this portal
161                self.pay_item_id = '145'
[11769]162        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
163            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
164            dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
165            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
166            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
167            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4]
[9617]168        elif 'maintenance' in self.context.p_category:
[9626]169            self.pay_item_id = '102'
[14329]170            xmldict['institution_acct'] = '0838798044'
171            xmldict['institution_bank_id'] = '76'
[9789]172            dalash_amt = 0.0
173            provider_amt = 0.0
[14218]174        elif 'clearance' in self.context.p_category:
175            self.pay_item_id = '146'
[14329]176            xmldict['institution_acct'] = '0838798044'
177            xmldict['institution_bank_id'] = '76'
[11557]178        else:
179            xmldict['institution_acct'] = "0000000000000"
180            xmldict['institution_bank_id'] = '0'
[9617]181
[14257]182        if self.pay_item_id in ('122', '123', '132', '137', '141',
183                                '142', '143', '144', '146', '147',):
184                gateway_amt = round(0.015 * self.context.amount_auth, 2)
185
[10736]186        xmldict['dalash_amt'] = 100 * dalash_amt
187        xmldict['provider_amt'] = 100 * provider_amt
188        xmldict['institution_amt'] = 100 * (
189                self.context.amount_auth - provider_amt -
190                gateway_amt - dalash_amt)
191
[9392]192        hashargs = (
193            self.context.p_id +
194            PRODUCT_ID +
195            self.pay_item_id +
196            str(int(self.amount_auth)) +
197            self.site_redirect_url +
198            self.mac)
199        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
200
[8263]201        # Interswitch amount is not part of the xml data
[9617]202
[10736]203        if 'maintenance' in self.context.p_category:
[9617]204            xmltext = """<payment_item_detail>
[8263]205<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
206<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" />
207</item_details>
208</payment_item_detail>""" % xmldict
[9617]209
[10736]210        else:
[9617]211            xmltext = """<payment_item_detail>
212<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
213<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" />
[10736]214<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
215<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" />
[9617]216</item_details>
217</payment_item_detail>""" % xmldict
218
[8263]219        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9789]220        self.context.provider_amt = provider_amt
[10736]221        self.context.gateway_amt = gateway_amt
[9789]222        self.context.thirdparty_amt = dalash_amt
[7894]223        return
224
[11634]225class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[10131]226    """ View which sends a POST request to the Interswitch
227    CollegePAY payment gateway.
228    """
229    grok.context(ICustomApplicantOnlinePayment)
230    grok.template('applicant_goto_interswitch')
231    action = POST_ACTION
232    site_name = SITE_NAME
233    currency = CURRENCY
234    pay_item_id = '103'
235    product_id = PRODUCT_ID
236    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
237
238    def update(self):
[12978]239        error = self.init_update()
240        if error:
241            self.flash(error, type='danger')
242            self.redirect(self.url(self.context, '@@index'))
243            return
[10131]244        xmldict = {}
[10176]245        provider_amt = 300.0
246        dalash_amt = 200.0
[11682]247        gateway_amt = GATEWAY_AMT
[11769]248        xmldict['institution_acct'] = '00000000000'
249        xmldict['institution_bank_id'] = '00'
[10131]250        if self.applicant.applicant_id.startswith('hnd'):
[14329]251            xmldict['institution_acct'] = '0838798044'
252            xmldict['institution_bank_id'] = '76'
[10597]253        elif self.applicant.applicant_id.startswith('nd'):
[14329]254            xmldict['institution_acct'] = '0838798044'
255            xmldict['institution_bank_id'] = '76'
[11677]256        elif self.applicant.applicant_id.startswith('rmd'):
[14329]257            xmldict['institution_acct'] = '0838798044'
258            xmldict['institution_bank_id'] = '76'
[10651]259        elif self.applicant.applicant_id.startswith('pgft'):
[14329]260            xmldict['institution_acct'] = '0838798044'
261            xmldict['institution_bank_id'] = '76'
[14074]262        elif self.applicant.applicant_id.startswith('putme'):
[14329]263            xmldict['institution_acct'] = '0838798044'
264            xmldict['institution_bank_id'] = '76'
[11795]265            self.pay_item_id = '104'
[10597]266        elif self.applicant.applicant_id.startswith('pre'):
[14329]267            xmldict['institution_acct'] = '0838798044'
268            xmldict['institution_bank_id'] = '76'
[14066]269            provider_amt = 262.5
270            dalash_amt = 0.0
271            gateway_amt = 37.5
[14070]272            self.pay_item_id = '104'
[10844]273        elif self.applicant.applicant_id.startswith('special'):
[11769]274            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
275                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
276                dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
277                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
278                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
279                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4]
[14257]280
281        if self.pay_item_id in ('122', '123', '132', '137', '141',
282                                '142', '143', '144', '146', '147',):
283                gateway_amt = round(0.015 * self.context.amount_auth, 2)
284
[10176]285        xmldict['dalash_amt'] = 100 * dalash_amt
[10131]286        xmldict['detail_ref'] = self.context.p_id
287        xmldict['provider_amt'] = 100 * provider_amt
288        xmldict['provider_acct'] = PROVIDER_ACCT
289        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
290        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
291        xmldict['institution_amt'] = 100 * (
[11682]292            self.context.amount_auth - provider_amt - gateway_amt - dalash_amt)
293        xmldict['institution_item_name'] = self.category
[10131]294        xmldict['institution_name'] = INSTITUTION_NAME
295
296        hashargs = (
297            self.context.p_id +
298            PRODUCT_ID +
299            self.pay_item_id +
300            str(int(self.amount_auth)) +
301            self.site_redirect_url +
302            self.mac)
303        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
304
305        # Interswitch amount is not part of the xml data
[10597]306
[11793]307        xmltext = """<payment_item_detail>
[10131]308<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
309<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" />
[10176]310<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
311<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" />
[10131]312</item_details>
313</payment_item_detail>""" % xmldict
[10597]314
[14074]315        if self.applicant.applicant_id.startswith('pre'):
[14066]316            xmltext = """<payment_item_detail>
317<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
318<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" />
319<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" />
320</item_details>
321</payment_item_detail>""" % xmldict
322
[10131]323        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
324        self.context.provider_amt = provider_amt
[11682]325        self.context.gateway_amt = gateway_amt
[10176]326        self.context.thirdparty_amt = dalash_amt
[10131]327        return
328
[11634]329class CustomInterswitchPaymentRequestWebservicePageStudent(
[9789]330    InterswitchPaymentRequestWebservicePageStudent):
[13591]331    """Request webservice view for the CollegePAY gateway
[7919]332    """
[8255]333    grok.context(ICustomStudentOnlinePayment)
[9789]334    product_id = PRODUCT_ID
335    gateway_host = HOST
[10131]336    gateway_url = URL
337
[13591]338class CustomInterswitchPaymentVerifyWebservicePageStudent(
339    InterswitchPaymentVerifyWebservicePageStudent):
340    """Payment verify view for the CollegePAY gateway
341    """
342    grok.context(ICustomStudentOnlinePayment)
343    product_id = PRODUCT_ID
344    gateway_host = HOST
345    gateway_url = URL
346
[11634]347class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10131]348    InterswitchPaymentRequestWebservicePageApplicant):
[13591]349    """Request webservice view for the CollegePAY gateway
[10131]350    """
351    grok.context(ICustomApplicantOnlinePayment)
352    product_id = PRODUCT_ID
353    gateway_host = HOST
[11557]354    gateway_url = URL
[13591]355
356class CustomInterswitchPaymentVerifyWebservicePageApplicant(
357    InterswitchPaymentVerifyWebservicePageApplicant):
358    """Payment verify view for the CollegePAY gateway
359    """
360    grok.context(ICustomApplicantOnlinePayment)
361    product_id = PRODUCT_ID
362    gateway_host = HOST
363    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.