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

Last change on this file since 11646 was 11646, checked in by Henrik Bettermann, 11 years ago

Use init_update and samePaymentMade methods.

  • Property svn:keywords set to Id
File size: 17.4 KB
Line 
1## $Id: browser.py 11646 2014-05-14 05:17:40Z 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'] = "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'] = "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 'maintenance' in self.context.p_category:
177            self.pay_item_id = '102'
178            xmldict['institution_acct'] = "0039050937"
179            xmldict['institution_bank_id'] = '31'
180            dalash_amt = 0.0
181            provider_amt = 0.0
182        else:
183            xmldict['institution_acct'] = "0000000000000"
184            xmldict['institution_bank_id'] = '0'
185
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
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
201        # Interswitch amount is not part of the xml data
202
203        if 'maintenance' in self.context.p_category:
204            xmltext = """<payment_item_detail>
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
209
210        else:
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" />
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" />
216</item_details>
217</payment_item_detail>""" % xmldict
218
219        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
220        self.context.provider_amt = provider_amt
221        self.context.gateway_amt = gateway_amt
222        self.context.thirdparty_amt = dalash_amt
223        return
224
225class CustomInterswitchPageApplicant(InterswitchPageApplicant):
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 interswitch_img_url(self):
239        return interswitch_img_url(self)
240
241    def update(self):
242        super(CustomInterswitchPageApplicant, self).update()
243        xmldict = {}
244        provider_amt = 300.0
245        dalash_amt = 200.0
246        if self.applicant.applicant_id.startswith('hnd'):
247            xmldict['institution_acct'] = '7000016724'
248            xmldict['institution_bank_id'] = '9'
249        elif self.applicant.applicant_id.startswith('nd'):
250            xmldict['institution_acct'] = '2014191363'
251            xmldict['institution_bank_id'] = '8'
252        elif self.applicant.applicant_id.startswith('pgft'):
253            xmldict['institution_acct'] = '7000016724'
254            xmldict['institution_bank_id'] = '9'
255        elif self.applicant.applicant_id.startswith('prejambites'):
256            xmldict['institution_acct'] = '0106259811'
257            xmldict['institution_bank_id'] = '10'
258            self.pay_item_id = '104'
259            provider_amt = 0.0
260            dalash_amt = 0.0
261        elif self.applicant.applicant_id.startswith('pre'):
262            xmldict['institution_acct'] = '2013910271'
263            xmldict['institution_bank_id'] = '8'
264            provider_amt = 0.0
265            dalash_amt = 0.0
266        elif self.applicant.applicant_id.startswith('special'):
267            xmldict['institution_acct'] = "7000016724"
268            xmldict['institution_bank_id'] = '9'
269            if self.applicant.special_application == 'certificate':
270                self.pay_item_id = '111'
271            elif self.applicant.special_application == 'state_result':
272                self.pay_item_id = '112'
273            elif self.applicant.special_application == 'transcript_local':
274                self.pay_item_id = '113'
275            elif self.applicant.special_application == 'transcript_foreign':
276                self.pay_item_id = '114'
277            elif self.applicant.special_application == 'ver_result':
278                self.pay_item_id = '115'
279            elif self.applicant.special_application == 'change_course':
280                self.pay_item_id = '116'
281            elif self.applicant.special_application == 'change_inst':
282                self.pay_item_id = '117'
283            elif self.applicant.special_application == 'jamb_reject':
284                self.pay_item_id = '118'
285            elif self.applicant.special_application == 'cert_of_cert':
286                self.pay_item_id = '119'
287            elif self.applicant.special_application == 'ref_let':
288                self.pay_item_id = '120'
289            elif self.applicant.special_application == 'proc_cert':
290                self.pay_item_id = '121'
291            elif self.applicant.special_application == 'loss_idcard':
292                self.pay_item_id = '122'
293                dalash_amt = 6.0
294                xmldict['dalash_amt'] = 100 * dalash_amt
295                provider_amt = 9.0
296                gateway_amt = 15.0
297            elif self.applicant.special_application == 'loss_examcard':
298                self.pay_item_id = '123'
299                dalash_amt = 3.0
300                xmldict['dalash_amt'] = 100 * dalash_amt
301                provider_amt = 4.5
302                gateway_amt = 7.5
303            elif self.applicant.special_application == 'loss_result':
304                self.pay_item_id = '124'
305            elif self.applicant.special_application == 'loss_receipt':
306                self.pay_item_id = '125'
307            elif self.applicant.special_application == 'loss_clearance':
308                self.pay_item_id = '126'
309            elif self.applicant.special_application == 'conv_brochure':
310                self.pay_item_id = '127'
311            elif self.applicant.special_application == 'hnd_certificate':
312                self.pay_item_id = '128'
313            elif self.applicant.special_application == 'hnd_state_result':
314                self.pay_item_id = '129'
315            elif self.applicant.special_application == 'hnd_transcript_local':
316                self.pay_item_id = '130'
317            elif self.applicant.special_application == 'hnd_transcript_foreign':
318                self.pay_item_id = '131'
319            elif self.applicant.special_application == 'staff_loss_idcard':
320                self.pay_item_id = '132'
321                dalash_amt = 6.0
322                xmldict['dalash_amt'] = 100 * dalash_amt
323                provider_amt = 9.0
324                gateway_amt = 15.0
325            elif self.context.p_category == 'hnd_conv_brochure':
326                self.pay_item_id = '133'
327            else:
328                xmldict['institution_acct'] = '00000000000'
329                xmldict['institution_bank_id'] = '00'
330        else:
331            xmldict['institution_acct'] = '00000000000'
332            xmldict['institution_bank_id'] = '00'
333        xmldict['dalash_amt'] = 100 * dalash_amt
334        xmldict['detail_ref'] = self.context.p_id
335        xmldict['provider_amt'] = 100 * provider_amt
336        xmldict['provider_acct'] = PROVIDER_ACCT
337        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
338        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
339        xmldict['institution_amt'] = 100 * (
340            self.context.amount_auth - provider_amt - GATEWAY_AMT - dalash_amt)
341        xmldict['institution_item_name'] = self.context.p_category
342        xmldict['institution_name'] = INSTITUTION_NAME
343
344        hashargs = (
345            self.context.p_id +
346            PRODUCT_ID +
347            self.pay_item_id +
348            str(int(self.amount_auth)) +
349            self.site_redirect_url +
350            self.mac)
351        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
352
353        # Interswitch amount is not part of the xml data
354
355        if not self.applicant.applicant_id.startswith('pre'):
356            xmltext = """<payment_item_detail>
357<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
358<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" />
359<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
360<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" />
361</item_details>
362</payment_item_detail>""" % xmldict
363
364        else:
365            xmltext = """<payment_item_detail>
366<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
367<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" />
368</item_details>
369</payment_item_detail>""" % xmldict
370
371        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
372        self.context.provider_amt = provider_amt
373        self.context.gateway_amt = GATEWAY_AMT
374        self.context.thirdparty_amt = dalash_amt
375        return
376
377class CustomInterswitchPaymentRequestWebservicePageStudent(
378    InterswitchPaymentRequestWebservicePageStudent):
379    """ Request webservice view for the CollegePAY gateway
380    """
381    grok.context(ICustomStudentOnlinePayment)
382    product_id = PRODUCT_ID
383    gateway_host = HOST
384    gateway_url = URL
385
386class CustomInterswitchPaymentRequestWebservicePageApplicant(
387    InterswitchPaymentRequestWebservicePageApplicant):
388    """ Request webservice view for the CollegePAY gateway
389    """
390    grok.context(ICustomApplicantOnlinePayment)
391    product_id = PRODUCT_ID
392    gateway_host = HOST
393    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.