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

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

Take PUTME application into consideration.

  • Property svn:keywords set to Id
File size: 15.6 KB
RevLine 
[7894]1## $Id: browser.py 11883 2014-10-28 13:21:10Z 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,
26    InterswitchPageStudent, InterswitchPageApplicant,
[9789]27    )
[9347]28from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment
29from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment
30from waeup.kwarapoly.interfaces import MessageFactory as _
[7894]31
[9487]32PRODUCT_ID = '3930'
[10131]33SITE_NAME = 'kwarapoly.waeup.org'
[9387]34PROVIDER_ACCT = '1010764827'
35PROVIDER_BANK_ID = '117'
[8263]36PROVIDER_ITEM_NAME = 'BT Education'
[9347]37INSTITUTION_NAME = 'KwaraPoly'
[7894]38CURRENCY = '566'
[9789]39GATEWAY_AMT = 300.0
[8401]40#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
[8293]41#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
[9392]42
[9487]43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
44#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[7894]45
[9487]46HOST = 'webpay.interswitchng.com'
47#HOST = 'testwebpay.interswitchng.com'
[9392]48
[9487]49URL = '/paydirect/services/TransactionQueryWs.asmx'
50#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
[7898]51httplib.HTTPConnection.debuglevel = 0
52
[11769]53
54SPECIAL_PAYMENT_PARAMS = {
55    'certificate': ('111', 200.0, 300.0, '7000016724', '9'),
56    'state_result': ('112', 200.0, 300.0, '7000016724', '9'),
57    'transcript_local': ('113', 200.0, 300.0, '7000016724', '9'),
58    'transcript_foreign': ('114', 200.0, 300.0, '7000016724', '9'),
59    'ver_result': ('115', 200.0, 300.0, '7000016724', '9'),
60    'change_course': ('116', 200.0, 300.0, '7000016724', '9'),
61    'change_inst': ('117', 200.0, 300.0, '7000016724', '9'),
62    'jamb_reject': ('118', 200.0, 300.0, '7000016724', '9'),
63    'cert_of_cert': ('119', 200.0, 300.0, '7000016724', '9'),
64    'ref_let': ('120', 200.0, 300.0, '7000016724', '9'),
65    'proc_cert': ('121', 200.0, 300.0, '7000016724', '9'),
66    'loss_idcard': ('122', 6.0, 9.0, '7000016724', '9'),
67    'loss_examcard': ('123', 3.0, 4.5, '7000016724', '9'),
68    'loss_result': ('124', 200.0, 300.0, '7000016724', '9'),
69    'loss_receipt': ('125', 200.0, 300.0, '7000016724', '9'),
70    'loss_clearance': ('126', 200.0, 300.0, '7000016724', '9'),
71    'conv_brochure': ('127', 200.0, 300.0, '7000016724', '9'),
72    'hnd_certificate': ('128', 200.0, 300.0, '7000016724', '9'),
73    'hnd_state_result': ('129', 200.0, 300.0, '7000016724', '9'),
74    'hnd_transcript_local': ('130', 200.0, 300.0, '7000016724', '9'),
75    'hnd_transcript_foreign': ('131', 200.0, 300.0, '7000016724', '9'),
76    'staff_loss_idcard': ('132', 6.0, 9.0, '7000016724', '9'),
77    'hnd_conv_brochure': ('133', 200.0, 300.0, '7000016724', '9'),
78    'pgd_state_result': ('134', 200.0, 300.0, '7000016724', '9'),
79    'pgd_conv_brochure': ('135', 200.0, 300.0, '7000016724', '9'),
80    'pgd_certificate': ('136', 200.0, 300.0, '7000016724', '9'),
81    'log_book': ('137', 3.0, 4.5, '1010508401', '117'),
82    'pgd_transcript_foreign': ('138', 200.0, 300.0, '7000016724', '9'),
83    'pgd_transcript_local': ('139', 200.0, 300.0, '7000016724', '9'),
84    'jamb_regularization': ('140', 200.0, 300.0, '0838798020', '76'),
85    }
86
[11634]87class CustomInterswitchPageStudent(InterswitchPageStudent):
[7894]88    """ View which sends a POST request to the Interswitch
89    CollegePAY payment gateway.
90    """
[8255]91    grok.context(ICustomStudentOnlinePayment)
[8256]92    grok.template('student_goto_interswitch')
[7894]93    action = POST_ACTION
94    site_name = SITE_NAME
95    currency = CURRENCY
96    product_id = PRODUCT_ID
[9487]97    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
[7894]98
99    def update(self):
[11646]100        error = self.init_update()
101        if error:
102            self.flash(error, type='danger')
103            self.redirect(self.url(self.context, '@@index'))
104            return
105        student = self.student
106        xmldict = self.xmldict
[8263]107        # Provider data
108        xmldict['detail_ref'] = self.context.p_id
109        xmldict['provider_acct'] = PROVIDER_ACCT
110        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
111        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
112        # Institution data
[9616]113        xmldict['institution_item_name'] = self.category
[8263]114        xmldict['institution_name'] = INSTITUTION_NAME
[10736]115        xmldict['institution_amt'] = 0.0
116        dalash_amt = 200.0
117        provider_amt = 300.0
118        gateway_amt = GATEWAY_AMT
[9616]119        self.pay_item_id = '000'
[11557]120        xmldict['institution_acct'] = "7000016724"
121        xmldict['institution_bank_id'] = "9"
[9737]122        if self.context.p_category == 'schoolfee':
[9616]123            self.pay_item_id = '101'
[9789]124            dalash_amt = 1800.0
[10736]125            provider_amt = 1200.0
[11865]126            if not student.current_mode.endswith('_pt'):
127                if xmldict['faculty'] in ('CPGS',):
128                    xmldict['institution_acct'] = "1771586608"    #changed account no. from 1771180233
129                    xmldict['institution_bank_id'] = '120'
130                elif xmldict['faculty'] in ('IBAS',):
131                    xmldict['institution_acct'] = "1771586608"  #Changed from FBN to SKYE Bank
132                    xmldict['institution_bank_id'] = '120'
133                    self.pay_item_id = '107'
134                elif xmldict['faculty'] in ('IETS',):
135                    xmldict['institution_acct'] = "0693033406" #Changed from FBN to Access Bank
136                    xmldict['institution_bank_id'] = '31'
137                    self.pay_item_id = '109'
138                elif xmldict['faculty'] in ('IFMS',):
139                    xmldict['institution_acct'] = "2013910271" #changed bank from GTBank to FBN
140                    xmldict['institution_bank_id'] = '8'
141                    self.pay_item_id = '106'
142                elif xmldict['faculty'] in ('ITCH',):
143                    xmldict['institution_acct'] = "0106259811"    #changed from SKYE Bank to GTbank
144                    xmldict['institution_bank_id'] = '10'
145                    self.pay_item_id = '110'
146                elif xmldict['faculty'] in ('IICT',):
147                    xmldict['institution_acct'] = "1100019929" #changed from FBN to Keystone Bank
148                    xmldict['institution_bank_id'] = '123'
149                    self.pay_item_id = '108'
150            else:
151                xmldict['institution_acct'] = "0838798020"  #part-time fees acquired by FCMB
152                xmldict['institution_bank_id'] = '76'
[11769]153        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
154            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
155            dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
156            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
157            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
158            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4]
159            if self.context.amount_auth <= 2000.0:
160                gateway_amt = round(0.015 * self.context.amount_auth, 2)
[9617]161        elif 'maintenance' in self.context.p_category:
[9626]162            self.pay_item_id = '102'
[9617]163            xmldict['institution_acct'] = "0039050937"
164            xmldict['institution_bank_id'] = '31'
[9789]165            dalash_amt = 0.0
166            provider_amt = 0.0
[11557]167        else:
168            xmldict['institution_acct'] = "0000000000000"
169            xmldict['institution_bank_id'] = '0'
[9617]170
[10736]171        xmldict['dalash_amt'] = 100 * dalash_amt
172        xmldict['provider_amt'] = 100 * provider_amt
173        xmldict['institution_amt'] = 100 * (
174                self.context.amount_auth - provider_amt -
175                gateway_amt - dalash_amt)
176
[9392]177        hashargs = (
178            self.context.p_id +
179            PRODUCT_ID +
180            self.pay_item_id +
181            str(int(self.amount_auth)) +
182            self.site_redirect_url +
183            self.mac)
184        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
185
[8263]186        # Interswitch amount is not part of the xml data
[9617]187
[10736]188        if 'maintenance' in self.context.p_category:
[9617]189            xmltext = """<payment_item_detail>
[8263]190<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
191<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" />
192</item_details>
193</payment_item_detail>""" % xmldict
[9617]194
[10736]195        else:
[9617]196            xmltext = """<payment_item_detail>
197<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
198<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]199<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
200<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]201</item_details>
202</payment_item_detail>""" % xmldict
203
[8263]204        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9789]205        self.context.provider_amt = provider_amt
[10736]206        self.context.gateway_amt = gateway_amt
[9789]207        self.context.thirdparty_amt = dalash_amt
[7894]208        return
209
[11634]210class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[10131]211    """ View which sends a POST request to the Interswitch
212    CollegePAY payment gateway.
213    """
214    grok.context(ICustomApplicantOnlinePayment)
215    grok.template('applicant_goto_interswitch')
216    action = POST_ACTION
217    site_name = SITE_NAME
218    currency = CURRENCY
219    pay_item_id = '103'
220    product_id = PRODUCT_ID
221    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
222
223    def update(self):
[11634]224        super(CustomInterswitchPageApplicant, self).update()
[10131]225        xmldict = {}
[10176]226        provider_amt = 300.0
227        dalash_amt = 200.0
[11682]228        gateway_amt = GATEWAY_AMT
[11769]229        xmldict['institution_acct'] = '00000000000'
230        xmldict['institution_bank_id'] = '00'
[10131]231        if self.applicant.applicant_id.startswith('hnd'):
[11677]232            xmldict['institution_acct'] = '1771440667'
233            xmldict['institution_bank_id'] = '120'
[10597]234        elif self.applicant.applicant_id.startswith('nd'):
[11677]235            xmldict['institution_acct'] = '1771440667'
236            xmldict['institution_bank_id'] = '120'
237        elif self.applicant.applicant_id.startswith('rmd'):
238            xmldict['institution_acct'] = '1771440667'
239            xmldict['institution_bank_id'] = '120'
[10651]240        elif self.applicant.applicant_id.startswith('pgft'):
241            xmldict['institution_acct'] = '7000016724'
242            xmldict['institution_bank_id'] = '9'
[11883]243        elif self.applicant.applicant_id.startswith('prejambites') or \
244            self.applicant.applicant_id.startswith('putme'):
[11791]245            # changed for prejambites from GTBank '0106259811' to FBN '2013910271'
246            xmldict['institution_acct'] = '2013910271'
247            xmldict['institution_bank_id'] = '8'
[11795]248            self.pay_item_id = '104'
[11793]249            # Until 14/9/2014 we have not sent split amount data for pre applications.
[11797]250            # To compenstate the loss we temporarily doubled the split amounts
251            # until 20/9/2014, see ticket 75.
252            #provider_amt = 600.0
253            #dalash_amt = 400.0
[10597]254        elif self.applicant.applicant_id.startswith('pre'):
[11791]255            # changed for prejambites from FBN '2013910271' to GTBank '0106259811'
256            xmldict['institution_acct'] = '0106259811'
257            xmldict['institution_bank_id'] = '10'
[11793]258            # Until 14/9/2014 we have not sent split amount data for pre applications.
[11797]259            # To compenstate the loss we temporarily doubled the split amounts
260            # until 20/9/2014, see ticket 75.
261            #provider_amt = 600.0
262            #dalash_amt = 400.0
[10844]263        elif self.applicant.applicant_id.startswith('special'):
[11769]264            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
265                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
266                dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
267                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
268                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
269                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4]
270                if self.context.amount_auth <= 2000.0:
271                    gateway_amt = round(0.015 * self.context.amount_auth, 2)
[10176]272        xmldict['dalash_amt'] = 100 * dalash_amt
[10131]273        xmldict['detail_ref'] = self.context.p_id
274        xmldict['provider_amt'] = 100 * provider_amt
275        xmldict['provider_acct'] = PROVIDER_ACCT
276        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
277        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
278        xmldict['institution_amt'] = 100 * (
[11682]279            self.context.amount_auth - provider_amt - gateway_amt - dalash_amt)
280        xmldict['institution_item_name'] = self.category
[10131]281        xmldict['institution_name'] = INSTITUTION_NAME
282
283        hashargs = (
284            self.context.p_id +
285            PRODUCT_ID +
286            self.pay_item_id +
287            str(int(self.amount_auth)) +
288            self.site_redirect_url +
289            self.mac)
290        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
291
292        # Interswitch amount is not part of the xml data
[10597]293
[11793]294        xmltext = """<payment_item_detail>
[10131]295<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
296<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]297<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
298<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]299</item_details>
300</payment_item_detail>""" % xmldict
[10597]301
[10131]302        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
303        self.context.provider_amt = provider_amt
[11682]304        self.context.gateway_amt = gateway_amt
[10176]305        self.context.thirdparty_amt = dalash_amt
[10131]306        return
307
[11634]308class CustomInterswitchPaymentRequestWebservicePageStudent(
[9789]309    InterswitchPaymentRequestWebservicePageStudent):
[7919]310    """ Request webservice view for the CollegePAY gateway
311    """
[8255]312    grok.context(ICustomStudentOnlinePayment)
[9789]313    product_id = PRODUCT_ID
314    gateway_host = HOST
[10131]315    gateway_url = URL
316
[11634]317class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10131]318    InterswitchPaymentRequestWebservicePageApplicant):
319    """ Request webservice view for the CollegePAY gateway
320    """
321    grok.context(ICustomApplicantOnlinePayment)
322    product_id = PRODUCT_ID
323    gateway_host = HOST
[11557]324    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.