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

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

Add Interswitch verification components.

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