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

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

Deduct Student Union Dues from Tution Fee.

Start customizing application category.

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