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

Last change on this file since 15087 was 15079, checked in by Henrik Bettermann, 7 years ago

Temporarily disable WAeAC charge for transcript payments.

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