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

Last change on this file since 17478 was 17478, checked in by Henrik Bettermann, 15 months ago

Chance IJMB bank account.

  • Property svn:keywords set to Id
File size: 13.7 KB
Line 
1## $Id: browser.py 17478 2023-07-10 01:42:13Z 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            if student.faccode == 'IJMB':
97                xmldict['institution_acct'] = '0093658062'
98        elif self.context.p_category == 'schoolfee':
99            provider_amt = 2800.0
100            tech_fee = 1200.0
101            xmldict['institution_acct'] = '1011739172'
102            if student.faccode in ('PRE', 'JUPEB'):
103                xmldict['institution_acct'] = '2001627961'
104                xmldict['institution_bank_id'] = '8'
105            if student.faccode == 'DELSU':
106                xmldict['institution_acct'] = '1011036493'
107            if student.faccode == 'NCE':
108                xmldict['institution_acct'] = '1011274462'
109                provider_amt = 4000.0
110                tech_fee = 0.0
111            if student.faccode == 'IJMB':
112                xmldict['institution_acct'] = '0093658062'
113            if student.current_mode.startswith('dp'):
114                xmldict['institution_acct'] = '2001627961'
115                xmldict['institution_bank_id'] = '8'
116        elif self.context.p_category == 'hostel_maintenance':
117            xmldict['institution_acct'] = '1012551384'
118        elif self.context.p_category == 'med_reg':
119            xmldict['institution_acct'] = '1011265606'
120        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
121        # Already now it becomes an Interswitch payment. We set the net amount
122        # and add gateway amount and other surcharges.
123        if not self.context.r_company:
124            self.context.r_company = u'interswitch'
125            self.context.net_amt = self.context.amount_auth
126            self.context.gateway_amt = self.gateway_amt
127            self.context.amount_auth += self.gateway_amt
128            self.context.provider_amt = provider_amt
129            self.context.amount_auth += provider_amt
130            self.context.amount_auth += tech_fee
131        xmldict['provider_amt'] = 100 * provider_amt
132        xmldict['tech_fee'] = 100 * tech_fee
133        xmldict['institution_item_name'] = self.context.category
134        xmldict['institution_name'] = INSTITUTION_NAME
135        xmldict['institution_amt'] = 100 * self.context.net_amt
136        if provider_amt == 0:
137            xmltext = """<payment_item_detail>
138<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
139<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" />
140</item_details>
141</payment_item_detail>""" % xmldict
142        elif tech_fee == 0:
143            xmltext = """<payment_item_detail>
144<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
145<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" />
146<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" />
147</item_details>
148</payment_item_detail>""" % xmldict
149        else:
150            xmltext = """<payment_item_detail>
151<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
152<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" />
153<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" />
154<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="47" acct_num="0213065415" />
155</item_details>
156</payment_item_detail>""" % xmldict
157        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
158        self.context.provider_amt = provider_amt
159        self.amount_auth = int(100 * self.context.amount_auth)
160        hashargs = (
161            self.context.p_id +
162            PRODUCT_ID +
163            self.pay_item_id +
164            str(int(self.amount_auth)) +
165            self.site_redirect_url +
166            self.mac)
167        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
168        return
169
170class CustomInterswitchPageApplicant(InterswitchPageApplicant):
171    """ View which sends a POST request to the Interswitch
172    CollegePAY payment gateway.
173    """
174    grok.context(ICustomApplicantOnlinePayment)
175    action = POST_ACTION
176    site_name = SITE_NAME
177    currency = CURRENCY
178    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
179    product_id = PRODUCT_ID
180    mac = MAC
181    gateway_amt = GATEWAY_AMT
182
183    def update(self):
184        if not module_activated(
185            self.context.__parent__.__parent__.year, self.context):
186            self.flash(_('Forbidden'), type='danger')
187            self.redirect(self.url(self.context, '@@index'))
188            return
189        error = self.init_update()
190        if error:
191            self.flash(error, type='danger')
192            self.redirect(self.url(self.context, '@@index'))
193            return
194        # Already now it becomes an Interswitch payment. We set the net amount
195        # and add the gateway amount.
196        if not self.context.r_company:
197            self.context.net_amt = self.context.amount_auth
198            self.context.amount_auth += self.gateway_amt
199            self.context.gateway_amt = self.gateway_amt
200            self.context.r_company = u'interswitch'
201        xmldict = {}
202        provider_amt = 250.0
203        xmldict['institution_acct'] = '1216063205'
204        xmldict['institution_bank_id'] = '117'
205        if self.context.__parent__.__parent__.prefix in (
206                                    'pre', 'jupeb', 'dpft', 'dppt',
207                                    'ugpt', 'ijmb'):
208            xmldict['institution_acct'] = '1011431799'
209            xmldict['institution_bank_id'] = '117'
210            provider_amt = 500.0           
211        if self.context.__parent__.__parent__.prefix in ('ijmb',):
212            xmldict['institution_acct'] = '0093658062'
213            xmldict['institution_bank_id'] = '121'
214        xmldict['detail_ref'] = self.context.p_id
215        xmldict['provider_amt'] = 100 * provider_amt
216        xmldict['provider_acct'] = PROVIDER_ACCT
217        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
218        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
219        xmldict['institution_item_name'] = self.context.category
220        xmldict['institution_name'] = INSTITUTION_NAME
221        xmldict['institution_amt'] = 100 * self.context.net_amt
222        if not self.context.provider_amt:
223            self.context.provider_amt = provider_amt
224            self.context.amount_auth += provider_amt
225        xmltext = """<payment_item_detail>
226<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
227<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" />
228<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" />
229</item_details>
230</payment_item_detail>""" % xmldict
231        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
232        self.amount_auth = int(100 * self.context.amount_auth)
233        hashargs = (
234            self.context.p_id +
235            PRODUCT_ID +
236            self.pay_item_id +
237            str(int(self.amount_auth)) +
238            self.site_redirect_url +
239            self.mac)
240        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
241        return
242
243class CustomInterswitchPaymentRequestWebservicePageStudent(
244    InterswitchPaymentRequestWebservicePageStudent):
245    """Request webservice view for the CollegePAY gateway
246    """
247    grok.context(ICustomStudentOnlinePayment)
248    product_id = PRODUCT_ID
249    gateway_host = HOST
250    gateway_url = URL
251    mac = MAC
252
253class CustomInterswitchPaymentVerifyWebservicePageStudent(
254    InterswitchPaymentVerifyWebservicePageStudent):
255    """Payment verify view for the CollegePAY gateway
256    """
257    grok.context(ICustomStudentOnlinePayment)
258    product_id = PRODUCT_ID
259    gateway_host = HOST
260    gateway_url = URL
261    mac = MAC
262
263class CustomInterswitchPaymentRequestWebservicePageApplicant(
264    InterswitchPaymentRequestWebservicePageApplicant):
265    """Request webservice view for the CollegePAY gateway
266    """
267    grok.context(ICustomApplicantOnlinePayment)
268    product_id = PRODUCT_ID
269    gateway_host = HOST
270    gateway_url = URL
271    mac = MAC
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
281    mac = MAC
282
283# PAYDirect
284
285from kofacustom.nigeria.interswitch.paydirectbrowser import (
286    PAYDirectPageStudent, PAYDirectPageApplicant,
287    StudentRefNumberSlip, ApplicantRefNumberSlip,
288    )
289
290from kofacustom.nigeria.interswitch.tests import (
291    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
292
293#PAYDIRECT_HOST = 'orion.interswitchng.com'
294#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
295#MERCHANT_ID = ''
296
297class CustomPAYDirectPageStudent(PAYDirectPageStudent):
298    """Inform student how to proceed
299    """
300    grok.context(ICustomStudentOnlinePayment)
301    gateway_amt = GATEWAY_AMT
302    merchant_id = MERCHANT_ID
303    gateway_url = PAYDIRECT_URL
304    gateway_host = PAYDIRECT_HOST
305    https = True
306
307class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
308    """ Inform applicant how to proceed.
309    """
310    grok.context(ICustomApplicantOnlinePayment)
311    gateway_amt = GATEWAY_AMT
312    merchant_id = MERCHANT_ID
313    gateway_url = PAYDIRECT_URL
314    gateway_host = PAYDIRECT_HOST
315    https = True
316
317class CustomStudentRefNumberSlip(StudentRefNumberSlip):
318    """Deliver a PDF slip of the context.
319    """
320    merchant_id = MERCHANT_ID
321
322class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
323    """Deliver a PDF slip of the context.
324    """
325    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.