source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/interswitch/browser.py @ 17938

Last change on this file since 17938 was 17900, checked in by Henrik Bettermann, 3 months ago

Add registration payment categories.

  • Property svn:keywords set to Id
File size: 13.7 KB
Line 
1## $Id: browser.py 17900 2024-08-21 08:09:35Z 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.iuokada.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.iuokada.interfaces import MessageFactory as _
32
33PRODUCT_ID = '7922'
34SITE_NAME = 'iuokada.waeup.org'
35PROVIDER_ACCT = '0773411069'
36PROVIDER_BANK_ID = '31'
37PROVIDER_ITEM_NAME = 'WAeAC'
38INSTITUTION_NAME = 'IUOkada'
39CURRENCY = '566'
40GATEWAY_AMT = 250.0
41#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch
42MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA'
43
44POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
45#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
46HOST = 'webpay.interswitchng.com'
47#HOST = 'sandbox.interswitchng.com'
48URL = '/paydirect/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        # Already now it becomes an Interswitch payment. We set the net amount
78        # and add the gateway amount.
79        if not self.context.r_company:
80            self.context.net_amt = self.context.amount_auth
81            self.context.amount_auth += self.gateway_amt
82            self.context.gateway_amt = self.gateway_amt
83            self.context.r_company = u'interswitch'
84        student = self.student
85        xmldict = self.xmldict
86        # Provider data
87        xmldict['detail_ref'] = self.context.p_id
88        xmldict['provider_acct'] = PROVIDER_ACCT
89        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
90        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
91        xmldict['institution_acct'] = ''
92        xmldict['institution_bank_id'] = ''
93        provider_amt = 0.0
94        self.pay_item_id = ''
95        # Institution data
96        if self.context.p_category in (
97            'schoolfee', 'schoolfee40', 'secondinstal'):
98            self.pay_item_id = '101'
99        elif self.context.p_category == 'book':
100            self.pay_item_id = '103'
101        elif self.context.p_category == 'parentsconsult':
102            self.pay_item_id = '104'
103        elif self.context.p_category in (
104            'municipal_fresh', 'municipal_returning',
105            'transcript_local', 'transcript_overseas', 'transcript'):
106            self.pay_item_id = '105'
107        else:
108            self.pay_item_id = '102'
109        if self.context.p_category in (
110            'registration', 'registration_fresh', 'registration_return',
111            'required_combi', 'pg_other', 'jupeb_reg'):
112            provider_amt = 5000.0
113        if self.context.p_category in (
114            'schoolfee', 'schoolfee40') and student.is_jupeb:
115            provider_amt = 5000.0
116        if self.context.p_category.startswith('jupeb'):
117            self.pay_item_id = '102'
118        xmldict['provider_amt'] = 100 * provider_amt
119        xmldict['institution_item_name'] = self.context.category
120        xmldict['institution_name'] = INSTITUTION_NAME
121        xmldict['institution_amt'] = 100 * self.context.net_amt - (
122            100 * provider_amt)
123
124        if grok.getSite().__name__ == 'iuokada-cdl':
125            xmldict['institution_acct'] = '1229771245'
126            xmldict['institution_bank_id'] = '117'
127            if self.context.p_category.startswith('schoolfee'):
128                xmldict['institution_acct'] = '1828332878'
129                xmldict['institution_bank_id'] = '31'
130        else:
131            if self.context.p_option == 'access':
132                xmldict['institution_acct'] = '0040484781'
133                xmldict['institution_bank_id'] = '31'
134            elif self.context.p_option == 'first':
135                xmldict['institution_acct'] = '2021420049'
136                xmldict['institution_bank_id'] = '8'
137            elif self.context.p_option == 'zenith':
138                xmldict['institution_acct'] = '1011005811'
139                xmldict['institution_bank_id'] = '117'
140            else:
141                xmldict['institution_acct'] = '0040484781'
142                xmldict['institution_bank_id'] = '31'
143
144            # Overwrite above selection
145            if self.context.p_category == 'book':
146                xmldict['institution_acct'] = '1228744877'
147                xmldict['institution_bank_id'] = '117'
148            elif self.context.p_category == 'parentsconsult':
149                xmldict['institution_acct'] = '1228747029'
150                xmldict['institution_bank_id'] = '117'
151            elif self.context.p_category == 'health_insurance':
152                xmldict['institution_acct'] = '1228744884'
153                xmldict['institution_bank_id'] = '117'
154
155        if provider_amt == 0:
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_details>
160</payment_item_detail>""" % xmldict
161        else:
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_details>
167</payment_item_detail>""" % xmldict
168        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
169        self.amount_auth = int(100 * self.context.amount_auth)
170        hashargs = (
171            self.context.p_id +
172            PRODUCT_ID +
173            self.pay_item_id +
174            str(int(self.amount_auth)) +
175            self.site_redirect_url +
176            self.mac)
177        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
178        return
179
180class CustomInterswitchPageApplicant(InterswitchPageApplicant):
181    """ View which sends a POST request to the Interswitch
182    CollegePAY payment gateway.
183    """
184    grok.context(ICustomApplicantOnlinePayment)
185    action = POST_ACTION
186    site_name = SITE_NAME
187    currency = CURRENCY
188    product_id = PRODUCT_ID
189    mac = MAC
190    gateway_amt = GATEWAY_AMT
191
192    def update(self):
193        if not module_activated(
194            self.context.__parent__.__parent__.year, self.context):
195            self.flash(_('Forbidden'), type='danger')
196            self.redirect(self.url(self.context, '@@index'))
197            return
198        error = self.init_update()
199        if error:
200            self.flash(error, type='danger')
201            self.redirect(self.url(self.context, '@@index'))
202            return
203        # Already now it becomes an Interswitch payment. We set the net amount
204        # and add the gateway amount.
205        if not self.context.r_company:
206            self.context.net_amt = self.context.amount_auth
207            self.context.amount_auth += self.gateway_amt
208            self.context.gateway_amt = self.gateway_amt
209            self.context.r_company = u'interswitch'
210        self.amount_auth = int(100 * self.context.amount_auth)
211        xmldict = {}
212        provider_amt = 0.0
213        self.pay_item_id = '101'
214        xmldict['institution_acct'] = '1011005811'
215        xmldict['institution_bank_id'] = '117'
216        if grok.getSite().__name__ == 'iuokada-cdl':
217            xmldict['institution_acct'] = '1229774710'
218            xmldict['institution_bank_id'] = '117'
219        xmldict['detail_ref'] = self.context.p_id
220        xmldict['provider_amt'] = 100 * provider_amt
221        xmldict['provider_acct'] = PROVIDER_ACCT
222        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
223        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
224        xmldict['institution_item_name'] = self.context.category
225        xmldict['institution_name'] = INSTITUTION_NAME
226        xmldict['institution_amt'] = 100 * self.context.net_amt
227        if not self.context.provider_amt:
228            self.context.provider_amt = provider_amt
229            self.context.amount_auth += provider_amt
230        if provider_amt == 0:
231            xmltext = """<payment_item_detail>
232<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
233<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" />
234</item_details>
235</payment_item_detail>""" % xmldict
236        else:
237            xmltext = """<payment_item_detail>
238<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
239<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" />
240<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" />
241</item_details>
242</payment_item_detail>""" % xmldict
243        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
244        self.amount_auth = int(100 * self.context.amount_auth)
245        hashargs = (
246            self.context.p_id +
247            PRODUCT_ID +
248            self.pay_item_id +
249            str(int(self.amount_auth)) +
250            self.site_redirect_url +
251            self.mac)
252        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
253        return
254
255class CustomInterswitchPaymentRequestWebservicePageStudent(
256    InterswitchPaymentRequestWebservicePageStudent):
257    """Request webservice view for the CollegePAY gateway
258    """
259    grok.context(ICustomStudentOnlinePayment)
260    product_id = PRODUCT_ID
261    gateway_host = HOST
262    gateway_url = URL
263    mac = MAC
264
265class CustomInterswitchPaymentVerifyWebservicePageStudent(
266    InterswitchPaymentVerifyWebservicePageStudent):
267    """Payment verify view for the CollegePAY gateway
268    """
269    grok.context(ICustomStudentOnlinePayment)
270    product_id = PRODUCT_ID
271    gateway_host = HOST
272    gateway_url = URL
273    mac = MAC
274
275class CustomInterswitchPaymentRequestWebservicePageApplicant(
276    InterswitchPaymentRequestWebservicePageApplicant):
277    """Request webservice view for the CollegePAY gateway
278    """
279    grok.context(ICustomApplicantOnlinePayment)
280    product_id = PRODUCT_ID
281    gateway_host = HOST
282    gateway_url = URL
283    mac = MAC
284
285class CustomInterswitchPaymentVerifyWebservicePageApplicant(
286    InterswitchPaymentVerifyWebservicePageApplicant):
287    """Payment verify view for the CollegePAY gateway
288    """
289    grok.context(ICustomApplicantOnlinePayment)
290    product_id = PRODUCT_ID
291    gateway_host = HOST
292    gateway_url = URL
293    mac = MAC
294
295
296# PAYDirect added on 19/05/2021
297
298from kofacustom.nigeria.interswitch.paydirectbrowser import (
299    PAYDirectPageStudent, PAYDirectPageApplicant,
300    StudentRefNumberSlip, ApplicantRefNumberSlip,
301    )
302
303PAYDIRECT_HOST = 'orion.interswitchng.com'
304PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
305MERCHANT_ID = '8124'
306
307class CustomPAYDirectPageStudent(PAYDirectPageStudent):
308    """Inform student how to proceed
309    """
310    grok.context(ICustomStudentOnlinePayment)
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 CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
318    """ Inform applicant how to proceed.
319    """
320    grok.context(ICustomApplicantOnlinePayment)
321    gateway_amt = GATEWAY_AMT
322    merchant_id = MERCHANT_ID
323    gateway_url = PAYDIRECT_URL
324    gateway_host = PAYDIRECT_HOST
325    https = True
326
327class CustomStudentRefNumberSlip(StudentRefNumberSlip):
328    """Deliver a PDF slip of the context.
329    """
330    merchant_id = MERCHANT_ID
331
332class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
333    """Deliver a PDF slip of the context.
334    """
335    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.