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

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

Add new fees (ticket #91)

Remove 'Fee' in drop-down menus.

  • Property svn:keywords set to Id
File size: 15.7 KB
Line 
1## $Id: browser.py 11922 2014-11-01 14:24:29Z 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
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    'utme_registration': ('142', 6.0, 9.0, '2013910271', '8'),
86    'utme_cbt': ('143', 6.0, 9.0, '2013910271', '8'),
87    'nysc_id_card': ('144', 6.0, 9.0, '7000016724', '9'),
88    }
89
90class CustomInterswitchPageStudent(InterswitchPageStudent):
91    """ View which sends a POST request to the Interswitch
92    CollegePAY payment gateway.
93    """
94    grok.context(ICustomStudentOnlinePayment)
95    grok.template('student_goto_interswitch')
96    action = POST_ACTION
97    site_name = SITE_NAME
98    currency = CURRENCY
99    product_id = PRODUCT_ID
100    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
101
102    def update(self):
103        error = self.init_update()
104        if error:
105            self.flash(error, type='danger')
106            self.redirect(self.url(self.context, '@@index'))
107            return
108        student = self.student
109        xmldict = self.xmldict
110        # Provider data
111        xmldict['detail_ref'] = self.context.p_id
112        xmldict['provider_acct'] = PROVIDER_ACCT
113        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
114        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
115        # Institution data
116        xmldict['institution_item_name'] = self.category
117        xmldict['institution_name'] = INSTITUTION_NAME
118        xmldict['institution_amt'] = 0.0
119        dalash_amt = 200.0
120        provider_amt = 300.0
121        gateway_amt = GATEWAY_AMT
122        self.pay_item_id = '000'
123        xmldict['institution_acct'] = "7000016724"
124        xmldict['institution_bank_id'] = "9"
125        if self.context.p_category == 'schoolfee':
126            self.pay_item_id = '101'
127            dalash_amt = 1800.0
128            provider_amt = 1200.0
129            if not student.current_mode.endswith('_pt'):
130                if xmldict['faculty'] in ('CPGS',):
131                    xmldict['institution_acct'] = "1771586608"    #changed account no. from 1771180233
132                    xmldict['institution_bank_id'] = '120'
133                elif xmldict['faculty'] in ('IBAS',):
134                    xmldict['institution_acct'] = "1771586608"  #Changed from FBN to SKYE Bank
135                    xmldict['institution_bank_id'] = '120'
136                    self.pay_item_id = '107'
137                elif xmldict['faculty'] in ('IETS',):
138                    xmldict['institution_acct'] = "0693033406" #Changed from FBN to Access Bank
139                    xmldict['institution_bank_id'] = '31'
140                    self.pay_item_id = '109'
141                elif xmldict['faculty'] in ('IFMS',):
142                    xmldict['institution_acct'] = "2013910271" #changed bank from GTBank to FBN
143                    xmldict['institution_bank_id'] = '8'
144                    self.pay_item_id = '106'
145                elif xmldict['faculty'] in ('ITCH',):
146                    xmldict['institution_acct'] = "0106259811"    #changed from SKYE Bank to GTbank
147                    xmldict['institution_bank_id'] = '10'
148                    self.pay_item_id = '110'
149                elif xmldict['faculty'] in ('IICT',):
150                    xmldict['institution_acct'] = "1100019929" #changed from FBN to Keystone Bank
151                    xmldict['institution_bank_id'] = '123'
152                    self.pay_item_id = '108'
153            else:
154                xmldict['institution_acct'] = "0838798020"  #part-time fees acquired by FCMB
155                xmldict['institution_bank_id'] = '76'
156        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
157            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
158            dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
159            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
160            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
161            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4]
162            if self.context.amount_auth <= 2000.0:
163                gateway_amt = round(0.015 * self.context.amount_auth, 2)
164        elif 'maintenance' in self.context.p_category:
165            self.pay_item_id = '102'
166            xmldict['institution_acct'] = "0039050937"
167            xmldict['institution_bank_id'] = '31'
168            dalash_amt = 0.0
169            provider_amt = 0.0
170        else:
171            xmldict['institution_acct'] = "0000000000000"
172            xmldict['institution_bank_id'] = '0'
173
174        xmldict['dalash_amt'] = 100 * dalash_amt
175        xmldict['provider_amt'] = 100 * provider_amt
176        xmldict['institution_amt'] = 100 * (
177                self.context.amount_auth - provider_amt -
178                gateway_amt - dalash_amt)
179
180        hashargs = (
181            self.context.p_id +
182            PRODUCT_ID +
183            self.pay_item_id +
184            str(int(self.amount_auth)) +
185            self.site_redirect_url +
186            self.mac)
187        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
188
189        # Interswitch amount is not part of the xml data
190
191        if 'maintenance' in self.context.p_category:
192            xmltext = """<payment_item_detail>
193<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
194<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" />
195</item_details>
196</payment_item_detail>""" % xmldict
197
198        else:
199            xmltext = """<payment_item_detail>
200<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
201<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" />
202<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
203<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" />
204</item_details>
205</payment_item_detail>""" % xmldict
206
207        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
208        self.context.provider_amt = provider_amt
209        self.context.gateway_amt = gateway_amt
210        self.context.thirdparty_amt = dalash_amt
211        return
212
213class CustomInterswitchPageApplicant(InterswitchPageApplicant):
214    """ View which sends a POST request to the Interswitch
215    CollegePAY payment gateway.
216    """
217    grok.context(ICustomApplicantOnlinePayment)
218    grok.template('applicant_goto_interswitch')
219    action = POST_ACTION
220    site_name = SITE_NAME
221    currency = CURRENCY
222    pay_item_id = '103'
223    product_id = PRODUCT_ID
224    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
225
226    def update(self):
227        super(CustomInterswitchPageApplicant, self).update()
228        xmldict = {}
229        provider_amt = 300.0
230        dalash_amt = 200.0
231        gateway_amt = GATEWAY_AMT
232        xmldict['institution_acct'] = '00000000000'
233        xmldict['institution_bank_id'] = '00'
234        if self.applicant.applicant_id.startswith('hnd'):
235            xmldict['institution_acct'] = '1771440667'
236            xmldict['institution_bank_id'] = '120'
237        elif self.applicant.applicant_id.startswith('nd'):
238            xmldict['institution_acct'] = '1771440667'
239            xmldict['institution_bank_id'] = '120'
240        elif self.applicant.applicant_id.startswith('rmd'):
241            xmldict['institution_acct'] = '1771440667'
242            xmldict['institution_bank_id'] = '120'
243        elif self.applicant.applicant_id.startswith('pgft'):
244            xmldict['institution_acct'] = '7000016724'
245            xmldict['institution_bank_id'] = '9'
246        elif self.applicant.applicant_id.startswith('prejambites') or \
247            self.applicant.applicant_id.startswith('putme'):
248            # changed for prejambites from GTBank '0106259811' to FBN '2013910271'
249            xmldict['institution_acct'] = '2013910271'
250            xmldict['institution_bank_id'] = '8'
251            self.pay_item_id = '104'
252            # Until 14/9/2014 we have not sent split amount data for pre applications.
253            # To compenstate the loss we temporarily doubled the split amounts
254            # until 20/9/2014, see ticket 75.
255            #provider_amt = 600.0
256            #dalash_amt = 400.0
257        elif self.applicant.applicant_id.startswith('pre'):
258            # changed for prejambites from FBN '2013910271' to GTBank '0106259811'
259            xmldict['institution_acct'] = '0106259811'
260            xmldict['institution_bank_id'] = '10'
261            # Until 14/9/2014 we have not sent split amount data for pre applications.
262            # To compenstate the loss we temporarily doubled the split amounts
263            # until 20/9/2014, see ticket 75.
264            #provider_amt = 600.0
265            #dalash_amt = 400.0
266        elif self.applicant.applicant_id.startswith('special'):
267            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
268                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
269                dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
270                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
271                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
272                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4]
273                if self.context.amount_auth <= 2000.0:
274                    gateway_amt = round(0.015 * self.context.amount_auth, 2)
275        xmldict['dalash_amt'] = 100 * dalash_amt
276        xmldict['detail_ref'] = self.context.p_id
277        xmldict['provider_amt'] = 100 * provider_amt
278        xmldict['provider_acct'] = PROVIDER_ACCT
279        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
280        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
281        xmldict['institution_amt'] = 100 * (
282            self.context.amount_auth - provider_amt - gateway_amt - dalash_amt)
283        xmldict['institution_item_name'] = self.category
284        xmldict['institution_name'] = INSTITUTION_NAME
285
286        hashargs = (
287            self.context.p_id +
288            PRODUCT_ID +
289            self.pay_item_id +
290            str(int(self.amount_auth)) +
291            self.site_redirect_url +
292            self.mac)
293        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
294
295        # Interswitch amount is not part of the xml data
296
297        xmltext = """<payment_item_detail>
298<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
299<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" />
300<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
301<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" />
302</item_details>
303</payment_item_detail>""" % xmldict
304
305        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
306        self.context.provider_amt = provider_amt
307        self.context.gateway_amt = gateway_amt
308        self.context.thirdparty_amt = dalash_amt
309        return
310
311class CustomInterswitchPaymentRequestWebservicePageStudent(
312    InterswitchPaymentRequestWebservicePageStudent):
313    """ Request webservice view for the CollegePAY gateway
314    """
315    grok.context(ICustomStudentOnlinePayment)
316    product_id = PRODUCT_ID
317    gateway_host = HOST
318    gateway_url = URL
319
320class CustomInterswitchPaymentRequestWebservicePageApplicant(
321    InterswitchPaymentRequestWebservicePageApplicant):
322    """ Request webservice view for the CollegePAY gateway
323    """
324    grok.context(ICustomApplicantOnlinePayment)
325    product_id = PRODUCT_ID
326    gateway_host = HOST
327    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.