source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/interswitch/browser.py @ 17660

Last change on this file since 17660 was 17646, checked in by Henrik Bettermann, 10 months ago

Fix bank id.

  • Property svn:keywords set to Id
File size: 14.4 KB
Line 
1## $Id: browser.py 17646 2023-11-22 18:50:01Z 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.unidel.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.unidel.interfaces import MessageFactory as _
32
33PRODUCT_ID = '22153701' # must be provided by Interswitch
34SITE_NAME = 'unidel.waeup.org'
35PROVIDER_ACCT = '0213065415'
36PROVIDER_BANK_ID = '47'
37PROVIDER_ITEM_NAME = 'WAeAC'
38INSTITUTION_NAME = 'UNIDEL'
39CURRENCY = '566'
40GATEWAY_AMT = 250.0
41#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
42MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi'
43
44POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay'
45#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
46HOST = 'webpay.interswitchng.com'
47#HOST = 'sandbox.interswitchng.com'
48URL = '/collections/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        student = self.student
78        xmldict = self.xmldict
79        # Provider data
80        xmldict['detail_ref'] = self.context.p_id
81        xmldict['provider_acct'] = PROVIDER_ACCT
82        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
83        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
84        # Institution data
85        xmldict['institution_acct'] = '000000000'
86        xmldict['institution_bank_id'] = '117'
87        provider_amt = 0.0
88        tech_fee = 0.0
89        if self.context.p_category == 'clearance':
90            provider_amt = 500.0
91            if student.current_mode in ('ug_ft', 'de_ft'):
92                xmldict['institution_acct'] = '1216063205'
93                tech_fee = 18000.0
94                xmldict['tech_acct'] = '0092304647'
95                xmldict['tech_bank_id'] = '121'
96            if student.faccode in ('PRE', 'JUPEB'):
97                xmldict['institution_acct'] = '1011431799'
98            if student.current_mode.startswith('dp'):
99                xmldict['institution_acct'] = '1011431799'
100            if student.faccode == 'IJMB':
101                xmldict['institution_acct'] = '0093658062'
102                xmldict['institution_bank_id'] = '121'
103            if self.context.p_item == 'Balance':
104                provider_amt = 0.0
105                tech_fee = 0.0
106        elif self.context.p_category == 'schoolfee':
107            provider_amt = 2800.0
108            tech_fee = 1200.0
109            xmldict['institution_acct'] = '1011739172'
110            xmldict['tech_acct'] = '0213065415'
111            xmldict['tech_bank_id'] = '47'
112            if student.faccode in ('PRE', 'JUPEB'):
113                xmldict['institution_acct'] = '2001627961'
114                xmldict['institution_bank_id'] = '8'
115            if student.faccode == 'DELSU':
116                xmldict['institution_acct'] = '1011036493'
117            if student.faccode == 'NCE':
118                xmldict['institution_acct'] = '1011274462'
119                provider_amt = 4000.0
120                tech_fee = 0.0
121            if student.faccode == 'IJMB':
122                xmldict['institution_acct'] = '0093658062'
123                xmldict['institution_bank_id'] = '121'
124            if student.current_mode.startswith('dp'):
125                xmldict['institution_acct'] = '2001627961'
126                xmldict['institution_bank_id'] = '8'
127            if self.context.p_item == 'Balance':
128                provider_amt = 0.0
129                tech_fee = 0.0
130        elif self.context.p_category == 'hostel_maintenance':
131            xmldict['institution_acct'] = '1012551384'
132        elif self.context.p_category == 'med_reg':
133            xmldict['institution_acct'] = '1011265606'
134        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
135        # Already now it becomes an Interswitch payment. We set the net amount
136        # and add gateway amount and other surcharges.
137        if not self.context.r_company:
138            self.context.r_company = u'interswitch'
139            self.context.net_amt = self.context.amount_auth
140            self.context.gateway_amt = self.gateway_amt
141            self.context.amount_auth += self.gateway_amt
142            self.context.provider_amt = provider_amt
143            self.context.amount_auth += provider_amt
144            self.context.amount_auth += tech_fee
145        xmldict['provider_amt'] = 100 * provider_amt
146        xmldict['tech_fee'] = 100 * tech_fee
147        xmldict['institution_item_name'] = self.context.category
148        xmldict['institution_name'] = INSTITUTION_NAME
149        xmldict['institution_amt'] = 100 * self.context.net_amt
150        if provider_amt == 0:
151            xmltext = """<payment_item_detail>
152<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
153<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" />
154</item_details>
155</payment_item_detail>""" % xmldict
156        elif tech_fee == 0:
157            xmltext = """<payment_item_detail>
158<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
159<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" />
160<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" />
161</item_details>
162</payment_item_detail>""" % xmldict
163        else:
164            xmltext = """<payment_item_detail>
165<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
166<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" />
167<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" />
168<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="%(tech_bank_id)s" acct_num="%(tech_acct)s"/>
169</item_details>
170</payment_item_detail>""" % xmldict
171        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
172        self.context.provider_amt = provider_amt
173        self.amount_auth = int(100 * self.context.amount_auth)
174        hashargs = (
175            self.context.p_id +
176            PRODUCT_ID +
177            self.pay_item_id +
178            str(int(self.amount_auth)) +
179            self.site_redirect_url +
180            self.mac)
181        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
182        return
183
184class CustomInterswitchPageApplicant(InterswitchPageApplicant):
185    """ View which sends a POST request to the Interswitch
186    CollegePAY payment gateway.
187    """
188    grok.context(ICustomApplicantOnlinePayment)
189    action = POST_ACTION
190    site_name = SITE_NAME
191    currency = CURRENCY
192    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
193    product_id = PRODUCT_ID
194    mac = MAC
195    gateway_amt = GATEWAY_AMT
196
197    def update(self):
198        if not module_activated(
199            self.context.__parent__.__parent__.year, self.context):
200            self.flash(_('Forbidden'), type='danger')
201            self.redirect(self.url(self.context, '@@index'))
202            return
203        error = self.init_update()
204        if error:
205            self.flash(error, type='danger')
206            self.redirect(self.url(self.context, '@@index'))
207            return
208        # Already now it becomes an Interswitch payment. We set the net amount
209        # and add the gateway amount.
210        if not self.context.r_company:
211            self.context.net_amt = self.context.amount_auth
212            self.context.amount_auth += self.gateway_amt
213            self.context.gateway_amt = self.gateway_amt
214            self.context.r_company = u'interswitch'
215        xmldict = {}
216        provider_amt = 250.0
217        xmldict['institution_acct'] = '1216063205'
218        xmldict['institution_bank_id'] = '117'
219        if self.context.__parent__.__parent__.prefix in (
220                                    'pre', 'jupeb', 'dpft', 'dppt',
221                                    'ugpt', 'ijmb', 'df'):
222            xmldict['institution_acct'] = '1011431799'
223            xmldict['institution_bank_id'] = '117'
224            provider_amt = 500.0           
225        if self.context.__parent__.__parent__.prefix in ('ijmb',):
226            xmldict['institution_acct'] = '0093658062'
227            xmldict['institution_bank_id'] = '121'
228        xmldict['detail_ref'] = self.context.p_id
229        xmldict['provider_amt'] = 100 * provider_amt
230        xmldict['provider_acct'] = PROVIDER_ACCT
231        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
232        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
233        xmldict['institution_item_name'] = self.context.category
234        xmldict['institution_name'] = INSTITUTION_NAME
235        xmldict['institution_amt'] = 100 * self.context.net_amt
236        if not self.context.provider_amt:
237            self.context.provider_amt = provider_amt
238            self.context.amount_auth += provider_amt
239        xmltext = """<payment_item_detail>
240<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
241<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" />
242<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" />
243</item_details>
244</payment_item_detail>""" % xmldict
245        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
246        self.amount_auth = int(100 * self.context.amount_auth)
247        hashargs = (
248            self.context.p_id +
249            PRODUCT_ID +
250            self.pay_item_id +
251            str(int(self.amount_auth)) +
252            self.site_redirect_url +
253            self.mac)
254        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
255        return
256
257class CustomInterswitchPaymentRequestWebservicePageStudent(
258    InterswitchPaymentRequestWebservicePageStudent):
259    """Request webservice view for the CollegePAY gateway
260    """
261    grok.context(ICustomStudentOnlinePayment)
262    product_id = PRODUCT_ID
263    gateway_host = HOST
264    gateway_url = URL
265    mac = MAC
266
267class CustomInterswitchPaymentVerifyWebservicePageStudent(
268    InterswitchPaymentVerifyWebservicePageStudent):
269    """Payment verify view for the CollegePAY gateway
270    """
271    grok.context(ICustomStudentOnlinePayment)
272    product_id = PRODUCT_ID
273    gateway_host = HOST
274    gateway_url = URL
275    mac = MAC
276
277class CustomInterswitchPaymentRequestWebservicePageApplicant(
278    InterswitchPaymentRequestWebservicePageApplicant):
279    """Request webservice view for the CollegePAY gateway
280    """
281    grok.context(ICustomApplicantOnlinePayment)
282    product_id = PRODUCT_ID
283    gateway_host = HOST
284    gateway_url = URL
285    mac = MAC
286
287class CustomInterswitchPaymentVerifyWebservicePageApplicant(
288    InterswitchPaymentVerifyWebservicePageApplicant):
289    """Payment verify view for the CollegePAY gateway
290    """
291    grok.context(ICustomApplicantOnlinePayment)
292    product_id = PRODUCT_ID
293    gateway_host = HOST
294    gateway_url = URL
295    mac = MAC
296
297# PAYDirect
298
299from kofacustom.nigeria.interswitch.paydirectbrowser import (
300    PAYDirectPageStudent, PAYDirectPageApplicant,
301    StudentRefNumberSlip, ApplicantRefNumberSlip,
302    )
303
304from kofacustom.nigeria.interswitch.tests import (
305    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
306
307#PAYDIRECT_HOST = 'orion.interswitchng.com'
308#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
309#MERCHANT_ID = ''
310
311class CustomPAYDirectPageStudent(PAYDirectPageStudent):
312    """Inform student how to proceed
313    """
314    grok.context(ICustomStudentOnlinePayment)
315    gateway_amt = GATEWAY_AMT
316    merchant_id = MERCHANT_ID
317    gateway_url = PAYDIRECT_URL
318    gateway_host = PAYDIRECT_HOST
319    https = True
320
321class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
322    """ Inform applicant how to proceed.
323    """
324    grok.context(ICustomApplicantOnlinePayment)
325    gateway_amt = GATEWAY_AMT
326    merchant_id = MERCHANT_ID
327    gateway_url = PAYDIRECT_URL
328    gateway_host = PAYDIRECT_HOST
329    https = True
330
331class CustomStudentRefNumberSlip(StudentRefNumberSlip):
332    """Deliver a PDF slip of the context.
333    """
334    merchant_id = MERCHANT_ID
335
336class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
337    """Deliver a PDF slip of the context.
338    """
339    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.