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

Last change on this file since 16686 was 16686, checked in by Henrik Bettermann, 3 years ago

Remove unused code.

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