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

Last change on this file since 17932 was 17931, checked in by Henrik Bettermann, 7 weeks ago

New fees.

  • Property svn:keywords set to Id
File size: 15.3 KB
Line 
1## $Id: browser.py 17931 2024-09-30 16:44:34Z 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 = 2000.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            elif student.current_mode.startswith('dp'):
97                xmldict['institution_acct'] = '1011431799'
98            if student.faccode in ('PRE', 'JUPEB'):
99                xmldict['institution_acct'] = '1011431799'
100            elif 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 = 6650.0
108            tech_fee = 2850.0
109            if student.is_fresh:
110                provider_amt = 7000.0
111                tech_fee = 3000.0
112            xmldict['institution_acct'] = '1011739172'
113            xmldict['tech_acct'] = '0213065415'
114            xmldict['tech_bank_id'] = '47'
115            if student.current_mode.startswith('dp'):
116                xmldict['institution_acct'] = '2001627961'
117                xmldict['institution_bank_id'] = '8'
118            if student.faccode in ('PRE', 'JUPEB'):
119                xmldict['institution_acct'] = '2001627961'
120                xmldict['institution_bank_id'] = '8'
121            elif student.faccode == 'DELSU':
122                xmldict['institution_acct'] = '1011036493'
123            elif student.faccode == 'NCE':
124                xmldict['institution_acct'] = '1011274462'
125                provider_amt = 4000.0
126                tech_fee = 0.0
127            elif student.faccode == 'IJMB':
128                xmldict['institution_acct'] = '0093658062'
129                xmldict['institution_bank_id'] = '121'
130            elif student.faccode in ('FMED', 'FBM', 'FLW'):
131                xmldict['institution_acct'] = '1011274462'
132            elif student.certcode == 'DFFPA':
133                xmldict['institution_acct'] = '2001627961'
134                xmldict['institution_bank_id'] = '8'
135                provider_amt = 4000.0
136                tech_fee = 0.0
137            if self.context.p_item == 'Balance':
138                provider_amt = 0.0
139                tech_fee = 0.0
140        elif self.context.p_category.startswith('ijmb'):
141                xmldict['institution_acct'] = '0093658062'
142                xmldict['institution_bank_id'] = '121'
143        elif self.context.p_category == 'hostel_maintenance':
144            xmldict['institution_acct'] = '1012551384'
145        elif self.context.p_category == 'med_reg':
146            xmldict['institution_acct'] = '1011265606'
147        elif self.context.p_category == 'teaching_practice':
148            xmldict['institution_acct'] = '1005399320'
149            xmldict['institution_bank_id'] = '8'
150        elif self.context.p_category.startswith('transcript'):
151            xmldict['institution_acct'] = '0010494552'
152            xmldict['institution_bank_id'] = '129'
153            provider_amt = 2000.0
154        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
155        # Already now it becomes an Interswitch payment. We set the net amount
156        # and add gateway amount and other surcharges.
157        if not self.context.r_company:
158            self.context.r_company = u'interswitch'
159            self.context.net_amt = self.context.amount_auth
160            self.context.gateway_amt = self.gateway_amt
161            self.context.amount_auth += self.gateway_amt
162            self.context.provider_amt = provider_amt
163            self.context.amount_auth += provider_amt
164            self.context.amount_auth += tech_fee
165        xmldict['provider_amt'] = 100 * provider_amt
166        xmldict['tech_fee'] = 100 * tech_fee
167        xmldict['institution_item_name'] = self.context.category
168        xmldict['institution_name'] = INSTITUTION_NAME
169        xmldict['institution_amt'] = 100 * self.context.net_amt
170        if provider_amt == 0:
171            xmltext = """<payment_item_detail>
172<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
173<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" />
174</item_details>
175</payment_item_detail>""" % xmldict
176        elif tech_fee == 0:
177            xmltext = """<payment_item_detail>
178<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
179<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" />
180<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" />
181</item_details>
182</payment_item_detail>""" % xmldict
183        else:
184            xmltext = """<payment_item_detail>
185<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
186<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" />
187<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" />
188<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"/>
189</item_details>
190</payment_item_detail>""" % xmldict
191        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
192        self.context.provider_amt = provider_amt
193        self.amount_auth = int(100 * self.context.amount_auth)
194        hashargs = (
195            self.context.p_id +
196            PRODUCT_ID +
197            self.pay_item_id +
198            str(int(self.amount_auth)) +
199            self.site_redirect_url +
200            self.mac)
201        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
202        return
203
204class CustomInterswitchPageApplicant(InterswitchPageApplicant):
205    """ View which sends a POST request to the Interswitch
206    CollegePAY payment gateway.
207    """
208    grok.context(ICustomApplicantOnlinePayment)
209    action = POST_ACTION
210    site_name = SITE_NAME
211    currency = CURRENCY
212    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
213    product_id = PRODUCT_ID
214    mac = MAC
215    gateway_amt = GATEWAY_AMT
216
217    def update(self):
218        if not module_activated(
219            self.context.__parent__.__parent__.year, self.context):
220            self.flash(_('Forbidden'), type='danger')
221            self.redirect(self.url(self.context, '@@index'))
222            return
223        error = self.init_update()
224        if error:
225            self.flash(error, type='danger')
226            self.redirect(self.url(self.context, '@@index'))
227            return
228        # Already now it becomes an Interswitch payment. We set the net amount
229        # and add the gateway amount.
230        if not self.context.r_company:
231            self.context.net_amt = self.context.amount_auth
232            self.context.amount_auth += self.gateway_amt
233            self.context.gateway_amt = self.gateway_amt
234            self.context.r_company = u'interswitch'
235        xmldict = {}
236        provider_amt = 250.0
237        xmldict['institution_acct'] = '1216063205'
238        xmldict['institution_bank_id'] = '117'
239        if self.context.__parent__.__parent__.prefix in (
240                                    'pre', 'jupeb', 'dpft', 'dppt',
241                                    'ugpt', 'ijmb', 'df'):
242            xmldict['institution_acct'] = '1011431799'
243            xmldict['institution_bank_id'] = '117'
244            provider_amt = 500.0           
245        if self.context.__parent__.__parent__.prefix in ('ijmb',):
246            xmldict['institution_acct'] = '0093658062'
247            xmldict['institution_bank_id'] = '121'
248        xmldict['detail_ref'] = self.context.p_id
249        xmldict['provider_amt'] = 100 * provider_amt
250        xmldict['provider_acct'] = PROVIDER_ACCT
251        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
252        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
253        xmldict['institution_item_name'] = self.context.category
254        xmldict['institution_name'] = INSTITUTION_NAME
255        xmldict['institution_amt'] = 100 * self.context.net_amt
256        if not self.context.provider_amt:
257            self.context.provider_amt = provider_amt
258            self.context.amount_auth += provider_amt
259        xmltext = """<payment_item_detail>
260<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
261<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" />
262<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" />
263</item_details>
264</payment_item_detail>""" % xmldict
265        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
266        self.amount_auth = int(100 * self.context.amount_auth)
267        hashargs = (
268            self.context.p_id +
269            PRODUCT_ID +
270            self.pay_item_id +
271            str(int(self.amount_auth)) +
272            self.site_redirect_url +
273            self.mac)
274        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
275        return
276
277class CustomInterswitchPaymentRequestWebservicePageStudent(
278    InterswitchPaymentRequestWebservicePageStudent):
279    """Request webservice view for the CollegePAY gateway
280    """
281    grok.context(ICustomStudentOnlinePayment)
282    product_id = PRODUCT_ID
283    gateway_host = HOST
284    gateway_url = URL
285    mac = MAC
286
287class CustomInterswitchPaymentVerifyWebservicePageStudent(
288    InterswitchPaymentVerifyWebservicePageStudent):
289    """Payment verify view for the CollegePAY gateway
290    """
291    grok.context(ICustomStudentOnlinePayment)
292    product_id = PRODUCT_ID
293    gateway_host = HOST
294    gateway_url = URL
295    mac = MAC
296
297class CustomInterswitchPaymentRequestWebservicePageApplicant(
298    InterswitchPaymentRequestWebservicePageApplicant):
299    """Request webservice view for the CollegePAY gateway
300    """
301    grok.context(ICustomApplicantOnlinePayment)
302    product_id = PRODUCT_ID
303    gateway_host = HOST
304    gateway_url = URL
305    mac = MAC
306
307class CustomInterswitchPaymentVerifyWebservicePageApplicant(
308    InterswitchPaymentVerifyWebservicePageApplicant):
309    """Payment verify view for the CollegePAY gateway
310    """
311    grok.context(ICustomApplicantOnlinePayment)
312    product_id = PRODUCT_ID
313    gateway_host = HOST
314    gateway_url = URL
315    mac = MAC
316
317# PAYDirect
318
319from kofacustom.nigeria.interswitch.paydirectbrowser import (
320    PAYDirectPageStudent, PAYDirectPageApplicant,
321    StudentRefNumberSlip, ApplicantRefNumberSlip,
322    )
323
324from kofacustom.nigeria.interswitch.tests import (
325    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
326
327#PAYDIRECT_HOST = 'orion.interswitchng.com'
328#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
329#MERCHANT_ID = ''
330
331class CustomPAYDirectPageStudent(PAYDirectPageStudent):
332    """Inform student how to proceed
333    """
334    grok.context(ICustomStudentOnlinePayment)
335    gateway_amt = GATEWAY_AMT
336    merchant_id = MERCHANT_ID
337    gateway_url = PAYDIRECT_URL
338    gateway_host = PAYDIRECT_HOST
339    https = True
340
341class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
342    """ Inform applicant how to proceed.
343    """
344    grok.context(ICustomApplicantOnlinePayment)
345    gateway_amt = GATEWAY_AMT
346    merchant_id = MERCHANT_ID
347    gateway_url = PAYDIRECT_URL
348    gateway_host = PAYDIRECT_HOST
349    https = True
350
351class CustomStudentRefNumberSlip(StudentRefNumberSlip):
352    """Deliver a PDF slip of the context.
353    """
354    merchant_id = MERCHANT_ID
355
356class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
357    """Deliver a PDF slip of the context.
358    """
359    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.