source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/interswitch/browser.py @ 17347

Last change on this file since 17347 was 17347, checked in by Henrik Bettermann, 19 months ago

Setup NCE school fee payments.

  • Property svn:keywords set to Id
File size: 13.1 KB
Line 
1## $Id: browser.py 17347 2023-03-13 08:51:35Z 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    module_activated,
23    InterswitchPaymentRequestWebservicePageApplicant,
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
29from kofacustom.unidel.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.unidel.interfaces import MessageFactory as _
32
33PRODUCT_ID = '22153701' # must be provided by Interswitch
34SITE_NAME = 'unidel.waeup.org'
35PROVIDER_ACCT = '0213065415'
36PROVIDER_BANK_ID = '47'
37PROVIDER_ITEM_NAME = 'WAeAC'
38INSTITUTION_NAME = 'UNIDEL'
39CURRENCY = '566'
40GATEWAY_AMT = 250.0
41#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
42MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi'
43
44POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay'
45#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
46HOST = 'webpay.interswitchng.com'
47#HOST = 'sandbox.interswitchng.com'
48URL = '/collections/api/v1/gettransaction.json'
49#URL = '/webpay/api/v1/gettransaction.json'
50
51httplib.HTTPSConnection.debuglevel = 0
52HTTPS = True
53
54class CustomInterswitchPageStudent(InterswitchPageStudent):
55    """ View which sends a POST request to the Interswitch
56    CollegePAY payment gateway.
57    """
58    grok.context(ICustomStudentOnlinePayment)
59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
63    mac = MAC
64    gateway_amt = GATEWAY_AMT
65
66    def update(self):
67        if not module_activated(
68            self.context.student.current_session, self.context):
69            self.flash(_('Forbidden'), type='danger')
70            self.redirect(self.url(self.context, '@@index'))
71            return
72        error = self.init_update()
73        if error:
74            self.flash(error, type='danger')
75            self.redirect(self.url(self.context, '@@index'))
76            return
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        # Institution data
85        xmldict['institution_acct'] = '000000000'
86        xmldict['institution_bank_id'] = '117'
87        provider_amt = 0.0
88        tech_fee = 0.0
89        if self.context.p_category == 'clearance':
90            provider_amt = 500.0
91            xmldict['institution_acct'] = '1216063205'
92            if student.faccode in ('PRE', 'JUPEB'):
93                xmldict['institution_acct'] = '1011431799'
94        elif self.context.p_category == 'schoolfee':
95            provider_amt = 2800.0
96            tech_fee = 1200.0
97            xmldict['institution_acct'] = '1011739172'
98            if student.faccode in ('PRE', 'JUPEB'):
99                xmldict['institution_acct'] = '2001627961'
100                xmldict['institution_bank_id'] = '8'
101            if student.faccode == 'NCE':
102                xmldict['institution_acct'] = '1130069220'
103                xmldict['institution_bank_id'] = '117'
104                provider_amt = 4000.0
105                tech_fee = 0.0
106        elif self.context.p_category == 'hostel_maintenance':
107            xmldict['institution_acct'] = '1012551384'
108        elif self.context.p_category == 'med_reg':
109            xmldict['institution_acct'] = '1011265606'
110        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
111        # Already now it becomes an Interswitch payment. We set the net amount
112        # and add gateway amount and other surcharges.
113        if not self.context.r_company:
114            self.context.r_company = u'interswitch'
115            self.context.net_amt = self.context.amount_auth
116            self.context.gateway_amt = self.gateway_amt
117            self.context.amount_auth += self.gateway_amt
118            self.context.provider_amt = provider_amt
119            self.context.amount_auth += provider_amt
120            self.context.amount_auth += tech_fee
121        xmldict['provider_amt'] = 100 * provider_amt
122        xmldict['tech_fee'] = 100 * tech_fee
123        xmldict['institution_item_name'] = self.context.category
124        xmldict['institution_name'] = INSTITUTION_NAME
125        xmldict['institution_amt'] = 100 * self.context.net_amt
126        if provider_amt == 0:
127            xmltext = """<payment_item_detail>
128<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
129<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" />
130</item_details>
131</payment_item_detail>""" % xmldict
132        elif tech_fee == 0:
133            xmltext = """<payment_item_detail>
134<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
135<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" />
136<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" />
137</item_details>
138</payment_item_detail>""" % xmldict
139        else:
140            xmltext = """<payment_item_detail>
141<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
142<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" />
143<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" />
144<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="47" acct_num="0213065415" />
145</item_details>
146</payment_item_detail>""" % xmldict
147        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
148        self.context.provider_amt = provider_amt
149        self.amount_auth = int(100 * self.context.amount_auth)
150        hashargs = (
151            self.context.p_id +
152            PRODUCT_ID +
153            self.pay_item_id +
154            str(int(self.amount_auth)) +
155            self.site_redirect_url +
156            self.mac)
157        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
158        return
159
160class CustomInterswitchPageApplicant(InterswitchPageApplicant):
161    """ View which sends a POST request to the Interswitch
162    CollegePAY payment gateway.
163    """
164    grok.context(ICustomApplicantOnlinePayment)
165    action = POST_ACTION
166    site_name = SITE_NAME
167    currency = CURRENCY
168    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
169    product_id = PRODUCT_ID
170    mac = MAC
171    gateway_amt = GATEWAY_AMT
172
173    def update(self):
174        if not module_activated(
175            self.context.__parent__.__parent__.year, self.context):
176            self.flash(_('Forbidden'), type='danger')
177            self.redirect(self.url(self.context, '@@index'))
178            return
179        error = self.init_update()
180        if error:
181            self.flash(error, type='danger')
182            self.redirect(self.url(self.context, '@@index'))
183            return
184        # Already now it becomes an Interswitch payment. We set the net amount
185        # and add the gateway amount.
186        if not self.context.r_company:
187            self.context.net_amt = self.context.amount_auth
188            self.context.amount_auth += self.gateway_amt
189            self.context.gateway_amt = self.gateway_amt
190            self.context.r_company = u'interswitch'
191        xmldict = {}
192        provider_amt = 250.0
193        xmldict['institution_acct'] = '1216063205'
194        xmldict['institution_bank_id'] = '117'
195        if self.context.__parent__.__parent__.prefix in (
196                                    'pre', 'jupeb', 'dpft', 'dppt',
197                                    'ugpt', 'ijmb'):
198            xmldict['institution_acct'] = '1011431799'
199            xmldict['institution_bank_id'] = '117'
200            provider_amt = 500.0           
201        xmldict['detail_ref'] = self.context.p_id
202        xmldict['provider_amt'] = 100 * provider_amt
203        xmldict['provider_acct'] = PROVIDER_ACCT
204        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
205        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
206        xmldict['institution_item_name'] = self.context.category
207        xmldict['institution_name'] = INSTITUTION_NAME
208        xmldict['institution_amt'] = 100 * self.context.net_amt
209        if not self.context.provider_amt:
210            self.context.provider_amt = provider_amt
211            self.context.amount_auth += provider_amt
212        xmltext = """<payment_item_detail>
213<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
214<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" />
215<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" />
216</item_details>
217</payment_item_detail>""" % xmldict
218        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
219        self.amount_auth = int(100 * self.context.amount_auth)
220        hashargs = (
221            self.context.p_id +
222            PRODUCT_ID +
223            self.pay_item_id +
224            str(int(self.amount_auth)) +
225            self.site_redirect_url +
226            self.mac)
227        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
228        return
229
230class CustomInterswitchPaymentRequestWebservicePageStudent(
231    InterswitchPaymentRequestWebservicePageStudent):
232    """Request webservice view for the CollegePAY gateway
233    """
234    grok.context(ICustomStudentOnlinePayment)
235    product_id = PRODUCT_ID
236    gateway_host = HOST
237    gateway_url = URL
238    mac = MAC
239
240class CustomInterswitchPaymentVerifyWebservicePageStudent(
241    InterswitchPaymentVerifyWebservicePageStudent):
242    """Payment verify view for the CollegePAY gateway
243    """
244    grok.context(ICustomStudentOnlinePayment)
245    product_id = PRODUCT_ID
246    gateway_host = HOST
247    gateway_url = URL
248    mac = MAC
249
250class CustomInterswitchPaymentRequestWebservicePageApplicant(
251    InterswitchPaymentRequestWebservicePageApplicant):
252    """Request webservice view for the CollegePAY gateway
253    """
254    grok.context(ICustomApplicantOnlinePayment)
255    product_id = PRODUCT_ID
256    gateway_host = HOST
257    gateway_url = URL
258    mac = MAC
259
260class CustomInterswitchPaymentVerifyWebservicePageApplicant(
261    InterswitchPaymentVerifyWebservicePageApplicant):
262    """Payment verify view for the CollegePAY gateway
263    """
264    grok.context(ICustomApplicantOnlinePayment)
265    product_id = PRODUCT_ID
266    gateway_host = HOST
267    gateway_url = URL
268    mac = MAC
269
270# PAYDirect
271
272from kofacustom.nigeria.interswitch.paydirectbrowser import (
273    PAYDirectPageStudent, PAYDirectPageApplicant,
274    StudentRefNumberSlip, ApplicantRefNumberSlip,
275    )
276
277from kofacustom.nigeria.interswitch.tests import (
278    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
279
280#PAYDIRECT_HOST = 'orion.interswitchng.com'
281#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
282#MERCHANT_ID = ''
283
284class CustomPAYDirectPageStudent(PAYDirectPageStudent):
285    """Inform student how to proceed
286    """
287    grok.context(ICustomStudentOnlinePayment)
288    gateway_amt = GATEWAY_AMT
289    merchant_id = MERCHANT_ID
290    gateway_url = PAYDIRECT_URL
291    gateway_host = PAYDIRECT_HOST
292    https = True
293
294class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
295    """ Inform applicant how to proceed.
296    """
297    grok.context(ICustomApplicantOnlinePayment)
298    gateway_amt = GATEWAY_AMT
299    merchant_id = MERCHANT_ID
300    gateway_url = PAYDIRECT_URL
301    gateway_host = PAYDIRECT_HOST
302    https = True
303
304class CustomStudentRefNumberSlip(StudentRefNumberSlip):
305    """Deliver a PDF slip of the context.
306    """
307    merchant_id = MERCHANT_ID
308
309class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
310    """Deliver a PDF slip of the context.
311    """
312    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.