source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/interswitch/browser.py @ 17459

Last change on this file since 17459 was 17459, checked in by Henrik Bettermann, 17 months ago

Change bank account for DELSU.

  • Property svn:keywords set to Id
File size: 13.4 KB
Line 
1## $Id: browser.py 17459 2023-06-28 09:04:34Z 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 hashlib
20import grok
21from kofacustom.nigeria.interswitch.browser import (
22    module_activated,
23    InterswitchPaymentRequestWebservicePageApplicant,
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
29from kofacustom.unidel.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.unidel.interfaces import MessageFactory as _
32
33PRODUCT_ID = '22153701' # must be provided by Interswitch
34SITE_NAME = 'unidel.waeup.org'
35PROVIDER_ACCT = '0213065415'
36PROVIDER_BANK_ID = '47'
37PROVIDER_ITEM_NAME = 'WAeAC'
38INSTITUTION_NAME = 'UNIDEL'
39CURRENCY = '566'
40GATEWAY_AMT = 250.0
41#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
42MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi'
43
44POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay'
45#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
46HOST = 'webpay.interswitchng.com'
47#HOST = 'sandbox.interswitchng.com'
48URL = '/collections/api/v1/gettransaction.json'
49#URL = '/webpay/api/v1/gettransaction.json'
50
51httplib.HTTPSConnection.debuglevel = 0
52HTTPS = True
53
54class CustomInterswitchPageStudent(InterswitchPageStudent):
55    """ View which sends a POST request to the Interswitch
56    CollegePAY payment gateway.
57    """
58    grok.context(ICustomStudentOnlinePayment)
59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
63    mac = MAC
64    gateway_amt = GATEWAY_AMT
65
66    def update(self):
67        if not module_activated(
68            self.context.student.current_session, self.context):
69            self.flash(_('Forbidden'), type='danger')
70            self.redirect(self.url(self.context, '@@index'))
71            return
72        error = self.init_update()
73        if error:
74            self.flash(error, type='danger')
75            self.redirect(self.url(self.context, '@@index'))
76            return
77        student = self.student
78        xmldict = self.xmldict
79        # Provider data
80        xmldict['detail_ref'] = self.context.p_id
81        xmldict['provider_acct'] = PROVIDER_ACCT
82        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
83        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
84        # Institution data
85        xmldict['institution_acct'] = '000000000'
86        xmldict['institution_bank_id'] = '117'
87        provider_amt = 0.0
88        tech_fee = 0.0
89        if self.context.p_category == 'clearance':
90            provider_amt = 500.0
91            xmldict['institution_acct'] = '1216063205'
92            if student.faccode in ('PRE', 'JUPEB'):
93                xmldict['institution_acct'] = '1011431799'
94            if student.current_mode.startswith('dp'):
95                xmldict['institution_acct'] = '1011431799'
96        elif self.context.p_category == 'schoolfee':
97            provider_amt = 2800.0
98            tech_fee = 1200.0
99            xmldict['institution_acct'] = '1011739172'
100            if student.faccode in ('PRE', 'JUPEB'):
101                xmldict['institution_acct'] = '2001627961'
102                xmldict['institution_bank_id'] = '8'
103            if student.faccode == 'DELSU':
104                xmldict['institution_acct'] = '1011036493'
105            if student.faccode == 'NCE':
106                xmldict['institution_acct'] = '1011274462'
107                provider_amt = 4000.0
108                tech_fee = 0.0
109            if student.current_mode.startswith('dp'):
110                xmldict['institution_acct'] = '2001627961'
111                xmldict['institution_bank_id'] = '8'
112        elif self.context.p_category == 'hostel_maintenance':
113            xmldict['institution_acct'] = '1012551384'
114        elif self.context.p_category == 'med_reg':
115            xmldict['institution_acct'] = '1011265606'
116        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
117        # Already now it becomes an Interswitch payment. We set the net amount
118        # and add gateway amount and other surcharges.
119        if not self.context.r_company:
120            self.context.r_company = u'interswitch'
121            self.context.net_amt = self.context.amount_auth
122            self.context.gateway_amt = self.gateway_amt
123            self.context.amount_auth += self.gateway_amt
124            self.context.provider_amt = provider_amt
125            self.context.amount_auth += provider_amt
126            self.context.amount_auth += tech_fee
127        xmldict['provider_amt'] = 100 * provider_amt
128        xmldict['tech_fee'] = 100 * tech_fee
129        xmldict['institution_item_name'] = self.context.category
130        xmldict['institution_name'] = INSTITUTION_NAME
131        xmldict['institution_amt'] = 100 * self.context.net_amt
132        if provider_amt == 0:
133            xmltext = """<payment_item_detail>
134<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
135<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" />
136</item_details>
137</payment_item_detail>""" % xmldict
138        elif tech_fee == 0:
139            xmltext = """<payment_item_detail>
140<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
141<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" />
142<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" />
143</item_details>
144</payment_item_detail>""" % xmldict
145        else:
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="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
150<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="47" acct_num="0213065415" />
151</item_details>
152</payment_item_detail>""" % xmldict
153        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
154        self.context.provider_amt = provider_amt
155        self.amount_auth = int(100 * self.context.amount_auth)
156        hashargs = (
157            self.context.p_id +
158            PRODUCT_ID +
159            self.pay_item_id +
160            str(int(self.amount_auth)) +
161            self.site_redirect_url +
162            self.mac)
163        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
164        return
165
166class CustomInterswitchPageApplicant(InterswitchPageApplicant):
167    """ View which sends a POST request to the Interswitch
168    CollegePAY payment gateway.
169    """
170    grok.context(ICustomApplicantOnlinePayment)
171    action = POST_ACTION
172    site_name = SITE_NAME
173    currency = CURRENCY
174    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
175    product_id = PRODUCT_ID
176    mac = MAC
177    gateway_amt = GATEWAY_AMT
178
179    def update(self):
180        if not module_activated(
181            self.context.__parent__.__parent__.year, self.context):
182            self.flash(_('Forbidden'), type='danger')
183            self.redirect(self.url(self.context, '@@index'))
184            return
185        error = self.init_update()
186        if error:
187            self.flash(error, type='danger')
188            self.redirect(self.url(self.context, '@@index'))
189            return
190        # Already now it becomes an Interswitch payment. We set the net amount
191        # and add the gateway amount.
192        if not self.context.r_company:
193            self.context.net_amt = self.context.amount_auth
194            self.context.amount_auth += self.gateway_amt
195            self.context.gateway_amt = self.gateway_amt
196            self.context.r_company = u'interswitch'
197        xmldict = {}
198        provider_amt = 250.0
199        xmldict['institution_acct'] = '1216063205'
200        xmldict['institution_bank_id'] = '117'
201        if self.context.__parent__.__parent__.prefix in (
202                                    'pre', 'jupeb', 'dpft', 'dppt',
203                                    'ugpt', 'ijmb'):
204            xmldict['institution_acct'] = '1011431799'
205            xmldict['institution_bank_id'] = '117'
206            provider_amt = 500.0           
207        xmldict['detail_ref'] = self.context.p_id
208        xmldict['provider_amt'] = 100 * provider_amt
209        xmldict['provider_acct'] = PROVIDER_ACCT
210        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
211        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
212        xmldict['institution_item_name'] = self.context.category
213        xmldict['institution_name'] = INSTITUTION_NAME
214        xmldict['institution_amt'] = 100 * self.context.net_amt
215        if not self.context.provider_amt:
216            self.context.provider_amt = provider_amt
217            self.context.amount_auth += provider_amt
218        xmltext = """<payment_item_detail>
219<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
220<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" />
221<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" />
222</item_details>
223</payment_item_detail>""" % xmldict
224        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
225        self.amount_auth = int(100 * self.context.amount_auth)
226        hashargs = (
227            self.context.p_id +
228            PRODUCT_ID +
229            self.pay_item_id +
230            str(int(self.amount_auth)) +
231            self.site_redirect_url +
232            self.mac)
233        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
234        return
235
236class CustomInterswitchPaymentRequestWebservicePageStudent(
237    InterswitchPaymentRequestWebservicePageStudent):
238    """Request webservice view for the CollegePAY gateway
239    """
240    grok.context(ICustomStudentOnlinePayment)
241    product_id = PRODUCT_ID
242    gateway_host = HOST
243    gateway_url = URL
244    mac = MAC
245
246class CustomInterswitchPaymentVerifyWebservicePageStudent(
247    InterswitchPaymentVerifyWebservicePageStudent):
248    """Payment verify view for the CollegePAY gateway
249    """
250    grok.context(ICustomStudentOnlinePayment)
251    product_id = PRODUCT_ID
252    gateway_host = HOST
253    gateway_url = URL
254    mac = MAC
255
256class CustomInterswitchPaymentRequestWebservicePageApplicant(
257    InterswitchPaymentRequestWebservicePageApplicant):
258    """Request webservice view for the CollegePAY gateway
259    """
260    grok.context(ICustomApplicantOnlinePayment)
261    product_id = PRODUCT_ID
262    gateway_host = HOST
263    gateway_url = URL
264    mac = MAC
265
266class CustomInterswitchPaymentVerifyWebservicePageApplicant(
267    InterswitchPaymentVerifyWebservicePageApplicant):
268    """Payment verify view for the CollegePAY gateway
269    """
270    grok.context(ICustomApplicantOnlinePayment)
271    product_id = PRODUCT_ID
272    gateway_host = HOST
273    gateway_url = URL
274    mac = MAC
275
276# PAYDirect
277
278from kofacustom.nigeria.interswitch.paydirectbrowser import (
279    PAYDirectPageStudent, PAYDirectPageApplicant,
280    StudentRefNumberSlip, ApplicantRefNumberSlip,
281    )
282
283from kofacustom.nigeria.interswitch.tests import (
284    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
285
286#PAYDIRECT_HOST = 'orion.interswitchng.com'
287#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
288#MERCHANT_ID = ''
289
290class CustomPAYDirectPageStudent(PAYDirectPageStudent):
291    """Inform student how to proceed
292    """
293    grok.context(ICustomStudentOnlinePayment)
294    gateway_amt = GATEWAY_AMT
295    merchant_id = MERCHANT_ID
296    gateway_url = PAYDIRECT_URL
297    gateway_host = PAYDIRECT_HOST
298    https = True
299
300class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
301    """ Inform applicant how to proceed.
302    """
303    grok.context(ICustomApplicantOnlinePayment)
304    gateway_amt = GATEWAY_AMT
305    merchant_id = MERCHANT_ID
306    gateway_url = PAYDIRECT_URL
307    gateway_host = PAYDIRECT_HOST
308    https = True
309
310class CustomStudentRefNumberSlip(StudentRefNumberSlip):
311    """Deliver a PDF slip of the context.
312    """
313    merchant_id = MERCHANT_ID
314
315class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
316    """Deliver a PDF slip of the context.
317    """
318    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.