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

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

Add JUPEB fee categories.

  • Property svn:keywords set to Id
File size: 11.4 KB
Line 
1## $Id: browser.py 16395 2021-02-15 13:16:44Z 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-kofa.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            xmldict['institution_acct'] = '1011005811'
99            xmldict['institution_bank_id'] = '117'
100            self.pay_item_id = '101'
101        elif self.context.p_category == 'book':
102            xmldict['institution_acct'] = '1013249587'
103            xmldict['institution_bank_id'] = '117'
104            self.pay_item_id = '103'
105        elif self.context.p_category == 'parentsconsult':
106            xmldict['institution_acct'] = '1012355544'
107            xmldict['institution_bank_id'] = '117'
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            xmldict['institution_acct'] = '0040621193'
113            xmldict['institution_bank_id'] = '31'
114            self.pay_item_id = '105'
115        else:
116            xmldict['institution_acct'] = '1011050158'
117            xmldict['institution_bank_id'] = '117'
118            self.pay_item_id = '102'
119        if self.context.p_category in (
120            'registration', 'required_combi', 'pg_other', 'jupeb_reg'):
121            provider_amt = 5000.0
122        if self.context.p_category in (
123            'schoolfee', 'schoolfee40') and student.is_jupeb:
124            provider_amt = 5000.0
125        if self.context.p_category.startswith('jupeb'):
126            xmldict['institution_acct'] = '0787077169'
127            xmldict['institution_bank_id'] = '31'
128            self.pay_item_id = '102'
129        xmldict['provider_amt'] = 100 * provider_amt
130        xmldict['institution_item_name'] = self.context.category
131        xmldict['institution_name'] = INSTITUTION_NAME
132        xmldict['institution_amt'] = 100 * self.context.net_amt - (
133            100 * provider_amt)
134        if provider_amt == 0:
135            xmltext = """<payment_item_detail>
136<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
137<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" />
138</item_details>
139</payment_item_detail>""" % xmldict
140        else:
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_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" />
145</item_details>
146</payment_item_detail>""" % xmldict
147        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
148        self.amount_auth = int(100 * self.context.amount_auth)
149        hashargs = (
150            self.context.p_id +
151            PRODUCT_ID +
152            self.pay_item_id +
153            str(int(self.amount_auth)) +
154            self.site_redirect_url +
155            self.mac)
156        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
157        return
158
159class CustomInterswitchPageApplicant(InterswitchPageApplicant):
160    """ View which sends a POST request to the Interswitch
161    CollegePAY payment gateway.
162    """
163    grok.context(ICustomApplicantOnlinePayment)
164    action = POST_ACTION
165    site_name = SITE_NAME
166    currency = CURRENCY
167    product_id = PRODUCT_ID
168    mac = MAC
169    gateway_amt = GATEWAY_AMT
170
171    def update(self):
172        if not module_activated(
173            self.context.__parent__.__parent__.year, self.context):
174            self.flash(_('Forbidden'), type='danger')
175            self.redirect(self.url(self.context, '@@index'))
176            return
177        error = self.init_update()
178        if error:
179            self.flash(error, type='danger')
180            self.redirect(self.url(self.context, '@@index'))
181            return
182        # Already now it becomes an Interswitch payment. We set the net amount
183        # and add the gateway amount.
184        if not self.context.r_company:
185            self.context.net_amt = self.context.amount_auth
186            self.context.amount_auth += self.gateway_amt
187            self.context.gateway_amt = self.gateway_amt
188            self.context.r_company = u'interswitch'
189        self.amount_auth = int(100 * self.context.amount_auth)
190        xmldict = {}
191        provider_amt = 0.0
192        self.pay_item_id = '101'
193        xmldict['institution_acct'] = '1011005811'
194        xmldict['institution_bank_id'] = '117'
195        xmldict['detail_ref'] = self.context.p_id
196        xmldict['provider_amt'] = 100 * provider_amt
197        xmldict['provider_acct'] = PROVIDER_ACCT
198        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
199        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
200        xmldict['institution_item_name'] = self.context.category
201        xmldict['institution_name'] = INSTITUTION_NAME
202        xmldict['institution_amt'] = 100 * self.context.net_amt
203        if not self.context.provider_amt:
204            self.context.provider_amt = provider_amt
205            self.context.amount_auth += provider_amt
206        if provider_amt == 0:
207            xmltext = """<payment_item_detail>
208<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
209<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" />
210</item_details>
211</payment_item_detail>""" % xmldict
212        else:
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_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" />
217</item_details>
218</payment_item_detail>""" % xmldict
219        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
220        self.amount_auth = int(100 * self.context.amount_auth)
221        hashargs = (
222            self.context.p_id +
223            PRODUCT_ID +
224            self.pay_item_id +
225            str(int(self.amount_auth)) +
226            self.site_redirect_url +
227            self.mac)
228        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
229        return
230
231class CustomInterswitchPaymentRequestWebservicePageStudent(
232    InterswitchPaymentRequestWebservicePageStudent):
233    """Request webservice view for the CollegePAY gateway
234    """
235    grok.context(ICustomStudentOnlinePayment)
236    product_id = PRODUCT_ID
237    gateway_host = HOST
238    gateway_url = URL
239    mac = MAC
240
241class CustomInterswitchPaymentVerifyWebservicePageStudent(
242    InterswitchPaymentVerifyWebservicePageStudent):
243    """Payment verify view for the CollegePAY gateway
244    """
245    grok.context(ICustomStudentOnlinePayment)
246    product_id = PRODUCT_ID
247    gateway_host = HOST
248    gateway_url = URL
249    mac = MAC
250
251class CustomInterswitchPaymentRequestWebservicePageApplicant(
252    InterswitchPaymentRequestWebservicePageApplicant):
253    """Request webservice view for the CollegePAY gateway
254    """
255    grok.context(ICustomApplicantOnlinePayment)
256    product_id = PRODUCT_ID
257    gateway_host = HOST
258    gateway_url = URL
259    mac = MAC
260
261class CustomInterswitchPaymentVerifyWebservicePageApplicant(
262    InterswitchPaymentVerifyWebservicePageApplicant):
263    """Payment verify view for the CollegePAY gateway
264    """
265    grok.context(ICustomApplicantOnlinePayment)
266    product_id = PRODUCT_ID
267    gateway_host = HOST
268    gateway_url = URL
269    mac = MAC
Note: See TracBrowser for help on using the repository browser.