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

Last change on this file since 17394 was 17373, checked in by Henrik Bettermann, 18 months ago

Configure acceptance fee for diploma students.

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