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

Last change on this file since 17620 was 17620, checked in by Henrik Bettermann, 11 months ago

See ticket 52#comment:5

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