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

Last change on this file since 16573 was 16490, checked in by Henrik Bettermann, 4 years ago

Initialize customization of PAYDirect components.

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