## $Id: browser.py 16429 2021-03-24 06:57:18Z henrik $ ## ## Copyright (C) 2012 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## import httplib import hashlib import grok from waeup.kofa.interfaces import CLEARED, RETURNING from kofacustom.nigeria.interswitch.browser import ( InterswitchPaymentRequestWebservicePageApplicant, InterswitchPaymentRequestWebservicePageStudent, InterswitchPaymentVerifyWebservicePageApplicant, InterswitchPaymentVerifyWebservicePageStudent, InterswitchPageStudent, InterswitchPageApplicant, ) from kofacustom.dspg.students.interfaces import ICustomStudentOnlinePayment from kofacustom.dspg.applicants.interfaces import ICustomApplicantOnlinePayment from kofacustom.dspg.interfaces import MessageFactory as _ from kofacustom.dspg.students.utils import MICROSOFT_FEE PRODUCT_ID = '7269' # must be provided by Interswitch SITE_NAME = 'dspg.waeup.org' PROVIDER_ACCT = '2028964403' PROVIDER_BANK_ID = '8' PROVIDER_ITEM_NAME = 'WAEAC' INSTITUTION_NAME = 'Delta State Polytechnic Ogwashi-Uku' CURRENCY = '566' GATEWAY_AMT = 250.0 MAC = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627' POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' HOST = 'webpay.interswitchng.com' #HOST = 'sandbox.interswitchng.com' URL = '/paydirect/api/v1/gettransaction.json' #URL = '/webpay/api/v1/gettransaction.json' httplib.HTTPSConnection.debuglevel = 0 HTTPS = True SPECIAL_PAYMENT_PARAMS = { 'carryover1': ('101', 500.0, '1015220292', '117'), 'carryover4': ('101', 500.0, '1015220292', '117'), 'carryover5': ('101', 500.0, '1015220292', '117'), 'carryover6': ('101', 500.0, '1015220292', '117'), 'carryover7': ('101', 500.0, '1015220292', '117'), 'carryover8': ('101', 500.0, '1015220292', '117'), 'carryover9': ('101', 500.0, '1015220292', '117'), 'carryover10': ('101', 500.0, '1015220292', '117'), 'carryover11': ('101', 500.0, '1015220292', '117'), 'carryover12': ('101', 500.0, '1015220292', '117'), 'balance': ('101', 500.0, '1015220292', '117'), 'certificate': ('111', 500.0, '1012808851', '117'), 'state_result': ('112', 500.0, '1012808851', '117'), 'transcript_local': ('113', 500.0, '1012808851', '117'), 'transcript_foreign': ('114', 500.0, '1012808851', '117'), 'ver_result': ('115', 500.0, '1012808851', '117'), 'change_course': ('116', 500.0, '1012808851', '117'), 'change_inst': ('117', 500.0, '1012808851', '117'), 'jamb_reject': ('118', 500.0, '1012808851', '117'), 'cert_of_cert': ('119', 500.0, '1012808851', '117'), 'ref_let': ('120', 500.0, '1012808851', '117'), 'proc_cert': ('121', 500.0, '1012808851', '117'), 'loss_idcard': ('122', 9.0, '1012808851', '117'), 'loss_examcard': ('123', 4.5, '1012808851', '117'), 'loss_result': ('124', 500.0, '1012808851', '117'), 'loss_receipt': ('125', 500.0, '1012808851', '117'), 'loss_clearance': ('126', 500.0, '1012808851', '117'), 'conv_brochure': ('127', 500.0, '1012808851', '117'), 'hnd_certificate': ('128', 500.0, '1012808851', '117'), 'hnd_state_result': ('129', 500.0, '1012808851', '117'), 'hnd_transcript_local': ('130', 500.0, '1012808851', '117'), 'hnd_transcript_foreign': ('131', 500.0, '1012808851', '117'), 'staff_loss_idcard': ('132', 9.0, '1012808851', '117'), 'hnd_conv_brochure': ('133', 500.0, '1012808851', '117'), 'pgd_state_result': ('134', 500.0, '1012808851', '117'), 'pgd_conv_brochure': ('135', 500.0, '1012808851', '117'), 'pgd_certificate': ('136', 500.0, '1012808851', '117'), 'log_book': ('137', 4.5, '1012808851', '117'), 'pgd_transcript_foreign': ('138', 500.0, '1012808851', '117'), 'pgd_transcript_local': ('139', 500.0, '1012808851', '117'), 'jamb_regularization': ('140', 500.0, '1012808851', '117'), 'utme_registration': ('142', 9.0, '1012808851', '117'), 'utme_cbt': ('143', 9.0, '1012808851', '117'), 'nysc_id_card': ('144', 9.0, '1012808851', '117'), 'ijmb_result': ('147', 500.0, '1012808851', '117'), 'conv': ('151', 500.0, '1012808851', '117'), } # Not yet readily configured. Bank account numbers are # contradictory. pay_item_ids are not yet assigned. class CustomInterswitchPageStudent(InterswitchPageStudent): """ View which sends a POST request to the Interswitch CollegePAY payment gateway. """ grok.context(ICustomStudentOnlinePayment) action = POST_ACTION site_name = SITE_NAME currency = CURRENCY product_id = PRODUCT_ID mac = MAC pay_item_id = '000' def update(self): error = self.init_update() if error: self.flash(error, type='danger') self.redirect(self.url(self.context, '@@index')) return self.context.r_company = u'interswitch' student = self.student xmldict = self.xmldict # Provider data xmldict['detail_ref'] = self.context.p_id xmldict['provider_acct'] = PROVIDER_ACCT xmldict['provider_bank_id'] = PROVIDER_BANK_ID xmldict['provider_item_name'] = PROVIDER_ITEM_NAME # Institution data xmldict['institution_acct'] = '00000000' xmldict['institution_bank_id'] = '00' xmldict['institution_amt'] = '0.0' provider_amt = 0.0 tech_fee = 0.0 microsoft_fee = 0.0 if self.context.p_category.startswith('schoolfee'): self.pay_item_id = '102' if self.context.p_item != 'Balance': provider_amt = 2800.0 tech_fee = 1200.0 if student.state == RETURNING: microsoft_fee = MICROSOFT_FEE if student.faccode == 'SPAT': xmldict['institution_acct'] = '1015220292' xmldict['institution_bank_id'] = '117' elif student.current_mode in ('nd_ft', 'hnd_ft'): xmldict['institution_acct'] = '2004145840' xmldict['institution_bank_id'] = '8' elif self.context.p_category == 'clearance': self.pay_item_id = '103' if self.context.p_item != 'Balance': provider_amt = 500.0 if student.faccode == 'SPAT': xmldict['institution_acct'] = '1015220292' xmldict['institution_bank_id'] = '117' elif student.current_mode in ('nd_ft', 'hnd_ft'): xmldict['institution_acct'] = '0072223654' xmldict['institution_bank_id'] = '121' elif self.context.p_category == 'gown': self.pay_item_id = '102' # We use school fee item id. xmldict['institution_acct'] = '2006612782' xmldict['institution_bank_id'] = '8' elif self.context.p_category == 'sports': self.pay_item_id = '110' xmldict['institution_acct'] = '6060300688' xmldict['institution_bank_id'] = '51' elif self.context.p_category == 'siwes': self.pay_item_id = '111' xmldict['institution_acct'] = '0080527351' xmldict['institution_bank_id'] = '11' elif self.context.p_category == 'eed_1': self.pay_item_id = '112' xmldict['institution_acct'] = '0039782431' xmldict['institution_bank_id'] = '11' elif self.context.p_category == 'eed_2': self.pay_item_id = '116' xmldict['institution_acct'] = '0039782431' xmldict['institution_bank_id'] = '11' elif self.context.p_category == 'eed_extra': self.pay_item_id = '157' xmldict['institution_acct'] = '0039782431' xmldict['institution_bank_id'] = '11' elif self.context.p_category == 'olevel_results_1': self.pay_item_id = '113' xmldict['institution_acct'] = '2015327204' xmldict['institution_bank_id'] = '8' elif self.context.p_category == 'olevel_results_2': self.pay_item_id = '115' xmldict['institution_acct'] = '2015327204' xmldict['institution_bank_id'] = '8' elif self.context.p_category == 'gns_1': self.pay_item_id = '154' xmldict['institution_acct'] = '2017447652' xmldict['institution_bank_id'] = '8' elif self.context.p_category == 'gns_2': self.pay_item_id = '155' xmldict['institution_acct'] = '2017447652' xmldict['institution_bank_id'] = '8' elif self.context.p_category == 'hostel_maintenance': if self.context.p_item != 'Balance': provider_amt = 500.0 self.pay_item_id = '117' xmldict['institution_acct'] = '1012808851' xmldict['institution_bank_id'] = '117' elif self.context.p_category == 'lsfp_penalty': self.pay_item_id = '102' xmldict['institution_acct'] = '1012808851' xmldict['institution_bank_id'] = '117' elif self.context.p_category == 'eng_1': self.pay_item_id = '118' xmldict['institution_acct'] = '2024473077' xmldict['institution_bank_id'] = '8' elif self.context.p_category == 'eng_2': self.pay_item_id = '119' xmldict['institution_acct'] = '2024473077' xmldict['institution_bank_id'] = '8' elif self.context.p_category == 'bfn': self.pay_item_id = '125' xmldict['institution_acct'] = '0048039049' xmldict['institution_bank_id'] = '11' elif self.context.p_category == 'facilities': self.pay_item_id = '156' xmldict['institution_acct'] = '1012808851' xmldict['institution_bank_id'] = '117' elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] xmldict['provider_amt'] = 100 * provider_amt xmldict['tech_fee'] = 100 * tech_fee xmldict['microsoft_fee'] = 100 * microsoft_fee xmldict['institution_item_name'] = self.context.category xmldict['institution_name'] = INSTITUTION_NAME xmldict['institution_amt'] = institution_amt = 100 * ( self.context.amount_auth - provider_amt - tech_fee - microsoft_fee - GATEWAY_AMT) if provider_amt == 0: xmltext = """ """ % xmldict elif tech_fee == 0: xmltext = """ """ % xmldict elif microsoft_fee == 0: xmltext = """ """ % xmldict else: xmltext = """ """ % xmldict # isouaba: All certificates in SPAT are part time thus any payments # coming from those certificates (Application, Acceptance, school fees # etc) 40% should be split to keystone account. # abraham: Please, kindly exclude the 40% going to Keystone bank for school of part- # time (SPAT) O'level Results Verification payment. if student.faccode == 'SPAT' and not self.context.p_category.startswith('olevel_results'): xmldict['institution_amt_2'] = 0.4 * institution_amt xmldict['institution_amt_1'] = 0.6 * institution_amt if provider_amt == 0: xmltext = """ """ % xmldict elif tech_fee == 0: xmltext = """ """ % xmldict else: xmltext = """ """ % xmldict # Some payments are treated completely separately. The following lines # override the configuration above. if self.context.p_category == 'dep_sug': self.pay_item_id = '102' # We use school fee item id # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 1000 xmldict['amt2'] = 100 * 500 xmldict['amt3'] = 100 * 900 xmldict['amt4'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'sbs_1': self.pay_item_id = '120' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 800 xmldict['amt2'] = 100 * 1000 xmldict['amt3'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'sbs_2': self.pay_item_id = '123' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 300 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'mkt': self.pay_item_id = '127' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'mcn': self.pay_item_id = '129' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'otm': self.pay_item_id = '131' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'acct': self.pay_item_id = '134' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 3000 xmldict['amt2'] = 100 * 500 xmldict['amt3'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'bam': self.pay_item_id = '136' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'pom': self.pay_item_id = '138' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'hrm': self.pay_item_id = '140' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'ndgrad': self.pay_item_id = '152' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 3000 xmldict['amt2'] = 100 * 5000 xmldict['amt3'] = 100 * 1000 xmldict['amt4'] = 100 * 3500 xmltext = """ """ % xmldict if self.context.p_category == 'hndgrad': self.pay_item_id = '153' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 5000 xmldict['amt2'] = 100 * 7500 xmldict['amt3'] = 100 * 1000 xmldict['amt4'] = 100 * 3500 xmltext = """ """ % xmldict if self.context.p_category == 'sas_1': self.pay_item_id = '158' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmldict['amt3'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'sas_2': self.pay_item_id = '159' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'com': self.pay_item_id = '160' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'sta': self.pay_item_id = '161' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'slt_1': self.pay_item_id = '162' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmldict['amt3'] = 100 * 3000 xmldict['amt4'] = 100 * 500 xmldict['amt5'] = 100 * 3000 xmldict['amt6'] = 100 * 2000 xmltext = """ """ % xmldict if self.context.p_category == 'slt_2': self.pay_item_id = '163' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmldict['amt3'] = 100 * 3000 xmltext = """ """ % xmldict if self.context.p_category == 'lis': self.pay_item_id = '164' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict if self.context.p_category == 'htm': self.pay_item_id = '165' # amount_auth is being ignored. However, the sum of all split payments # must coincide with the amount_auth configured in students/utils.py xmldict['amt1'] = 100 * 500 xmldict['amt2'] = 100 * 500 xmltext = """ """ % xmldict self.xml_data = """""" % xmltext self.context.provider_amt = provider_amt self.context.gateway_amt = GATEWAY_AMT self.amount_auth = int(100 * self.context.amount_auth) hashargs = ( self.context.p_id + PRODUCT_ID + self.pay_item_id + str(int(self.amount_auth)) + self.site_redirect_url + self.mac) self.hashvalue = hashlib.sha512(hashargs).hexdigest() return class CustomInterswitchPageApplicant(InterswitchPageApplicant): """ View which sends a POST request to the Interswitch CollegePAY payment gateway. """ grok.context(ICustomApplicantOnlinePayment) action = POST_ACTION site_name = SITE_NAME currency = CURRENCY pay_item_id = '101' # must be provided by Interswitch product_id = PRODUCT_ID mac = MAC def update(self): error = self.init_update() if error: self.flash(error, type='danger') self.redirect(self.url(self.context, '@@index')) return self.context.r_company = u'interswitch' xmldict = {} provider_amt = 500.0 gateway_amt = GATEWAY_AMT xmldict['institution_acct'] = '00000000' xmldict['institution_bank_id'] = '00' if self.applicant.__parent__.application_category in ('ndft', 'hndft'): xmldict['institution_acct'] = '0072223654' xmldict['institution_bank_id'] = '121' elif self.applicant.__parent__.application_category in ( 'ndpt', 'hndpt', 'ndwe', 'hndwe'): xmldict['institution_acct'] = '1015220292' xmldict['institution_bank_id'] = '117' elif self.applicant.__parent__.prefix in ('conv', 'hndfincl', 'ndfincl'): xmldict['institution_acct'] = '1012808851' xmldict['institution_bank_id'] = '117' self.pay_item_id = '151' elif self.applicant.applicant_id.startswith('special'): if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys(): self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0] provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1] xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2] xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3] if self.pay_item_id in ('122', '123', '132', '137', '141', '142', '143', '144', '146', '147',): gateway_amt = round(0.015 * self.context.amount_auth, 2) xmldict['detail_ref'] = self.context.p_id xmldict['provider_amt'] = 100 * provider_amt xmldict['provider_acct'] = PROVIDER_ACCT xmldict['provider_bank_id'] = PROVIDER_BANK_ID xmldict['provider_item_name'] = PROVIDER_ITEM_NAME xmldict['institution_amt'] = institution_amt = 100 * ( self.context.amount_auth - provider_amt - gateway_amt) xmldict['institution_item_name'] = self.context.category xmldict['institution_name'] = INSTITUTION_NAME xmltext = """ """ % xmldict # isouaba: All certificates in SPAT are part time thus any payments # coming from those certificates (Application, Acceptance, school fees # etc) 40% should be split to keystone account. if self.applicant.__parent__.application_category in ( 'ndpt', 'hndpt', 'ndwe', 'hndwe'): xmldict['institution_amt_2'] = 0.4 * institution_amt xmldict['institution_amt_1'] = 0.6 * institution_amt xmltext = """ """ % xmldict self.xml_data = """""" % xmltext self.context.provider_amt = provider_amt self.context.gateway_amt = GATEWAY_AMT self.amount_auth = int(100 * self.context.amount_auth) hashargs = ( self.context.p_id + PRODUCT_ID + self.pay_item_id + str(int(self.amount_auth)) + self.site_redirect_url + self.mac) self.hashvalue = hashlib.sha512(hashargs).hexdigest() return class CustomInterswitchPaymentRequestWebservicePageStudent( InterswitchPaymentRequestWebservicePageStudent): """Request webservice view for the CollegePAY gateway """ grok.context(ICustomStudentOnlinePayment) product_id = PRODUCT_ID gateway_host = HOST gateway_url = URL mac = MAC class CustomInterswitchPaymentVerifyWebservicePageStudent( InterswitchPaymentVerifyWebservicePageStudent): """Payment verify view for the CollegePAY gateway """ grok.context(ICustomStudentOnlinePayment) product_id = PRODUCT_ID gateway_host = HOST gateway_url = URL mac = MAC class CustomInterswitchPaymentRequestWebservicePageApplicant( InterswitchPaymentRequestWebservicePageApplicant): """Request webservice view for the CollegePAY gateway """ grok.context(ICustomApplicantOnlinePayment) product_id = PRODUCT_ID gateway_host = HOST gateway_url = URL mac = MAC class CustomInterswitchPaymentVerifyWebservicePageApplicant( InterswitchPaymentVerifyWebservicePageApplicant): """Payment verify view for the CollegePAY gateway """ grok.context(ICustomApplicantOnlinePayment) product_id = PRODUCT_ID gateway_host = HOST gateway_url = URL mac = MAC