source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/browser.py @ 14942

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

Configure Gown Hire Fee.

  • Property svn:keywords set to Id
File size: 18.3 KB
Line 
1## $Id: browser.py 14942 2018-01-22 22:48:02Z 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.dspg.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.dspg.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.dspg.interfaces import MessageFactory as _
31
32PRODUCT_ID = '7269' # must be provided by Interswitch
33SITE_NAME = 'dspg.waeup.org'
34PROVIDER_ACCT = '2028964403'
35PROVIDER_BANK_ID = '8'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'Delta State Polytechnic Ogwashi-Uku'
38CURRENCY = '566'
39GATEWAY_AMT = 250.0
40
41POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
42#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
43HOST = 'webpay.interswitchng.com'
44#HOST = 'sandbox.interswitchng.com'
45URL = '/paydirect/api/v1/gettransaction.json'
46#URL = '/webpay/api/v1/gettransaction.json'
47
48httplib.HTTPSConnection.debuglevel = 0
49HTTPS = True
50
51SPECIAL_PAYMENT_PARAMS = {
52
53    'carryover1': ('101', 500.0, '1012808851', '117'),
54    'carryover5': ('101', 500.0, '1012808851', '117'),
55    'carryover6': ('101', 500.0, '1012808851', '117'),
56    'carryover7': ('101', 500.0, '1012808851', '117'),
57    'carryover8': ('101', 500.0, '1012808851', '117'),
58    'carryover9': ('101', 500.0, '1012808851', '117'),
59    'carryover10': ('101', 500.0, '1012808851', '117'),
60    'carryover11': ('101', 500.0, '1012808851', '117'),
61    'carryover12': ('101', 500.0, '1012808851', '117'),
62    'balance': ('101', 500.0, '1012808851', '117'),
63
64    'certificate': ('111', 500.0, '1012808851', '117'),
65    'state_result': ('112', 500.0, '1012808851', '117'),
66    'transcript_local': ('113', 500.0, '1012808851', '117'),
67    'transcript_foreign': ('114', 500.0, '1012808851', '117'),
68    'ver_result': ('115', 500.0, '1012808851', '117'),
69    'change_course': ('116', 500.0, '1012808851', '117'),
70    'change_inst': ('117', 500.0, '1012808851', '117'),
71    'jamb_reject': ('118', 500.0, '1012808851', '117'),
72    'cert_of_cert': ('119', 500.0, '1012808851', '117'),
73    'ref_let': ('120', 500.0, '1012808851', '117'),
74    'proc_cert': ('121', 500.0, '1012808851', '117'),
75    'loss_idcard': ('122', 9.0, '1012808851', '117'),
76    'loss_examcard': ('123', 4.5, '1012808851', '117'),
77    'loss_result': ('124', 500.0, '1012808851', '117'),
78    'loss_receipt': ('125', 500.0, '1012808851', '117'),
79    'loss_clearance': ('126', 500.0, '1012808851', '117'),
80    'conv_brochure': ('127', 500.0, '1012808851', '117'),
81    'hnd_certificate': ('128', 500.0, '1012808851', '117'),
82    'hnd_state_result': ('129', 500.0, '1012808851', '117'),
83    'hnd_transcript_local': ('130', 500.0, '1012808851', '117'),
84    'hnd_transcript_foreign': ('131', 500.0, '1012808851', '117'),
85    'staff_loss_idcard': ('132', 9.0, '1012808851', '117'),
86    'hnd_conv_brochure': ('133', 500.0, '1012808851', '117'),
87    'pgd_state_result': ('134', 500.0, '1012808851', '117'),
88    'pgd_conv_brochure': ('135', 500.0, '1012808851', '117'),
89    'pgd_certificate': ('136', 500.0, '1012808851', '117'),
90    'log_book': ('137', 4.5, '1012808851', '117'),
91    'pgd_transcript_foreign': ('138', 500.0, '1012808851', '117'),
92    'pgd_transcript_local': ('139', 500.0, '1012808851', '117'),
93    'jamb_regularization': ('140', 500.0, '1012808851', '117'),
94    'utme_registration': ('142', 9.0, '1012808851', '117'),
95    'utme_cbt': ('143', 9.0, '1012808851', '117'),
96    'nysc_id_card': ('144', 9.0, '1012808851', '117'),
97    'ijmb_result': ('147', 500.0, '1012808851', '117'),
98    }
99
100
101# Not yet readily configured. Bank account numbers are
102# contradictory. pay_item_ids are not yet assigned.
103
104class CustomInterswitchPageStudent(InterswitchPageStudent):
105    """ View which sends a POST request to the Interswitch
106    CollegePAY payment gateway.
107    """
108    grok.context(ICustomStudentOnlinePayment)
109    action = POST_ACTION
110    site_name = SITE_NAME
111    currency = CURRENCY
112    product_id = PRODUCT_ID
113    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
114    pay_item_id = '000'
115
116    def update(self):
117        error = self.init_update()
118        if error:
119            self.flash(error, type='danger')
120            self.redirect(self.url(self.context, '@@index'))
121            return
122        student = self.student
123        xmldict = self.xmldict
124        # Provider data
125        xmldict['detail_ref'] = self.context.p_id
126        xmldict['provider_acct'] = PROVIDER_ACCT
127        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
128        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
129        # Institution data
130        xmldict['institution_acct'] = '00000000'
131        xmldict['institution_bank_id'] = '00'
132        xmldict['institution_amt'] = '0.0'
133        provider_amt = 0.0
134        if self.context.p_category.startswith('schoolfee'):
135            self.pay_item_id = '102'
136            provider_amt = 2800.0
137            if student.faccode == 'SPAT':
138                xmldict['institution_acct'] = '1012808851'
139                xmldict['institution_bank_id'] = '117'
140            elif student.current_mode in ('nd_ft', 'hnd_ft'):
141                xmldict['institution_acct'] = '0026235493'
142                xmldict['institution_bank_id'] = '31'
143        elif self.context.p_category == 'clearance':
144            self.pay_item_id = '103'
145            provider_amt = 500.0
146            if student.faccode == 'SPAT':
147                xmldict['institution_acct'] = '1012808851'
148                xmldict['institution_bank_id'] = '117'
149            elif student.current_mode == 'nd_ft':
150                xmldict['institution_acct'] = '2004402644'
151                xmldict['institution_bank_id'] = '8'
152        elif self.context.p_category == 'gown':
153            self.pay_item_id = '102' # We use school fee item id.
154            xmldict['institution_acct'] = '2006612782'
155            xmldict['institution_bank_id'] = '8'
156        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
157            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
158            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
159            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
160            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
161        xmldict['provider_amt'] = 100 * provider_amt
162        xmldict['institution_item_name'] = self.context.category
163        xmldict['institution_name'] = INSTITUTION_NAME
164        xmldict['institution_amt'] = institution_amt = 100 * (
165            self.context.amount_auth - provider_amt - GATEWAY_AMT)
166        if provider_amt == 0:
167            xmltext = """<payment_item_detail>
168<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
169<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" />
170</item_details>
171</payment_item_detail>""" % xmldict
172        else:
173            xmltext = """<payment_item_detail>
174<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
175<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" />
176<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" />
177</item_details>
178</payment_item_detail>""" % xmldict
179
180        # isouaba: All certificates in SPAT are part time thus any payments
181        # coming from those certificates (Application, Acceptance, school fees
182        # etc) 40% should be split to keystone account.
183        if student.faccode == 'SPAT':
184            xmldict['institution_amt_2'] = 0.4 * institution_amt
185            xmldict['institution_amt_1'] = 0.6 * institution_amt
186            if provider_amt == 0:
187                xmltext = """<payment_item_detail>
188<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
189<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
190<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
191</item_details>
192</payment_item_detail>""" % xmldict
193            else:
194                xmltext = """<payment_item_detail>
195<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
196<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
197<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
198<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
199</item_details>
200</payment_item_detail>""" % xmldict
201
202        # dep_sug payments are treated completely separately. The following lines
203        # override the configuration above.
204        if self.context.p_category == 'dep_sug':
205            self.pay_item_id = '102' # We use school fee item id
206            # amount_auth is being ignored. However, the sum of all split payments
207            # must coincide with the amount_auth configured in students/utils.py
208            xmldict['amt1'] = 100 * 1000
209            xmldict['amt2'] = 100 * 500
210            xmldict['amt3'] = 100 * 900
211            xmldict['amt4'] = 100 * 500
212
213            xmltext = """<payment_item_detail>
214<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
215<item_detail item_id="1" item_name="SUG" item_amt="%(amt1)d" bank_id="11" acct_num="0038079930" />
216<item_detail item_id="2" item_name="Students Welfare" item_amt="%(amt2)d" bank_id="11" acct_num="0037892949" />
217<item_detail item_id="3" item_name="Anti-Cult Book" item_amt="%(amt3)d" bank_id="11" acct_num="0037892949" />
218<item_detail item_id="4" item_name="NADESSTU" item_amt="%(amt4)d" bank_id="11" acct_num="0036375968" />
219</item_details>
220</payment_item_detail>""" % xmldict
221
222#            if student.faccode == 'SPAT':
223#                xmltext = """<payment_item_detail>
224#<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
225#<item_detail item_id="1" item_name="Students Welfare" item_amt="%(amt2)d" bank_id="11" acct_num="0037892949" />
226#<item_detail item_id="2" item_name="Anti-Cult Book" item_amt="%(amt3)d" bank_id="11" acct_num="0037892949" />
227#</item_details>
228#</payment_item_detail>""" % xmldict
229
230        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
231        self.context.provider_amt = provider_amt
232        self.context.gateway_amt = GATEWAY_AMT
233        hashargs = (
234            self.context.p_id +
235            PRODUCT_ID +
236            self.pay_item_id +
237            str(int(self.amount_auth)) +
238            self.site_redirect_url +
239            self.mac)
240        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
241        return
242
243class CustomInterswitchPageApplicant(InterswitchPageApplicant):
244    """ View which sends a POST request to the Interswitch
245    CollegePAY payment gateway.
246    """
247    grok.context(ICustomApplicantOnlinePayment)
248    action = POST_ACTION
249    site_name = SITE_NAME
250    currency = CURRENCY
251    pay_item_id = '101' # must be provided by Interswitch
252    product_id = PRODUCT_ID
253    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
254
255    def update(self):
256        error = self.init_update()
257        if error:
258            self.flash(error, type='danger')
259            self.redirect(self.url(self.context, '@@index'))
260            return
261        xmldict = {}
262        provider_amt = 500.0
263        gateway_amt = GATEWAY_AMT
264        xmldict['institution_acct'] = '00000000'
265        xmldict['institution_bank_id'] = '00'
266        if self.applicant.__parent__.application_category in ('ndft', 'hndft'):
267            xmldict['institution_acct'] = '0010761873'
268            xmldict['institution_bank_id'] = '11'
269        elif self.applicant.__parent__.application_category in (
270            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
271            xmldict['institution_acct'] = '1015220292'
272            xmldict['institution_bank_id'] = '117'
273        elif self.applicant.applicant_id.startswith('special'):
274            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
275                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
276                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
277                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
278                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
279        if self.pay_item_id in ('122', '123', '132', '137', '141',
280                                '142', '143', '144', '146', '147',):
281                gateway_amt = round(0.015 * self.context.amount_auth, 2)
282        xmldict['detail_ref'] = self.context.p_id
283        xmldict['provider_amt'] = 100 * provider_amt
284        xmldict['provider_acct'] = PROVIDER_ACCT
285        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
286        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
287        xmldict['institution_amt'] = institution_amt = 100 * (
288            self.context.amount_auth - provider_amt - gateway_amt)
289        xmldict['institution_item_name'] = self.context.category
290        xmldict['institution_name'] = INSTITUTION_NAME
291        xmltext = """<payment_item_detail>
292<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
293<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" />
294<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" />
295</item_details>
296</payment_item_detail>""" % xmldict
297
298        # isouaba: All certificates in SPAT are part time thus any payments
299        # coming from those certificates (Application, Acceptance, school fees
300        # etc) 40% should be split to keystone account.
301        if self.applicant.__parent__.application_category in (
302            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
303            xmldict['institution_amt_2'] = 0.4 * institution_amt
304            xmldict['institution_amt_1'] = 0.6 * institution_amt
305            xmltext = """<payment_item_detail>
306<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
307<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
308<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
309<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
310</item_details>
311</payment_item_detail>""" % xmldict
312
313        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
314        self.context.provider_amt = provider_amt
315        self.context.gateway_amt = GATEWAY_AMT
316
317        hashargs = (
318            self.context.p_id +
319            PRODUCT_ID +
320            self.pay_item_id +
321            str(int(self.amount_auth)) +
322            self.site_redirect_url +
323            self.mac)
324        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
325        return
326
327class CustomInterswitchPaymentRequestWebservicePageStudent(
328    InterswitchPaymentRequestWebservicePageStudent):
329    """Request webservice view for the CollegePAY gateway
330    """
331    grok.context(ICustomStudentOnlinePayment)
332    product_id = PRODUCT_ID
333    gateway_host = HOST
334    gateway_url = URL
335    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
336
337class CustomInterswitchPaymentVerifyWebservicePageStudent(
338    InterswitchPaymentVerifyWebservicePageStudent):
339    """Payment verify view for the CollegePAY gateway
340    """
341    grok.context(ICustomStudentOnlinePayment)
342    product_id = PRODUCT_ID
343    gateway_host = HOST
344    gateway_url = URL
345    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
346
347class CustomInterswitchPaymentRequestWebservicePageApplicant(
348    InterswitchPaymentRequestWebservicePageApplicant):
349    """Request webservice view for the CollegePAY gateway
350    """
351    grok.context(ICustomApplicantOnlinePayment)
352    product_id = PRODUCT_ID
353    gateway_host = HOST
354    gateway_url = URL
355    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
356
357class CustomInterswitchPaymentVerifyWebservicePageApplicant(
358    InterswitchPaymentVerifyWebservicePageApplicant):
359    """Payment verify view for the CollegePAY gateway
360    """
361    grok.context(ICustomApplicantOnlinePayment)
362    product_id = PRODUCT_ID
363    gateway_host = HOST
364    gateway_url = URL
365    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
Note: See TracBrowser for help on using the repository browser.