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
RevLine 
[7894]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##
[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
[11634]53class CustomInterswitchPageStudent(InterswitchPageStudent):
[7894]54    """ View which sends a POST request to the Interswitch
55    CollegePAY payment gateway.
56    """
[8255]57    grok.context(ICustomStudentOnlinePayment)
[8256]58    grok.template('student_goto_interswitch')
[7894]59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
[9487]63    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
[7894]64
[9464]65    def interswitch_img_url(self):
66        return interswitch_img_url(self)
67
[7894]68    def update(self):
[11646]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
[8263]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
[9616]82        xmldict['institution_item_name'] = self.category
[8263]83        xmldict['institution_name'] = INSTITUTION_NAME
[10736]84        xmldict['institution_amt'] = 0.0
85        dalash_amt = 200.0
86        provider_amt = 300.0
87        gateway_amt = GATEWAY_AMT
[9616]88        self.pay_item_id = '000'
[11557]89        xmldict['institution_acct'] = "7000016724"
90        xmldict['institution_bank_id'] = "9"
[9737]91        if self.context.p_category == 'schoolfee':
[9616]92            self.pay_item_id = '101'
[9789]93            dalash_amt = 1800.0
[10736]94            provider_amt = 1200.0
[9616]95            if xmldict['faculty'] in ('CPGS',):
96                xmldict['institution_acct'] = "1771180233"
97                xmldict['institution_bank_id'] = '120'
98            elif xmldict['faculty'] in ('IBAS',):
[10667]99                xmldict['institution_acct'] = "2013910271"
100                xmldict['institution_bank_id'] = '8'
101                self.pay_item_id = '107'
[9616]102            elif xmldict['faculty'] in ('IETS',):
[10667]103                xmldict['institution_acct'] = "2013910271"
104                xmldict['institution_bank_id'] = '8'
105                self.pay_item_id = '109'
106            elif xmldict['faculty'] in ('IFMS',):
[9616]107                xmldict['institution_acct'] = "0106259811"
108                xmldict['institution_bank_id'] = '10'
[10667]109                self.pay_item_id = '106'
[9616]110            elif xmldict['faculty'] in ('ITCH',):
[10667]111                xmldict['institution_acct'] = "1771180233"
112                xmldict['institution_bank_id'] = '120'
113                self.pay_item_id = '110'
114            elif xmldict['faculty'] in ('IICT',):
[9616]115                xmldict['institution_acct'] = "2013910271"
116                xmldict['institution_bank_id'] = '8'
[10667]117                self.pay_item_id = '108'
[10736]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'
[11629]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'
[9617]176        elif 'maintenance' in self.context.p_category:
[9626]177            self.pay_item_id = '102'
[9617]178            xmldict['institution_acct'] = "0039050937"
179            xmldict['institution_bank_id'] = '31'
[9789]180            dalash_amt = 0.0
181            provider_amt = 0.0
[11557]182        else:
183            xmldict['institution_acct'] = "0000000000000"
184            xmldict['institution_bank_id'] = '0'
[9617]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 interswitch_img_url(self):
239        return interswitch_img_url(self)
240
241    def update(self):
[11634]242        super(CustomInterswitchPageApplicant, self).update()
[10131]243        xmldict = {}
[10176]244        provider_amt = 300.0
245        dalash_amt = 200.0
[10131]246        if self.applicant.applicant_id.startswith('hnd'):
[10254]247            xmldict['institution_acct'] = '7000016724'
[10131]248            xmldict['institution_bank_id'] = '9'
[10597]249        elif self.applicant.applicant_id.startswith('nd'):
[10131]250            xmldict['institution_acct'] = '2014191363'
251            xmldict['institution_bank_id'] = '8'
[10651]252        elif self.applicant.applicant_id.startswith('pgft'):
253            xmldict['institution_acct'] = '7000016724'
254            xmldict['institution_bank_id'] = '9'
[10597]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
[10844]266        elif self.applicant.applicant_id.startswith('special'):
[11557]267            xmldict['institution_acct'] = "7000016724"
268            xmldict['institution_bank_id'] = '9'
[10844]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'
[11629]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'
[10844]327            else:
328                xmldict['institution_acct'] = '00000000000'
329                xmldict['institution_bank_id'] = '00'
[10131]330        else:
331            xmldict['institution_acct'] = '00000000000'
332            xmldict['institution_bank_id'] = '00'
[10176]333        xmldict['dalash_amt'] = 100 * dalash_amt
[10131]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 * (
[10176]340            self.context.amount_auth - provider_amt - GATEWAY_AMT - dalash_amt)
[10131]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
[10597]354
355        if not self.applicant.applicant_id.startswith('pre'):
356            xmltext = """<payment_item_detail>
[10131]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" />
[10176]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" />
[10131]361</item_details>
362</payment_item_detail>""" % xmldict
[10597]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
[10131]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
[10176]374        self.context.thirdparty_amt = dalash_amt
[10131]375        return
376
[11634]377class CustomInterswitchPaymentRequestWebservicePageStudent(
[9789]378    InterswitchPaymentRequestWebservicePageStudent):
[7919]379    """ Request webservice view for the CollegePAY gateway
380    """
[8255]381    grok.context(ICustomStudentOnlinePayment)
[9789]382    product_id = PRODUCT_ID
383    gateway_host = HOST
[10131]384    gateway_url = URL
385
[11634]386class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10131]387    InterswitchPaymentRequestWebservicePageApplicant):
388    """ Request webservice view for the CollegePAY gateway
389    """
390    grok.context(ICustomApplicantOnlinePayment)
391    product_id = PRODUCT_ID
392    gateway_host = HOST
[11557]393    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.