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

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

prejambites same as pre

  • Property svn:keywords set to Id
File size: 16.5 KB
RevLine 
[7894]1## $Id: browser.py 14074 2016-08-12 07:32:44Z 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 = {
[13329]57    'certificate': ('111', 200.0, 300.0, '0106259811', '10'),
58    'state_result': ('112', 200.0, 300.0, '0106259811', '10'),
59    'transcript_local': ('113', 200.0, 300.0, '0106259811', '10'),
60    'transcript_foreign': ('114', 200.0, 300.0, '0106259811', '10'),
61    'ver_result': ('115', 200.0, 300.0, '0106259811', '10'),
62    'change_course': ('116', 200.0, 300.0, '0106259811', '10'),
63    'change_inst': ('117', 200.0, 300.0, '0106259811', '10'),
64    'jamb_reject': ('118', 200.0, 300.0, '0106259811', '10'),
65    'cert_of_cert': ('119', 200.0, 300.0, '0106259811', '10'),
66    'ref_let': ('120', 200.0, 300.0, '0106259811', '10'),
67    'proc_cert': ('121', 200.0, 300.0, '0106259811', '10'),
68    'loss_idcard': ('122', 6.0, 9.0, '0106259811', '10'),
69    'loss_examcard': ('123', 3.0, 4.5, '0106259811', '10'),
70    'loss_result': ('124', 200.0, 300.0, '0106259811', '10'),
71    'loss_receipt': ('125', 200.0, 300.0, '0106259811', '10'),
72    'loss_clearance': ('126', 200.0, 300.0, '0106259811', '10'),
73    'conv_brochure': ('127', 200.0, 300.0, '0106259811', '10'),
74    'hnd_certificate': ('128', 200.0, 300.0, '0106259811', '10'),
75    'hnd_state_result': ('129', 200.0, 300.0, '0106259811', '10'),
76    'hnd_transcript_local': ('130', 200.0, 300.0, '0106259811', '10'),
77    'hnd_transcript_foreign': ('131', 200.0, 300.0, '0106259811', '10'),
78    'staff_loss_idcard': ('132', 6.0, 9.0, '0106259811', '10'),
79    'hnd_conv_brochure': ('133', 200.0, 300.0, '0106259811', '10'),
80    'pgd_state_result': ('134', 200.0, 300.0, '0106259811', '10'),
81    'pgd_conv_brochure': ('135', 200.0, 300.0, '0106259811', '10'),
82    'pgd_certificate': ('136', 200.0, 300.0, '0106259811', '10'),
83    'log_book': ('137', 3.0, 4.5, '0106259811', '10'),
84    'pgd_transcript_foreign': ('138', 200.0, 300.0, '0106259811', '10'),
85    'pgd_transcript_local': ('139', 200.0, 300.0, '0106259811', '10'),
86    'jamb_regularization': ('140', 200.0, 300.0, '0106259811', '10'),
87    'utme_registration': ('142', 6.0, 9.0, '0106259811', '10'),
88    'utme_cbt': ('143', 6.0, 9.0, '0106259811', '10'),
89    'nysc_id_card': ('144', 6.0, 9.0, '0106259811', '10'),
[11769]90    }
91
[11634]92class CustomInterswitchPageStudent(InterswitchPageStudent):
[7894]93    """ View which sends a POST request to the Interswitch
94    CollegePAY payment gateway.
95    """
[8255]96    grok.context(ICustomStudentOnlinePayment)
[8256]97    grok.template('student_goto_interswitch')
[7894]98    action = POST_ACTION
99    site_name = SITE_NAME
100    currency = CURRENCY
101    product_id = PRODUCT_ID
[9487]102    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
[7894]103
104    def update(self):
[11646]105        error = self.init_update()
106        if error:
107            self.flash(error, type='danger')
108            self.redirect(self.url(self.context, '@@index'))
109            return
110        student = self.student
111        xmldict = self.xmldict
[8263]112        # Provider data
113        xmldict['detail_ref'] = self.context.p_id
114        xmldict['provider_acct'] = PROVIDER_ACCT
115        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
116        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
117        # Institution data
[9616]118        xmldict['institution_item_name'] = self.category
[8263]119        xmldict['institution_name'] = INSTITUTION_NAME
[10736]120        xmldict['institution_amt'] = 0.0
121        dalash_amt = 200.0
122        provider_amt = 300.0
123        gateway_amt = GATEWAY_AMT
[9616]124        self.pay_item_id = '000'
[13329]125        xmldict['institution_acct'] = "0106259811"
126        xmldict['institution_bank_id'] = "10"
[13653]127        if self.context.p_category == 'schoolfee' \
128            or self.context.p_category.startswith('carryover'):
[9616]129            self.pay_item_id = '101'
[9789]130            dalash_amt = 1800.0
[10736]131            provider_amt = 1200.0
[13329]132            if not student.current_mode.endswith('_we'):
[11865]133                if xmldict['faculty'] in ('CPGS',):
[13329]134                    xmldict['institution_acct'] = "0106259811"   
135                    xmldict['institution_bank_id'] = '10'
[11955]136                elif xmldict['faculty'] in ('IAS',):
[13329]137                    xmldict['institution_acct'] = "0106259811" 
138                    xmldict['institution_bank_id'] = '10'
[11865]139                    self.pay_item_id = '107'
[11955]140                elif xmldict['faculty'] in ('IES',):
[13329]141                    xmldict['institution_acct'] = "0106259811"
142                    xmldict['institution_bank_id'] = '10'
[11865]143                    self.pay_item_id = '109'
144                elif xmldict['faculty'] in ('IFMS',):
[13329]145                    xmldict['institution_acct'] = "0106259811"
146                    xmldict['institution_bank_id'] = '10'
[11865]147                    self.pay_item_id = '106'
[11955]148                elif xmldict['faculty'] in ('IOT',):
[13329]149                    xmldict['institution_acct'] = "0106259811"   
[11865]150                    xmldict['institution_bank_id'] = '10'
151                    self.pay_item_id = '110'
152                elif xmldict['faculty'] in ('IICT',):
[13329]153                    xmldict['institution_acct'] = "0106259811"
154                    xmldict['institution_bank_id'] = '10'
[11865]155                    self.pay_item_id = '108'
156            else:
[13329]157                xmldict['institution_acct'] = "0106259811" 
158                xmldict['institution_bank_id'] = '10'
[12061]159                #Introduce a pay_item_id for part-time for the first time on this portal
160                self.pay_item_id = '145'
[11769]161        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
162            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
163            dalash_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
164            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
165            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
166            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][4]
167            if self.context.amount_auth <= 2000.0:
168                gateway_amt = round(0.015 * self.context.amount_auth, 2)
[9617]169        elif 'maintenance' in self.context.p_category:
[9626]170            self.pay_item_id = '102'
[13329]171            xmldict['institution_acct'] = "0106259811"
172            xmldict['institution_bank_id'] = '10'
[9789]173            dalash_amt = 0.0
174            provider_amt = 0.0
[11557]175        else:
176            xmldict['institution_acct'] = "0000000000000"
177            xmldict['institution_bank_id'] = '0'
[9617]178
[10736]179        xmldict['dalash_amt'] = 100 * dalash_amt
180        xmldict['provider_amt'] = 100 * provider_amt
181        xmldict['institution_amt'] = 100 * (
182                self.context.amount_auth - provider_amt -
183                gateway_amt - dalash_amt)
184
[9392]185        hashargs = (
186            self.context.p_id +
187            PRODUCT_ID +
188            self.pay_item_id +
189            str(int(self.amount_auth)) +
190            self.site_redirect_url +
191            self.mac)
192        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
193
[8263]194        # Interswitch amount is not part of the xml data
[9617]195
[10736]196        if 'maintenance' in self.context.p_category:
[9617]197            xmltext = """<payment_item_detail>
[8263]198<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
199<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" />
200</item_details>
201</payment_item_detail>""" % xmldict
[9617]202
[10736]203        else:
[9617]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" />
[10736]207<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
208<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]209</item_details>
210</payment_item_detail>""" % xmldict
211
[8263]212        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9789]213        self.context.provider_amt = provider_amt
[10736]214        self.context.gateway_amt = gateway_amt
[9789]215        self.context.thirdparty_amt = dalash_amt
[7894]216        return
217
[11634]218class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[10131]219    """ View which sends a POST request to the Interswitch
220    CollegePAY payment gateway.
221    """
222    grok.context(ICustomApplicantOnlinePayment)
223    grok.template('applicant_goto_interswitch')
224    action = POST_ACTION
225    site_name = SITE_NAME
226    currency = CURRENCY
227    pay_item_id = '103'
228    product_id = PRODUCT_ID
229    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
230
231    def update(self):
[12978]232        error = self.init_update()
233        if error:
234            self.flash(error, type='danger')
235            self.redirect(self.url(self.context, '@@index'))
236            return
[10131]237        xmldict = {}
[10176]238        provider_amt = 300.0
239        dalash_amt = 200.0
[11682]240        gateway_amt = GATEWAY_AMT
[11769]241        xmldict['institution_acct'] = '00000000000'
242        xmldict['institution_bank_id'] = '00'
[10131]243        if self.applicant.applicant_id.startswith('hnd'):
[13329]244            xmldict['institution_acct'] = '0106259811'
245            xmldict['institution_bank_id'] = '10'
[10597]246        elif self.applicant.applicant_id.startswith('nd'):
[13329]247            xmldict['institution_acct'] = '0106259811'
248            xmldict['institution_bank_id'] = '10'
[11677]249        elif self.applicant.applicant_id.startswith('rmd'):
[13329]250            xmldict['institution_acct'] = '0106259811'
251            xmldict['institution_bank_id'] = '10'
[10651]252        elif self.applicant.applicant_id.startswith('pgft'):
[13329]253            xmldict['institution_acct'] = '0106259811'
254            xmldict['institution_bank_id'] = '10'
[14074]255        elif self.applicant.applicant_id.startswith('putme'):
[13184]256            xmldict['institution_acct'] = '0106259811'
[13185]257            xmldict['institution_bank_id'] = '10'
[11795]258            self.pay_item_id = '104'
[10597]259        elif self.applicant.applicant_id.startswith('pre'):
[13329]260            xmldict['institution_acct'] = '0106259811'
261            xmldict['institution_bank_id'] = '10'
[14066]262            provider_amt = 262.5
263            dalash_amt = 0.0
264            gateway_amt = 37.5
[14070]265            self.pay_item_id = '104'
[10844]266        elif self.applicant.applicant_id.startswith('special'):
[11769]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)
[10176]275        xmldict['dalash_amt'] = 100 * dalash_amt
[10131]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 * (
[11682]282            self.context.amount_auth - provider_amt - gateway_amt - dalash_amt)
283        xmldict['institution_item_name'] = self.category
[10131]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
[10597]296
[11793]297        xmltext = """<payment_item_detail>
[10131]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" />
[10176]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" />
[10131]302</item_details>
303</payment_item_detail>""" % xmldict
[10597]304
[14074]305        if self.applicant.applicant_id.startswith('pre'):
[14066]306            xmltext = """<payment_item_detail>
307<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
308<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" />
309<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" />
310</item_details>
311</payment_item_detail>""" % xmldict
312
[10131]313        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
314        self.context.provider_amt = provider_amt
[11682]315        self.context.gateway_amt = gateway_amt
[10176]316        self.context.thirdparty_amt = dalash_amt
[10131]317        return
318
[11634]319class CustomInterswitchPaymentRequestWebservicePageStudent(
[9789]320    InterswitchPaymentRequestWebservicePageStudent):
[13591]321    """Request webservice view for the CollegePAY gateway
[7919]322    """
[8255]323    grok.context(ICustomStudentOnlinePayment)
[9789]324    product_id = PRODUCT_ID
325    gateway_host = HOST
[10131]326    gateway_url = URL
327
[13591]328class CustomInterswitchPaymentVerifyWebservicePageStudent(
329    InterswitchPaymentVerifyWebservicePageStudent):
330    """Payment verify view for the CollegePAY gateway
331    """
332    grok.context(ICustomStudentOnlinePayment)
333    product_id = PRODUCT_ID
334    gateway_host = HOST
335    gateway_url = URL
336
[11634]337class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10131]338    InterswitchPaymentRequestWebservicePageApplicant):
[13591]339    """Request webservice view for the CollegePAY gateway
[10131]340    """
341    grok.context(ICustomApplicantOnlinePayment)
342    product_id = PRODUCT_ID
343    gateway_host = HOST
[11557]344    gateway_url = URL
[13591]345
346class CustomInterswitchPaymentVerifyWebservicePageApplicant(
347    InterswitchPaymentVerifyWebservicePageApplicant):
348    """Payment verify view for the CollegePAY gateway
349    """
350    grok.context(ICustomApplicantOnlinePayment)
351    product_id = PRODUCT_ID
352    gateway_host = HOST
353    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.