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

Last change on this file since 13328 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
Line 
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##
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    InterswitchPageStudent, InterswitchPageApplicant,
26    )
27from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
28from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment
29from waeup.uniben.interfaces import MessageFactory as _
30
31PRODUCT_ID = '57'
32SITE_NAME = 'uniben-kofa.waeup.org'
33PROVIDER_ACCT = '1010764827'
34PROVIDER_BANK_ID = '117'
35PROVIDER_ITEM_NAME = 'BT Education'
36INSTITUTION_NAME = 'Uniben'
37CURRENCY = '566'
38GATEWAY_AMT = 150.0
39#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
40#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
41POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
42#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
43
44HOST = 'webpay.interswitchng.com'
45#HOST = 'testwebpay.interswitchng.com'
46URL = '/paydirect/services/TransactionQueryWs.asmx'
47#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
48httplib.HTTPConnection.debuglevel = 0
49
50class CustomInterswitchPageStudent(InterswitchPageStudent):
51    """ View which sends a POST request to the Interswitch
52    CollegePAY payment gateway.
53    """
54    grok.context(ICustomStudentOnlinePayment)
55    action = POST_ACTION
56    site_name = SITE_NAME
57    currency = CURRENCY
58    product_id = PRODUCT_ID
59
60    def update(self):
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
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
74        xmldict['institution_acct'] = '000000000000'
75        xmldict['institution_bank_id'] = '00'
76        xmldict['institution_amt'] = '0.0'
77        provider_amt = 0.0
78        self.pay_item_id = '0000'
79        if self.context.p_category == 'schoolfee':
80            if not self.context.p_item == 'Balance':
81                provider_amt = 1500.0
82            if student.current_mode.endswith('_ft'):
83                self.pay_item_id = '5700'
84                if student.current_mode in ('ug_ft','de_ft','ume_ft'):
85                    xmldict['institution_acct'] = '2017506430'
86                    xmldict['institution_bank_id'] = '8'
87                elif student.current_mode in ('dp_ft','dp_pt','ct_pt','ct_ft'):
88                    xmldict['institution_acct'] = '0058653774'
89                    xmldict['institution_bank_id'] = '72'
90                elif student.current_mode in ('pg_ft'):
91                    xmldict['institution_acct'] = '6230033428'
92                    xmldict['institution_bank_id'] = '51'
93            elif student.current_mode.endswith('_pt'):
94                self.pay_item_id = '5701'
95                if student.current_mode in ('ug_pt','de_pt'):
96                    xmldict['institution_acct'] = '0122009929'
97                    xmldict['institution_bank_id'] = '16'
98                elif student.current_mode in ('pg_pt', 'special_pg_pt'):
99                    xmldict['institution_acct'] = '4150033274'
100                    xmldict['institution_bank_id'] = '51'
101        elif self.context.p_category == 'clearance':
102            self.pay_item_id = '5702'
103            provider_amt = 1500.0
104            if student.faccode == 'FCETA':
105                xmldict['institution_acct'] = '5210007943'
106                xmldict['institution_bank_id'] = '51'
107            else:
108                xmldict['institution_bank_id'] = '10'
109                xmldict['institution_acct'] = '0031716047'
110        elif self.context.p_category == 'gown':
111            self.pay_item_id = '5704'
112            xmldict['institution_bank_id'] = '16'
113            xmldict['institution_acct'] = '0122011401'
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
126        elif self.context.p_category.startswith('hostel_maintenance'):
127            self.pay_item_id = '5705'
128            xmldict['institution_bank_id'] = '129'
129            xmldict['institution_acct'] = '0014419432'
130
131        xmldict['provider_amt'] = 100 * provider_amt
132        xmldict['institution_item_name'] = self.category
133        xmldict['institution_name'] = INSTITUTION_NAME
134        xmldict['institution_amt'] = 100 * (
135            self.context.amount_auth - provider_amt - GATEWAY_AMT)
136
137        if self.context.p_category == 'bed_allocation':
138            xmldict['institution_amt'] = 100 * (
139                self.context.amount_auth - GATEWAY_AMT - union_dues)
140            xmltext = """<payment_item_detail>
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" />
143<item_detail item_id="2" item_name="UNION DUES" item_amt="%(union_dues)d" bank_id="31" acct_num="0005986952" />
144</item_details>
145</payment_item_detail>""" % xmldict
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
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" />
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" />
162</item_details>
163</payment_item_detail>""" % xmldict
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" />
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
172        self.context.provider_amt = provider_amt
173        self.context.gateway_amt = GATEWAY_AMT
174        return
175
176class CustomInterswitchPageApplicant(InterswitchPageApplicant):
177    """ View which sends a POST request to the Interswitch
178    CollegePAY payment gateway.
179    """
180    grok.context(ICustomApplicantOnlinePayment)
181    action = POST_ACTION
182    site_name = SITE_NAME
183    currency = CURRENCY
184    pay_item_id = '5703'
185    product_id = PRODUCT_ID
186
187    def update(self):
188        error = self.init_update()
189        if error:
190            self.flash(error, type='danger')
191            self.redirect(self.url(self.context, '@@index'))
192            return
193        xmldict = {}
194        provider_amt = 400.0
195        if self.applicant.applicant_id[:3] in ('pga', 'pgd'): # CERHI
196            xmldict['institution_acct'] = '1014312532'
197            xmldict['institution_bank_id'] = '117'
198        elif self.applicant.applicant_id.startswith('pg'):
199            xmldict['institution_acct'] = '0031716030'
200            xmldict['institution_bank_id'] = '10'
201        elif self.applicant.applicant_id.startswith('dp'):
202            xmldict['institution_acct'] = '9201805071'
203            xmldict['institution_bank_id'] = '17'
204        elif self.applicant.applicant_id.startswith('pt'):
205            xmldict['institution_acct'] = '9201805071'
206            xmldict['institution_bank_id'] = '17'
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'
213            provider_amt = 200.0
214        else:
215            xmldict['institution_acct'] = '1014326805'
216            xmldict['institution_bank_id'] = '117'
217        xmldict['detail_ref'] = self.context.p_id
218        xmldict['provider_amt'] = 100 * provider_amt
219        xmldict['provider_acct'] = PROVIDER_ACCT
220        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
221        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
222        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
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
233        self.context.provider_amt = provider_amt
234        self.context.gateway_amt = GATEWAY_AMT
235        return
236
237class CustomInterswitchPaymentRequestWebservicePageStudent(
238    InterswitchPaymentRequestWebservicePageStudent):
239    """ Request webservice view for the CollegePAY gateway
240    """
241    grok.context(ICustomStudentOnlinePayment)
242    product_id = PRODUCT_ID
243    gateway_host = HOST
244    gateway_url = URL
245
246class CustomInterswitchPaymentRequestWebservicePageApplicant(
247    InterswitchPaymentRequestWebservicePageApplicant):
248    """ Request webservice view for the CollegePAY gateway
249    """
250    grok.context(ICustomApplicantOnlinePayment)
251    product_id = PRODUCT_ID
252    gateway_host = HOST
253    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.