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

Last change on this file since 17839 was 17839, checked in by Henrik Bettermann, 4 months ago

Add fee.

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