source: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/interswitch/browser.py

Last change on this file was 17936, checked in by Henrik Bettermann, 5 weeks ago

Switch to production system.

  • Property svn:keywords set to Id
File size: 12.7 KB
Line 
1## $Id: browser.py 17936 2024-10-04 22:26:13Z 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    module_activated,
28    )
29from kofacustom.nigeria.interswitch.webcheckoutbrowser import (
30    webcheckout_module_activated,
31    WebCheckoutPageStudent,
32    WebCheckoutPageApplicant,
33    WebCheckoutConfirmTransactionStudent,
34    WebCheckoutConfirmTransactionApplicant,
35    )
36from kofacustom.edopoly.students.interfaces import ICustomStudentOnlinePayment
37from kofacustom.edopoly.applicants.interfaces import ICustomApplicantOnlinePayment
38from kofacustom.edopoly.interfaces import MessageFactory as _
39
40PRODUCT_ID = '7571' # must be provided by Interswitch
41SITE_NAME = 'edopoly-kofa.waeup.org'
42PROVIDER_ACCT = '0773411069'
43PROVIDER_BANK_ID = '31'
44PROVIDER_ITEM_NAME = 'WAeAC'
45INSTITUTION_NAME = 'EdoPoly'
46CURRENCY = '566'
47GATEWAY_AMT = 250.0
48MAC = '672ABFB2F3755A7793DE545BDA00F44878DF59140B43A1E7DF16245D299F3108AFF65502F16D95256B3242B43CBC3F512A208EB1BA977080D65328800C49912C'
49
50POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
51#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
52HOST = 'webpay.interswitchng.com'
53#HOST = 'sandbox.interswitchng.com'
54URL = '/paydirect/api/v1/gettransaction.json'
55#URL = '/webpay/api/v1/gettransaction.json'
56
57httplib.HTTPSConnection.debuglevel = 0
58HTTPS = True
59
60SPECIAL_PAYMENT_PARAMS = {
61
62    'conv_nd': ('101', 1000.0, '0031913976', '121'),
63    'conv_hnd': ('101', 1000.0, '0031913976', '121'),
64    }
65
66
67class CustomInterswitchPageStudent(InterswitchPageStudent):
68    """ View which sends a POST request to the Interswitch
69    CollegePAY payment gateway.
70    """
71    grok.context(ICustomStudentOnlinePayment)
72    action = POST_ACTION
73    site_name = SITE_NAME
74    currency = CURRENCY
75    product_id = PRODUCT_ID
76    mac = MAC
77
78    def update(self):
79        if not module_activated(
80            self.context.student.current_session, self.context):
81            self.flash(_('Forbidden'), type='danger')
82            self.redirect(self.url(self.context, '@@index'))
83            return
84        error = self.init_update()
85        if error:
86            self.flash(error, type='danger')
87            self.redirect(self.url(self.context, '@@index'))
88            return
89        self.context.r_company = u'interswitch'
90        student = self.student
91        xmldict = self.xmldict
92        # Provider data
93        xmldict['detail_ref'] = self.context.p_id
94        xmldict['provider_acct'] = PROVIDER_ACCT
95        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
96        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
97        provider_amt = 0.0
98        if not self.context.p_item == 'Balance':
99            if self.context.p_category == 'ict_entre':
100                provider_amt = 3000.0
101            if self.context.p_category == 'clearance':
102                provider_amt = 1500.0
103            # temporarily disabled
104            #if self.context.p_category in ('transcript', 'certificate'):
105            #    provider_amt = 2000.0
106        # Institution data
107        xmldict['institution_acct'] = '0068241848'
108        xmldict['institution_bank_id'] = '121'
109        if self.context.p_category == 'union':
110            xmldict['institution_acct'] = '0066437412'
111        if self.context.p_category == 'nhis':
112            xmldict['institution_acct'] = '0075379404'
113        if self.context.p_category == 'cyber':
114            xmldict['institution_acct'] = '1220055070'
115            xmldict['institution_bank_id'] = '117'
116        if self.context.p_category == 'ispon':
117            xmldict['institution_acct'] = '1220055104'
118            xmldict['institution_bank_id'] = '117'
119        xmldict['institution_amt'] = '0.0'
120        self.pay_item_id = '101' # must be provided by Interswitch
121        xmldict['provider_amt'] = 100 * provider_amt
122        xmldict['institution_item_name'] = self.context.category
123        xmldict['institution_name'] = INSTITUTION_NAME
124        xmldict['institution_amt'] = 100 * (
125            self.context.amount_auth - provider_amt - GATEWAY_AMT)
126        # Interswitch amount is not part of the xml data
127        if provider_amt == 0:
128            xmltext = """<payment_item_detail>
129<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
130<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" />
131</item_details>
132</payment_item_detail>""" % xmldict
133        else:
134            xmltext = """<payment_item_detail>
135<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
136<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" />
137<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" />
138</item_details>
139</payment_item_detail>""" % xmldict
140        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
141        self.context.provider_amt = provider_amt
142        self.context.gateway_amt = GATEWAY_AMT
143        self.amount_auth = int(100 * self.context.amount_auth)
144        hashargs = (
145            self.context.p_id +
146            PRODUCT_ID +
147            self.pay_item_id +
148            str(int(self.amount_auth)) +
149            self.site_redirect_url +
150            self.mac)
151        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
152        return
153
154class CustomInterswitchPageApplicant(InterswitchPageApplicant):
155    """ View which sends a POST request to the Interswitch
156    CollegePAY payment gateway.
157    """
158    grok.context(ICustomApplicantOnlinePayment)
159    action = POST_ACTION
160    site_name = SITE_NAME
161    currency = CURRENCY
162    pay_item_id = '101' # must be provided by Interswitch
163    product_id = PRODUCT_ID
164    mac = MAC
165
166    def update(self):
167        if not module_activated(
168            self.context.__parent__.__parent__.year, self.context):
169            self.flash(_('Forbidden'), type='danger')
170            self.redirect(self.url(self.context, '@@index'))
171            return
172        error = self.init_update()
173        if error:
174            self.flash(error, type='danger')
175            self.redirect(self.url(self.context, '@@index'))
176            return
177        self.context.r_company = u'interswitch'
178        xmldict = {}
179        provider_amt = 1000.0
180        if self.context.p_category != 'application':
181            provider_amt = 0.0
182        xmldict['institution_acct'] = '0068241848'
183        xmldict['institution_bank_id'] = '121'
184        xmldict['detail_ref'] = self.context.p_id
185        xmldict['provider_amt'] = 100 * provider_amt
186        xmldict['provider_acct'] = PROVIDER_ACCT
187        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
188        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
189        xmldict['institution_amt'] = 100 * (
190            self.context.amount_auth - provider_amt - GATEWAY_AMT)
191        xmldict['institution_item_name'] = self.context.category
192        xmldict['institution_name'] = INSTITUTION_NAME
193        if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
194            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
195            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[
196                self.context.p_category][2]
197            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[
198                self.context.p_category][3]
199            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
200            xmldict['institution_amt'] = 100 * (
201                self.context.amount_auth - provider_amt - GATEWAY_AMT)
202            xmldict['provider_amt'] = 100 * provider_amt
203        # Interswitch amount is not part of the xml data
204        if provider_amt == 0:
205            xmltext = """<payment_item_detail>
206<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
207<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" />
208</item_details>
209</payment_item_detail>""" % xmldict
210        else:
211            xmltext = """<payment_item_detail>
212<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
213<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" />
214<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" />
215</item_details>
216</payment_item_detail>""" % xmldict
217
218        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
219        self.context.provider_amt = provider_amt
220        self.context.gateway_amt = GATEWAY_AMT
221        self.amount_auth = int(100 * self.context.amount_auth)
222        hashargs = (
223            self.context.p_id +
224            PRODUCT_ID +
225            self.pay_item_id +
226            str(int(self.amount_auth)) +
227            self.site_redirect_url +
228            self.mac)
229        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
230        return
231
232class CustomInterswitchPaymentRequestWebservicePageStudent(
233    InterswitchPaymentRequestWebservicePageStudent):
234    """Request webservice view for the CollegePAY gateway
235    """
236    grok.context(ICustomStudentOnlinePayment)
237    product_id = PRODUCT_ID
238    gateway_host = HOST
239    gateway_url = URL
240    mac = MAC
241
242class CustomInterswitchPaymentVerifyWebservicePageStudent(
243    InterswitchPaymentVerifyWebservicePageStudent):
244    """Payment verify view for the CollegePAY gateway
245    """
246    grok.context(ICustomStudentOnlinePayment)
247    product_id = PRODUCT_ID
248    gateway_host = HOST
249    gateway_url = URL
250    mac = MAC
251
252class CustomInterswitchPaymentRequestWebservicePageApplicant(
253    InterswitchPaymentRequestWebservicePageApplicant):
254    """Request webservice view for the CollegePAY gateway
255    """
256    grok.context(ICustomApplicantOnlinePayment)
257    product_id = PRODUCT_ID
258    gateway_host = HOST
259    gateway_url = URL
260    mac = MAC
261
262class CustomInterswitchPaymentVerifyWebservicePageApplicant(
263    InterswitchPaymentVerifyWebservicePageApplicant):
264    """Payment verify view for the CollegePAY gateway
265    """
266    grok.context(ICustomApplicantOnlinePayment)
267    product_id = PRODUCT_ID
268    gateway_host = HOST
269    gateway_url = URL
270    mac = MAC
271
272# WebCheckout customizations
273
274MERCHANT_CODE = 'MX104253'
275PAY_ITEM_ID = 'Default_Payable_MX104253'
276
277class CustomWebCheckoutPageStudent(WebCheckoutPageStudent):
278    """ View which sends a POST request to the Interswitch
279    WebCheckout payment gateway.
280    """
281    action = 'https://newwebpay.interswitchng.com/collections/w/pay'
282    #action = 'https://newwebpay.qa.interswitchng.com/collections/w/pay'
283    currency = '566'
284    pay_item_id = PAY_ITEM_ID
285    merchant_code = MERCHANT_CODE
286    gateway_amt = 0.0
287    product_id = PRODUCT_ID
288
289class CustomWebCheckoutPageApplicant(WebCheckoutPageApplicant):
290    """ View which sends a POST request to the Interswitch
291    WebCheckout payment gateway.
292    """
293
294    action = 'https://newwebpay.interswitchng.com/collections/w/pay'
295    currency = '566'
296    pay_item_id = PAY_ITEM_ID
297    merchant_code = MERCHANT_CODE
298
299class CustomWebCheckoutConfirmTransactionStudent(WebCheckoutConfirmTransactionStudent):
300    """ Request webservice view for the WebCheckout gateway
301    """
302    merchant_code = MERCHANT_CODE
303    gateway_host = 'webpay.interswitchng.com'
304    gateway_url = '/collections/api/v1/gettransaction.json'
305    https = True
306
307class CustomWebCheckoutConfirmTransactionApplicant(WebCheckoutConfirmTransactionApplicant):
308    """ Request webservice view for the WebCheckout gateway
309    """
310    merchant_code = MERCHANT_CODE
311    gateway_host = 'webpay.interswitchng.com'
312    gateway_url = '/collections/api/v1/gettransaction.json'
313    https = True
314
315
Note: See TracBrowser for help on using the repository browser.