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

Last change on this file since 16574 was 16574, checked in by Henrik Bettermann, 3 years ago

Use live gateway.

  • Property svn:keywords set to Id
File size: 12.5 KB
RevLine 
[10765]1## $Id: browser.py 16574 2021-08-17 09:52:07Z 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
[12479]19import hashlib
[10765]20import grok
21from kofacustom.nigeria.interswitch.browser import (
[15999]22    module_activated,
[10765]23    InterswitchPaymentRequestWebservicePageApplicant,
[11638]24    InterswitchPaymentRequestWebservicePageStudent,
[13587]25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
[11638]27    InterswitchPageStudent, InterswitchPageApplicant,
[10765]28    )
[16490]29from kofacustom.nigeria.interswitch.paydirectbrowser import (
[16574]30    PAYDirectPageStudent, PAYDirectPageApplicant,
31    StudentRefNumberSlip, ApplicantRefNumberSlip,
[16490]32    )
[15563]33from kofacustom.iuokada.students.interfaces import ICustomStudentOnlinePayment
34from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment
35from kofacustom.iuokada.interfaces import MessageFactory as _
[10765]36
[15728]37PRODUCT_ID = '7922'
[15563]38SITE_NAME = 'iuokada-kofa.waeup.org'
[15645]39PROVIDER_ACCT = '0773411069'
40PROVIDER_BANK_ID = '31'
41PROVIDER_ITEM_NAME = 'WAeAC'
[15563]42INSTITUTION_NAME = 'IUOkada'
[10765]43CURRENCY = '566'
[15728]44GATEWAY_AMT = 250.0
45#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch
46MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA'
[10765]47
[15728]48POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
49#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
50HOST = 'webpay.interswitchng.com'
51#HOST = 'sandbox.interswitchng.com'
52URL = '/paydirect/api/v1/gettransaction.json'
53#URL = '/webpay/api/v1/gettransaction.json'
[14276]54
[12479]55httplib.HTTPSConnection.debuglevel = 0
56HTTPS = True
[10765]57
[11638]58class CustomInterswitchPageStudent(InterswitchPageStudent):
[10765]59    """ View which sends a POST request to the Interswitch
60    CollegePAY payment gateway.
61    """
62    grok.context(ICustomStudentOnlinePayment)
63    action = POST_ACTION
64    site_name = SITE_NAME
65    currency = CURRENCY
66    product_id = PRODUCT_ID
[15269]67    mac = MAC 
[15773]68    gateway_amt = GATEWAY_AMT
[10765]69
70    def update(self):
[15999]71        if not module_activated(
72            self.context.student.current_session, self.context):
73            self.flash(_('Forbidden'), type='danger')
74            self.redirect(self.url(self.context, '@@index'))
75            return
[12979]76        error = self.init_update()
77        if error:
78            self.flash(error, type='danger')
79            self.redirect(self.url(self.context, '@@index'))
80            return
[15773]81        # Already now it becomes an Interswitch payment. We set the net amount
82        # and add the gateway amount.
83        if not self.context.r_company:
84            self.context.net_amt = self.context.amount_auth
85            self.context.amount_auth += self.gateway_amt
86            self.context.gateway_amt = self.gateway_amt
87            self.context.r_company = u'interswitch'
[11647]88        student = self.student
89        xmldict = self.xmldict
[10765]90        # Provider data
91        xmldict['detail_ref'] = self.context.p_id
92        xmldict['provider_acct'] = PROVIDER_ACCT
93        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
94        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[15728]95        xmldict['institution_acct'] = ''
96        xmldict['institution_bank_id'] = ''
[15773]97        provider_amt = 0.0
[15728]98        self.pay_item_id = ''
[10765]99        # Institution data
[15728]100        if self.context.p_category in (
101            'schoolfee', 'schoolfee40', 'secondinstal'):
102            self.pay_item_id = '101'
103        elif self.context.p_category == 'book':
104            self.pay_item_id = '103'
105        elif self.context.p_category == 'parentsconsult':
106            self.pay_item_id = '104'
[15794]107        elif self.context.p_category in (
108            'municipal_fresh', 'municipal_returning',
[16142]109            'transcript_local', 'transcript_overseas', 'transcript'):
[15794]110            self.pay_item_id = '105'
[15728]111        else:
112            self.pay_item_id = '102'
[16233]113        if self.context.p_category in (
[16395]114            'registration', 'required_combi', 'pg_other', 'jupeb_reg'):
[15728]115            provider_amt = 5000.0
[16047]116        if self.context.p_category in (
117            'schoolfee', 'schoolfee40') and student.is_jupeb:
118            provider_amt = 5000.0
[16395]119        if self.context.p_category.startswith('jupeb'):
120            self.pay_item_id = '102'
[10765]121        xmldict['provider_amt'] = 100 * provider_amt
[12511]122        xmldict['institution_item_name'] = self.context.category
[10765]123        xmldict['institution_name'] = INSTITUTION_NAME
[16270]124        xmldict['institution_amt'] = 100 * self.context.net_amt - (
125            100 * provider_amt)
[16434]126
127        if self.context.p_option == 'access':
128            xmldict['institution_acct'] = '0040484781'
129            xmldict['institution_bank_id'] = '31'
130        elif self.context.p_option == 'first':
131            xmldict['institution_acct'] = '2021420049'
132            xmldict['institution_bank_id'] = '8'
133        elif self.context.p_option == 'zenith':
134            xmldict['institution_acct'] = '1011005811'
135            xmldict['institution_bank_id'] = '117'
136        else:
137            xmldict['institution_acct'] = '0040484781'
138            xmldict['institution_bank_id'] = '31'
139
[10765]140        if provider_amt == 0:
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_details>
145</payment_item_detail>""" % xmldict
146        else:
147            xmltext = """<payment_item_detail>
148<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
149<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" />
150<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" />
151</item_details>
152</payment_item_detail>""" % xmldict
153        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[15773]154        self.amount_auth = int(100 * self.context.amount_auth)
[12479]155        hashargs = (
156            self.context.p_id +
157            PRODUCT_ID +
158            self.pay_item_id +
159            str(int(self.amount_auth)) +
160            self.site_redirect_url +
161            self.mac)
162        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
[10765]163        return
164
[11638]165class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[10765]166    """ View which sends a POST request to the Interswitch
167    CollegePAY payment gateway.
168    """
169    grok.context(ICustomApplicantOnlinePayment)
170    action = POST_ACTION
171    site_name = SITE_NAME
172    currency = CURRENCY
173    product_id = PRODUCT_ID
[15269]174    mac = MAC
[15773]175    gateway_amt = GATEWAY_AMT
[10765]176
177    def update(self):
[15999]178        if not module_activated(
179            self.context.__parent__.__parent__.year, self.context):
180            self.flash(_('Forbidden'), type='danger')
181            self.redirect(self.url(self.context, '@@index'))
182            return
[12979]183        error = self.init_update()
184        if error:
185            self.flash(error, type='danger')
186            self.redirect(self.url(self.context, '@@index'))
187            return
[15773]188        # Already now it becomes an Interswitch payment. We set the net amount
189        # and add the gateway amount.
190        if not self.context.r_company:
191            self.context.net_amt = self.context.amount_auth
192            self.context.amount_auth += self.gateway_amt
193            self.context.gateway_amt = self.gateway_amt
194            self.context.r_company = u'interswitch'
195        self.amount_auth = int(100 * self.context.amount_auth)
[10765]196        xmldict = {}
[15773]197        provider_amt = 0.0
[15786]198        self.pay_item_id = '101'
[15783]199        xmldict['institution_acct'] = '1011005811'
200        xmldict['institution_bank_id'] = '117'
[10765]201        xmldict['detail_ref'] = self.context.p_id
202        xmldict['provider_amt'] = 100 * provider_amt
203        xmldict['provider_acct'] = PROVIDER_ACCT
204        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
205        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[12511]206        xmldict['institution_item_name'] = self.context.category
[10765]207        xmldict['institution_name'] = INSTITUTION_NAME
[15773]208        xmldict['institution_amt'] = 100 * self.context.net_amt
209        if not self.context.provider_amt:
210            self.context.provider_amt = provider_amt
211            self.context.amount_auth += provider_amt
[15784]212        if provider_amt == 0:
213            xmltext = """<payment_item_detail>
[15785]214<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
[10765]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" />
[15784]216</item_details>
217</payment_item_detail>""" % xmldict
218        else:
219            xmltext = """<payment_item_detail>
[15785]220<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
[15784]221<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" />
[10765]222<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" />
223</item_details>
224</payment_item_detail>""" % xmldict
225        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[15773]226        self.amount_auth = int(100 * self.context.amount_auth)
[12479]227        hashargs = (
228            self.context.p_id +
229            PRODUCT_ID +
[15786]230            self.pay_item_id +
[12479]231            str(int(self.amount_auth)) +
232            self.site_redirect_url +
233            self.mac)
234        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
[10765]235        return
236
[11638]237class CustomInterswitchPaymentRequestWebservicePageStudent(
[10765]238    InterswitchPaymentRequestWebservicePageStudent):
[13587]239    """Request webservice view for the CollegePAY gateway
[10765]240    """
241    grok.context(ICustomStudentOnlinePayment)
242    product_id = PRODUCT_ID
243    gateway_host = HOST
244    gateway_url = URL
[15269]245    mac = MAC
[10765]246
[13587]247class CustomInterswitchPaymentVerifyWebservicePageStudent(
248    InterswitchPaymentVerifyWebservicePageStudent):
249    """Payment verify view for the CollegePAY gateway
250    """
251    grok.context(ICustomStudentOnlinePayment)
252    product_id = PRODUCT_ID
253    gateway_host = HOST
254    gateway_url = URL
[15269]255    mac = MAC
[13587]256
[11638]257class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10765]258    InterswitchPaymentRequestWebservicePageApplicant):
[13587]259    """Request webservice view for the CollegePAY gateway
[10765]260    """
261    grok.context(ICustomApplicantOnlinePayment)
262    product_id = PRODUCT_ID
263    gateway_host = HOST
[12479]264    gateway_url = URL
[15269]265    mac = MAC
[13587]266
267class CustomInterswitchPaymentVerifyWebservicePageApplicant(
268    InterswitchPaymentVerifyWebservicePageApplicant):
269    """Payment verify view for the CollegePAY gateway
270    """
271    grok.context(ICustomApplicantOnlinePayment)
272    product_id = PRODUCT_ID
273    gateway_host = HOST
[15269]274    gateway_url = URL
[16490]275    mac = MAC
276
277
278# PAYDirect added on 19/05/2021
279
[16574]280PAYDIRECT_HOST = 'orion.interswitchng.com'
281PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
282MERCHANT_ID = '8124'
283
[16490]284class CustomPAYDirectPageStudent(PAYDirectPageStudent):
285    """Inform student how to proceed
286    """
287    grok.context(ICustomStudentOnlinePayment)
288    gateway_amt = GATEWAY_AMT
[16574]289    merchant_id = MERCHANT_ID
290    gateway_url = PAYDIRECT_URL
291    gateway_host = PAYDIRECT_HOST
[16490]292    https = True
293
294class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
295    """ Inform applicant how to proceed.
296    """
297    grok.context(ICustomApplicantOnlinePayment)
298    gateway_amt = GATEWAY_AMT
[16574]299    merchant_id = MERCHANT_ID
300    gateway_url = PAYDIRECT_URL
301    gateway_host = PAYDIRECT_HOST
[16490]302    https = True
[16574]303
304class CustomStudentRefNumberSlip(StudentRefNumberSlip):
305    """Deliver a PDF slip of the context.
306    """
307    merchant_id = MERCHANT_ID
308
309class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
310    """Deliver a PDF slip of the context.
311    """
312    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.