source: main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py @ 13325

Last change on this file since 13325 was 13301, checked in by Henrik Bettermann, 9 years ago

Use item id just provided by Interswitch.

  • Property svn:keywords set to Id
File size: 12.2 KB
RevLine 
[7894]1## $Id: browser.py 13301 2015-10-08 10:33:42Z 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
[7894]19import grok
[13301]20from zope.component import getUtility
21from waeup.kofa.students.interfaces import IStudentsUtils
[9782]22from kofacustom.nigeria.interswitch.browser import (
23    InterswitchPaymentRequestWebservicePageApplicant,
[11633]24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPageStudent, InterswitchPageApplicant,
[9782]26    )
[8263]27from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
28from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment
[8020]29from waeup.uniben.interfaces import MessageFactory as _
[7894]30
31PRODUCT_ID = '57'
[8263]32SITE_NAME = 'uniben-kofa.waeup.org'
[8424]33PROVIDER_ACCT = '1010764827'
34PROVIDER_BANK_ID = '117'
[8263]35PROVIDER_ITEM_NAME = 'BT Education'
36INSTITUTION_NAME = 'Uniben'
[7894]37CURRENCY = '566'
[9775]38GATEWAY_AMT = 150.0
[8401]39#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
[8293]40#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
[8385]41POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
[8293]42#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[7894]43
[8293]44HOST = 'webpay.interswitchng.com'
45#HOST = 'testwebpay.interswitchng.com'
46URL = '/paydirect/services/TransactionQueryWs.asmx'
47#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
[7898]48httplib.HTTPConnection.debuglevel = 0
49
[11633]50class CustomInterswitchPageStudent(InterswitchPageStudent):
[7894]51    """ View which sends a POST request to the Interswitch
52    CollegePAY payment gateway.
53    """
[8255]54    grok.context(ICustomStudentOnlinePayment)
[7894]55    action = POST_ACTION
56    site_name = SITE_NAME
57    currency = CURRENCY
58    product_id = PRODUCT_ID
59
60    def update(self):
[11644]61        error = self.init_update()
62        if error:
63            self.flash(error, type='danger')
64            self.redirect(self.url(self.context, '@@index'))
65            return
66        student = self.student
67        xmldict = self.xmldict
[8263]68        # Provider data
69        xmldict['detail_ref'] = self.context.p_id
70        xmldict['provider_acct'] = PROVIDER_ACCT
71        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
72        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
73        # Institution data
[9385]74        xmldict['institution_acct'] = '000000000000'
75        xmldict['institution_bank_id'] = '00'
[9384]76        xmldict['institution_amt'] = '0.0'
[9869]77        provider_amt = 0.0
78        self.pay_item_id = '0000'
[9384]79        if self.context.p_category == 'schoolfee':
[9869]80            if not self.context.p_item == 'Balance':
81                provider_amt = 1500.0
[9384]82            if student.current_mode.endswith('_ft'):
[9389]83                self.pay_item_id = '5700'
[11478]84                if student.current_mode in ('ug_ft','de_ft','ume_ft'):
[9460]85                    xmldict['institution_acct'] = '2017506430'
86                    xmldict['institution_bank_id'] = '8'
[11478]87                elif student.current_mode in ('dp_ft','dp_pt','ct_pt','ct_ft'):
[12471]88                    xmldict['institution_acct'] = '0058653774'
89                    xmldict['institution_bank_id'] = '72'
[9460]90                elif student.current_mode in ('pg_ft'):
[11478]91                    xmldict['institution_acct'] = '6230033428'
[9384]92                    xmldict['institution_bank_id'] = '51'
93            elif student.current_mode.endswith('_pt'):
[9389]94                self.pay_item_id = '5701'
[11478]95                if student.current_mode in ('ug_pt','de_pt'):
[9460]96                    xmldict['institution_acct'] = '0122009929'
[9384]97                    xmldict['institution_bank_id'] = '16'
[11725]98                elif student.current_mode in ('pg_pt', 'special_pg_pt'):
[12471]99                    xmldict['institution_acct'] = '4150033274'
100                    xmldict['institution_bank_id'] = '51'
[9384]101        elif self.context.p_category == 'clearance':
[9389]102            self.pay_item_id = '5702'
[9775]103            provider_amt = 1500.0
[9796]104            if student.faccode == 'FCETA':
105                xmldict['institution_acct'] = '5210007943'
106                xmldict['institution_bank_id'] = '51'
[11478]107            else:
108                xmldict['institution_bank_id'] = '10'
[9742]109                xmldict['institution_acct'] = '0031716047'
[9727]110        elif self.context.p_category == 'gown':
[9515]111            self.pay_item_id = '5704'
[11478]112            xmldict['institution_bank_id'] = '16'
113            xmldict['institution_acct'] = '0122011401'
[13301]114        elif self.context.p_category.startswith('bed_allocation'):
115            self.pay_item_id = '5716'
116            students_utils = getUtility(IStudentsUtils)
117            stage = students_utils.getAccommodationDetails(student)['bt']
118            stage = stage.split('_')[2]
119            if stage == 'fr':
120                union_dues = 500.0
121            else:
122                union_dues = 300.0
123            xmldict['institution_bank_id'] = '129'
124            xmldict['institution_acct'] = '0014419432'
125            xmldict['union_dues'] = 100 * union_dues
[9727]126        elif self.context.p_category.startswith('hostel_maintenance'):
127            self.pay_item_id = '5705'
[12471]128            xmldict['institution_bank_id'] = '129'
129            xmldict['institution_acct'] = '0014419432'
[9384]130
131        xmldict['provider_amt'] = 100 * provider_amt
132        xmldict['institution_item_name'] = self.category
[8263]133        xmldict['institution_name'] = INSTITUTION_NAME
[9384]134        xmldict['institution_amt'] = 100 * (
[9775]135            self.context.amount_auth - provider_amt - GATEWAY_AMT)
[13301]136
137        if self.context.p_category == 'bed_allocation':
138            xmldict['institution_amt'] = 100 * (
139                self.context.amount_auth - GATEWAY_AMT - union_dues)
[9515]140            xmltext = """<payment_item_detail>
[8263]141<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
142<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" />
[13301]143<item_detail item_id="2" item_name="UNION DUES" item_amt="%(union_dues)d" bank_id="31" acct_num="0005986952" />
[9515]144</item_details>
145</payment_item_detail>""" % xmldict
[13301]146        elif provider_amt == 0:
147            xmltext = """<payment_item_detail>
148<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
149<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" />
150</item_details>
151</payment_item_detail>""" % xmldict
[13111]152        elif self.context.p_category == 'schoolfee' and \
153            student.current_mode == 'ug_ft':
154            xmldict['institution_amt'] = 100 * (
155                self.context.amount_auth - provider_amt - GATEWAY_AMT - 3000)
156            xmltext = """<payment_item_detail>
157<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
158<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" />
159<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" />
[13183]160<item_detail item_id="3" item_name="T-SHIP" item_amt="200000" bank_id="72" acct_num="0061647254" />
161<item_detail item_id="4" item_name="MTN-NET LIBRARY" item_amt="100000" bank_id="8" acct_num="20177722298" />
[13111]162</item_details>
163</payment_item_detail>""" % xmldict
[9515]164        else:
165            xmltext = """<payment_item_detail>
166<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
167<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" />
[8263]168<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" />
169</item_details>
170</payment_item_detail>""" % xmldict
171        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9775]172        self.context.provider_amt = provider_amt
173        self.context.gateway_amt = GATEWAY_AMT
[7894]174        return
175
[11633]176class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[8256]177    """ View which sends a POST request to the Interswitch
178    CollegePAY payment gateway.
179    """
180    grok.context(ICustomApplicantOnlinePayment)
[8263]181    action = POST_ACTION
182    site_name = SITE_NAME
183    currency = CURRENCY
[8274]184    pay_item_id = '5703'
[8263]185    product_id = PRODUCT_ID
[8256]186
187    def update(self):
[11644]188        error = self.init_update()
189        if error:
190            self.flash(error, type='danger')
191            self.redirect(self.url(self.context, '@@index'))
192            return
[8256]193        xmldict = {}
[9775]194        provider_amt = 400.0
[13250]195        if self.applicant.applicant_id[:3] in ('pga', 'pgd'): # CERHI
[13243]196            xmldict['institution_acct'] = '1014312532'
197            xmldict['institution_bank_id'] = '117'
[13245]198        elif self.applicant.applicant_id.startswith('pg'):
[8568]199            xmldict['institution_acct'] = '0031716030'
200            xmldict['institution_bank_id'] = '10'
[9636]201        elif self.applicant.applicant_id.startswith('dp'):
202            xmldict['institution_acct'] = '9201805071'
203            xmldict['institution_bank_id'] = '17'
[10741]204        elif self.applicant.applicant_id.startswith('pt'):
205            xmldict['institution_acct'] = '9201805071'
206            xmldict['institution_bank_id'] = '17'
[13141]207        elif self.applicant.applicant_id.startswith('pre'):
208            xmldict['institution_acct'] = '1014315131'
209            xmldict['institution_bank_id'] = '117'
210        elif self.applicant.applicant_id.startswith('cbt'):
211            xmldict['institution_acct'] = '5030058259'
212            xmldict['institution_bank_id'] = '51'
[13143]213            provider_amt = 200.0
[8545]214        else:
[13186]215            xmldict['institution_acct'] = '1014326805'
216            xmldict['institution_bank_id'] = '117'
[8263]217        xmldict['detail_ref'] = self.context.p_id
[8545]218        xmldict['provider_amt'] = 100 * provider_amt
[8263]219        xmldict['provider_acct'] = PROVIDER_ACCT
220        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
221        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[9775]222        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
[8263]223        xmldict['institution_item_name'] = self.context.p_category
224        xmldict['institution_name'] = INSTITUTION_NAME
225        # Interswitch amount is not part of the xml data
226        xmltext = """<payment_item_detail>
227<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
228<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" />
229<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" />
230</item_details>
231</payment_item_detail>""" % xmldict
232        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9775]233        self.context.provider_amt = provider_amt
234        self.context.gateway_amt = GATEWAY_AMT
[8256]235        return
236
[11633]237class CustomInterswitchPaymentRequestWebservicePageStudent(
[9782]238    InterswitchPaymentRequestWebservicePageStudent):
[7919]239    """ Request webservice view for the CollegePAY gateway
240    """
[8255]241    grok.context(ICustomStudentOnlinePayment)
[9782]242    product_id = PRODUCT_ID
243    gateway_host = HOST
244    gateway_url = URL
[7919]245
[11633]246class CustomInterswitchPaymentRequestWebservicePageApplicant(
[9782]247    InterswitchPaymentRequestWebservicePageApplicant):
[8256]248    """ Request webservice view for the CollegePAY gateway
249    """
250    grok.context(ICustomApplicantOnlinePayment)
[9782]251    product_id = PRODUCT_ID
252    gateway_host = HOST
[11478]253    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.