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

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

Uups, accidentally checked in.

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