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

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

Add payment categories.

  • Property svn:keywords set to Id
File size: 10.6 KB
Line 
1## $Id: browser.py 16820 2022-02-21 11:58:38Z 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.edopoly.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.edopoly.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.edopoly.interfaces import MessageFactory as _
31
32PRODUCT_ID = '7571' # must be provided by Interswitch
33SITE_NAME = 'edopoly-kofa.waeup.org'
34PROVIDER_ACCT = '0773411069'
35PROVIDER_BANK_ID = '31'
36PROVIDER_ITEM_NAME = 'WAeAC'
37INSTITUTION_NAME = 'EdoPoly'
38CURRENCY = '566'
39GATEWAY_AMT = 250.0
40MAC = '672ABFB2F3755A7793DE545BDA00F44878DF59140B43A1E7DF16245D299F3108AFF65502F16D95256B3242B43CBC3F512A208EB1BA977080D65328800C49912C'
41
42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
43#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
44HOST = 'webpay.interswitchng.com'
45#HOST = 'sandbox.interswitchng.com'
46URL = '/paydirect/api/v1/gettransaction.json'
47#URL = '/webpay/api/v1/gettransaction.json'
48
49httplib.HTTPSConnection.debuglevel = 0
50HTTPS = True
51
52SPECIAL_PAYMENT_PARAMS = {
53
54    'conv_nd': ('101', 1000.0, '0031913976', '121'),
55    'conv_hnd': ('101', 1000.0, '0031913976', '121'),
56    }
57
58
59class CustomInterswitchPageStudent(InterswitchPageStudent):
60    """ View which sends a POST request to the Interswitch
61    CollegePAY payment gateway.
62    """
63    grok.context(ICustomStudentOnlinePayment)
64    action = POST_ACTION
65    site_name = SITE_NAME
66    currency = CURRENCY
67    product_id = PRODUCT_ID
68    mac = MAC
69
70    def update(self):
71        error = self.init_update()
72        if error:
73            self.flash(error, type='danger')
74            self.redirect(self.url(self.context, '@@index'))
75            return
76        self.context.r_company = u'interswitch'
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        provider_amt = 0.0
85        if not self.context.p_item == 'Balance':
86            if self.context.p_category == 'ict_entre':
87                provider_amt = 3000.0
88            if self.context.p_category == 'clearance':
89                provider_amt = 1500.0
90            # temporarily disabled
91            #if self.context.p_category in ('transcript', 'certificate'):
92            #    provider_amt = 2000.0
93        # Institution data
94        xmldict['institution_acct'] = '0068241848'
95        xmldict['institution_bank_id'] = '121'
96        if self.context.p_category == 'union':
97            xmldict['institution_acct'] = '0066437412'
98        if self.context.p_category == 'nhis':
99            xmldict['institution_acct'] = '0075379404'
100        if self.context.p_category == 'cyber':
101            xmldict['institution_acct'] = '1220055070'
102            xmldict['institution_bank_id'] = '117'
103        if self.context.p_category == 'ispon':
104            xmldict['institution_acct'] = '1220055104'
105            xmldict['institution_bank_id'] = '117'
106        xmldict['institution_amt'] = '0.0'
107        self.pay_item_id = '101' # must be provided by Interswitch
108        xmldict['provider_amt'] = 100 * provider_amt
109        xmldict['institution_item_name'] = self.context.category
110        xmldict['institution_name'] = INSTITUTION_NAME
111        xmldict['institution_amt'] = 100 * (
112            self.context.amount_auth - provider_amt - GATEWAY_AMT)
113        # Interswitch amount is not part of the xml data
114        if provider_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_details>
119</payment_item_detail>""" % xmldict
120        else:
121            xmltext = """<payment_item_detail>
122<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
123<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" />
124<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" />
125</item_details>
126</payment_item_detail>""" % xmldict
127        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
128        self.context.provider_amt = provider_amt
129        self.context.gateway_amt = GATEWAY_AMT
130        self.amount_auth = int(100 * self.context.amount_auth)
131        hashargs = (
132            self.context.p_id +
133            PRODUCT_ID +
134            self.pay_item_id +
135            str(int(self.amount_auth)) +
136            self.site_redirect_url +
137            self.mac)
138        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
139        return
140
141class CustomInterswitchPageApplicant(InterswitchPageApplicant):
142    """ View which sends a POST request to the Interswitch
143    CollegePAY payment gateway.
144    """
145    grok.context(ICustomApplicantOnlinePayment)
146    action = POST_ACTION
147    site_name = SITE_NAME
148    currency = CURRENCY
149    pay_item_id = '101' # must be provided by Interswitch
150    product_id = PRODUCT_ID
151    mac = MAC
152
153    def update(self):
154        error = self.init_update()
155        if error:
156            self.flash(error, type='danger')
157            self.redirect(self.url(self.context, '@@index'))
158            return
159        self.context.r_company = u'interswitch'
160        xmldict = {}
161        provider_amt = 1000.0
162        if self.context.p_category != 'application':
163            provider_amt = 0.0
164        xmldict['institution_acct'] = '0068241848'
165        xmldict['institution_bank_id'] = '121'
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 * (
172            self.context.amount_auth - provider_amt - GATEWAY_AMT)
173        xmldict['institution_item_name'] = self.context.category
174        xmldict['institution_name'] = INSTITUTION_NAME
175        if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
176            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
177            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[
178                self.context.p_category][2]
179            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[
180                self.context.p_category][3]
181            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
182            xmldict['institution_amt'] = 100 * (
183                self.context.amount_auth - provider_amt - GATEWAY_AMT)
184            xmldict['provider_amt'] = 100 * provider_amt
185        # Interswitch amount is not part of the xml data
186        if provider_amt == 0:
187            xmltext = """<payment_item_detail>
188<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
189<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" />
190</item_details>
191</payment_item_detail>""" % xmldict
192        else:
193            xmltext = """<payment_item_detail>
194<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
195<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" />
196<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" />
197</item_details>
198</payment_item_detail>""" % xmldict
199
200        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
201        self.context.provider_amt = provider_amt
202        self.context.gateway_amt = GATEWAY_AMT
203        self.amount_auth = int(100 * self.context.amount_auth)
204        hashargs = (
205            self.context.p_id +
206            PRODUCT_ID +
207            self.pay_item_id +
208            str(int(self.amount_auth)) +
209            self.site_redirect_url +
210            self.mac)
211        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
212        return
213
214class CustomInterswitchPaymentRequestWebservicePageStudent(
215    InterswitchPaymentRequestWebservicePageStudent):
216    """Request webservice view for the CollegePAY gateway
217    """
218    grok.context(ICustomStudentOnlinePayment)
219    product_id = PRODUCT_ID
220    gateway_host = HOST
221    gateway_url = URL
222    mac = MAC
223
224class CustomInterswitchPaymentVerifyWebservicePageStudent(
225    InterswitchPaymentVerifyWebservicePageStudent):
226    """Payment verify view for the CollegePAY gateway
227    """
228    grok.context(ICustomStudentOnlinePayment)
229    product_id = PRODUCT_ID
230    gateway_host = HOST
231    gateway_url = URL
232    mac = MAC
233
234class CustomInterswitchPaymentRequestWebservicePageApplicant(
235    InterswitchPaymentRequestWebservicePageApplicant):
236    """Request webservice view for the CollegePAY gateway
237    """
238    grok.context(ICustomApplicantOnlinePayment)
239    product_id = PRODUCT_ID
240    gateway_host = HOST
241    gateway_url = URL
242    mac = MAC
243
244class CustomInterswitchPaymentVerifyWebservicePageApplicant(
245    InterswitchPaymentVerifyWebservicePageApplicant):
246    """Payment verify view for the CollegePAY gateway
247    """
248    grok.context(ICustomApplicantOnlinePayment)
249    product_id = PRODUCT_ID
250    gateway_host = HOST
251    gateway_url = URL
252    mac = MAC
Note: See TracBrowser for help on using the repository browser.