source: main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/interswitch/browser.py @ 17936

Last change on this file since 17936 was 16400, checked in by Henrik Bettermann, 4 years ago

Only one lsfp_penalty fee. Use payment id 104.

  • Property svn:keywords set to Id
File size: 9.9 KB
RevLine 
[10765]1## $Id: browser.py 16400 2021-02-24 19:12:50Z 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 (
22    InterswitchPaymentRequestWebservicePageApplicant,
[11638]23    InterswitchPaymentRequestWebservicePageStudent,
[13587]24    InterswitchPaymentVerifyWebservicePageApplicant,
25    InterswitchPaymentVerifyWebservicePageStudent,
[11638]26    InterswitchPageStudent, InterswitchPageApplicant,
[10765]27    )
[14035]28from kofacustom.coewarri.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.coewarri.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.coewarri.interfaces import MessageFactory as _
[10765]31
[14129]32PRODUCT_ID = '6667'
[14035]33SITE_NAME = 'coewarri-kofa.waeup.org'
[15211]34PROVIDER_ACCT = '0427773399'
[14092]35PROVIDER_BANK_ID = '10'
[10765]36PROVIDER_ITEM_NAME = 'BT Education'
[14035]37INSTITUTION_NAME = 'COE Warri'
[10765]38CURRENCY = '566'
[14658]39GATEWAY_AMT = 250.0
[14344]40MAC = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94'
[14098]41
[14129]42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
43#POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
44HOST = 'webpay.interswitchng.com'
45#HOST = 'stageserv.interswitchng.com'
46URL = '/paydirect/api/v1/gettransaction.json'
47#URL = '/test_paydirect/api/v1/gettransaction.json'
[14097]48
[12479]49httplib.HTTPSConnection.debuglevel = 0
50HTTPS = True
[10765]51
[11638]52class CustomInterswitchPageStudent(InterswitchPageStudent):
[10765]53    """ View which sends a POST request to the Interswitch
54    CollegePAY payment gateway.
55    """
56    grok.context(ICustomStudentOnlinePayment)
57    action = POST_ACTION
58    site_name = SITE_NAME
59    currency = CURRENCY
60    product_id = PRODUCT_ID
[14344]61    mac = MAC
[10765]62
63    def update(self):
[12979]64        error = self.init_update()
65        if error:
66            self.flash(error, type='danger')
67            self.redirect(self.url(self.context, '@@index'))
68            return
[15776]69        self.context.r_company = u'interswitch'
[11647]70        student = self.student
71        xmldict = self.xmldict
[14342]72        self.pay_item_id = '0000'
[10765]73        # Provider data
74        xmldict['detail_ref'] = self.context.p_id
75        xmldict['provider_acct'] = PROVIDER_ACCT
76        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
77        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[14640]78        provider_amt = 0.0
[15328]79        share_amt = 0.0
[10765]80        # Institution data
[16380]81        xmldict['institution_acct'] = '2000746414'
82        xmldict['institution_bank_id'] = '8'
[12511]83        xmldict['institution_item_name'] = self.context.category
[10765]84        xmldict['institution_name'] = INSTITUTION_NAME
[14336]85        if self.context.p_category == 'clearance':
86            self.pay_item_id = '102'
[14640]87            provider_amt = 500.0
[14342]88        elif self.context.p_category.startswith('schoolfee'):
[14336]89            self.pay_item_id = '103'
[15321]90            if self.context.p_category in ('schoolfee_1', 'schoolfee_2') \
[14640]91                and not self.context.p_item == 'Balance':
[15328]92                provider_amt = 1400.0
93                share_amt = 600.0
[15321]94            if self.context.p_category == 'schoolfee' \
95                and not self.context.p_item == 'Balance':
[15328]96                provider_amt = 2800.0
97                share_amt = 1200.0
[16400]98        elif self.context.p_category == 'lsfp_penalty':
99            self.pay_item_id = '104'
100            xmldict['institution_acct'] = '1751080425'
101            xmldict['institution_bank_id'] = '120'
[14342]102        xmldict['provider_amt'] = 100 * provider_amt
[15328]103        xmldict['share_amt'] = 100 * share_amt
[14342]104        xmldict['institution_amt'] = 100 * (
[15335]105            self.context.amount_auth - provider_amt - share_amt - GATEWAY_AMT)
[14342]106
[10765]107        # Interswitch amount is not part of the xml data
108        if provider_amt == 0:
109            xmltext = """<payment_item_detail>
110<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
111<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" />
112</item_details>
113</payment_item_detail>""" % xmldict
[15328]114        elif share_amt == 0:
115            xmltext = """<payment_item_detail>
116<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
117<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" />
118<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" />
119</item_details>
120</payment_item_detail>""" % xmldict
[10765]121        else:
122            xmltext = """<payment_item_detail>
123<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
124<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" />
125<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" />
[15328]126<item_detail item_id="3" item_name="Tech Fee Share" item_amt="%(share_amt)d" bank_id="307" acct_num="5100189030" />
[10765]127</item_details>
128</payment_item_detail>""" % xmldict
129        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
130        self.context.provider_amt = provider_amt
131        self.context.gateway_amt = GATEWAY_AMT
[15776]132        self.amount_auth = int(100 * self.context.amount_auth)
[12479]133        hashargs = (
134            self.context.p_id +
135            PRODUCT_ID +
136            self.pay_item_id +
137            str(int(self.amount_auth)) +
138            self.site_redirect_url +
139            self.mac)
140        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
[10765]141        return
142
[11638]143class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[10765]144    """ View which sends a POST request to the Interswitch
145    CollegePAY payment gateway.
146    """
147    grok.context(ICustomApplicantOnlinePayment)
148    action = POST_ACTION
149    site_name = SITE_NAME
150    currency = CURRENCY
[14097]151    pay_item_id = '101'
[10765]152    product_id = PRODUCT_ID
[14344]153    mac = MAC
[10765]154
155    def update(self):
[12979]156        error = self.init_update()
157        if error:
158            self.flash(error, type='danger')
159            self.redirect(self.url(self.context, '@@index'))
160            return
[15776]161        self.context.r_company = u'interswitch'
[10765]162        xmldict = {}
[14092]163        provider_amt = 500.0
[16380]164        xmldict['institution_acct'] = '2000746414'
165        xmldict['institution_bank_id'] = '8'
[10765]166        xmldict['detail_ref'] = self.context.p_id
167        xmldict['provider_amt'] = 100 * provider_amt
168        xmldict['provider_acct'] = PROVIDER_ACCT
169        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
170        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
171        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
[12511]172        xmldict['institution_item_name'] = self.context.category
[10765]173        xmldict['institution_name'] = INSTITUTION_NAME
174        # Interswitch amount is not part of the xml data
175        xmltext = """<payment_item_detail>
176<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
177<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" />
178<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" />
179</item_details>
180</payment_item_detail>""" % xmldict
181        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
182        self.context.provider_amt = provider_amt
183        self.context.gateway_amt = GATEWAY_AMT
[15776]184        self.amount_auth = int(100 * self.context.amount_auth)
[12479]185        hashargs = (
186            self.context.p_id +
187            PRODUCT_ID +
188            self.pay_item_id +
189            str(int(self.amount_auth)) +
190            self.site_redirect_url +
191            self.mac)
192        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
[10765]193        return
194
[11638]195class CustomInterswitchPaymentRequestWebservicePageStudent(
[10765]196    InterswitchPaymentRequestWebservicePageStudent):
[13587]197    """Request webservice view for the CollegePAY gateway
[10765]198    """
199    grok.context(ICustomStudentOnlinePayment)
200    product_id = PRODUCT_ID
201    gateway_host = HOST
202    gateway_url = URL
[14344]203    mac = MAC
[10765]204
[13587]205class CustomInterswitchPaymentVerifyWebservicePageStudent(
206    InterswitchPaymentVerifyWebservicePageStudent):
207    """Payment verify view for the CollegePAY gateway
208    """
209    grok.context(ICustomStudentOnlinePayment)
210    product_id = PRODUCT_ID
211    gateway_host = HOST
212    gateway_url = URL
[14344]213    mac = MAC
[13587]214
[11638]215class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10765]216    InterswitchPaymentRequestWebservicePageApplicant):
[13587]217    """Request webservice view for the CollegePAY gateway
[10765]218    """
219    grok.context(ICustomApplicantOnlinePayment)
220    product_id = PRODUCT_ID
221    gateway_host = HOST
[12479]222    gateway_url = URL
[14344]223    mac = MAC
[13587]224
225class CustomInterswitchPaymentVerifyWebservicePageApplicant(
226    InterswitchPaymentVerifyWebservicePageApplicant):
227    """Payment verify view for the CollegePAY gateway
228    """
229    grok.context(ICustomApplicantOnlinePayment)
230    product_id = PRODUCT_ID
231    gateway_host = HOST
[14342]232    gateway_url = URL
[14344]233    mac = MAC
Note: See TracBrowser for help on using the repository browser.