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

Last change on this file since 16238 was 15776, checked in by Henrik Bettermann, 5 years ago

Adjust to Nigeria package.

Clearance/acceptance fee for nce_pt is 15000 for both local and non-local.

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