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

Last change on this file since 15284 was 15259, checked in by Henrik Bettermann, 6 years ago

Fix xmldict.

  • Property svn:keywords set to Id
File size: 9.9 KB
Line 
1## $Id: browser.py 15259 2018-12-03 11:58:27Z 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        student = self.student
77        xmldict = self.xmldict
78        # Provider data
79        xmldict['detail_ref'] = self.context.p_id
80        xmldict['provider_acct'] = PROVIDER_ACCT
81        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
82        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
83        provider_amt = 0.0
84        if not self.context.p_item == 'Balance':
85            if self.context.p_category == 'ict_entre':
86                provider_amt = 3000.0
87            if self.context.p_category == 'clearance':
88                provider_amt = 1500.0
89            # temporarily disabled
90            #if self.context.p_category in ('transcript', 'certificate'):
91            #    provider_amt = 2000.0
92        # Institution data
93        xmldict['institution_acct'] = '0068241848'
94        xmldict['institution_bank_id'] = '121'
95        if self.context.p_category == 'union':
96            xmldict['institution_acct'] = '0066437412'
97        xmldict['institution_amt'] = '0.0'
98        self.pay_item_id = '101' # must be provided by Interswitch
99        xmldict['provider_amt'] = 100 * provider_amt
100        xmldict['institution_item_name'] = self.context.category
101        xmldict['institution_name'] = INSTITUTION_NAME
102        xmldict['institution_amt'] = 100 * (
103            self.context.amount_auth - provider_amt - GATEWAY_AMT)
104        # Interswitch amount is not part of the xml data
105        if provider_amt == 0:
106            xmltext = """<payment_item_detail>
107<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
108<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" />
109</item_details>
110</payment_item_detail>""" % xmldict
111        else:
112            xmltext = """<payment_item_detail>
113<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
114<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" />
115<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" />
116</item_details>
117</payment_item_detail>""" % xmldict
118        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
119        self.context.provider_amt = provider_amt
120        self.context.gateway_amt = GATEWAY_AMT
121
122        hashargs = (
123            self.context.p_id +
124            PRODUCT_ID +
125            self.pay_item_id +
126            str(int(self.amount_auth)) +
127            self.site_redirect_url +
128            self.mac)
129        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
130        return
131
132class CustomInterswitchPageApplicant(InterswitchPageApplicant):
133    """ View which sends a POST request to the Interswitch
134    CollegePAY payment gateway.
135    """
136    grok.context(ICustomApplicantOnlinePayment)
137    action = POST_ACTION
138    site_name = SITE_NAME
139    currency = CURRENCY
140    pay_item_id = '101' # must be provided by Interswitch
141    product_id = PRODUCT_ID
142    mac = MAC
143
144    def update(self):
145        error = self.init_update()
146        if error:
147            self.flash(error, type='danger')
148            self.redirect(self.url(self.context, '@@index'))
149            return
150        xmldict = {}
151        provider_amt = 1000.0
152        if self.context.p_category != 'application':
153            provider_amt = 0.0
154        xmldict['institution_acct'] = '0068241848'
155        xmldict['institution_bank_id'] = '121'
156        xmldict['detail_ref'] = self.context.p_id
157        xmldict['provider_amt'] = 100 * provider_amt
158        xmldict['provider_acct'] = PROVIDER_ACCT
159        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
160        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
161        xmldict['institution_amt'] = 100 * (
162            self.context.amount_auth - provider_amt - GATEWAY_AMT)
163        xmldict['institution_item_name'] = self.context.category
164        xmldict['institution_name'] = INSTITUTION_NAME
165        if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
166            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
167            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[
168                self.context.p_category][2]
169            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[
170                self.context.p_category][3]
171            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
172            xmldict['institution_amt'] = 100 * (
173                self.context.amount_auth - provider_amt - GATEWAY_AMT)
174            xmldict['provider_amt'] = 100 * provider_amt
175        # Interswitch amount is not part of the xml data
176        if provider_amt == 0:
177            xmltext = """<payment_item_detail>
178<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
179<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" />
180</item_details>
181</payment_item_detail>""" % xmldict
182        else:
183            xmltext = """<payment_item_detail>
184<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
185<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" />
186<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" />
187</item_details>
188</payment_item_detail>""" % xmldict
189
190        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
191        self.context.provider_amt = provider_amt
192        self.context.gateway_amt = GATEWAY_AMT
193
194        hashargs = (
195            self.context.p_id +
196            PRODUCT_ID +
197            self.pay_item_id +
198            str(int(self.amount_auth)) +
199            self.site_redirect_url +
200            self.mac)
201        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
202        return
203
204class CustomInterswitchPaymentRequestWebservicePageStudent(
205    InterswitchPaymentRequestWebservicePageStudent):
206    """Request webservice view for the CollegePAY gateway
207    """
208    grok.context(ICustomStudentOnlinePayment)
209    product_id = PRODUCT_ID
210    gateway_host = HOST
211    gateway_url = URL
212    mac = MAC
213
214class CustomInterswitchPaymentVerifyWebservicePageStudent(
215    InterswitchPaymentVerifyWebservicePageStudent):
216    """Payment verify 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 CustomInterswitchPaymentRequestWebservicePageApplicant(
225    InterswitchPaymentRequestWebservicePageApplicant):
226    """Request webservice view for the CollegePAY gateway
227    """
228    grok.context(ICustomApplicantOnlinePayment)
229    product_id = PRODUCT_ID
230    gateway_host = HOST
231    gateway_url = URL
232    mac = MAC
233
234class CustomInterswitchPaymentVerifyWebservicePageApplicant(
235    InterswitchPaymentVerifyWebservicePageApplicant):
236    """Payment verify 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
Note: See TracBrowser for help on using the repository browser.