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

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

Prepare student payments. Not yet readily configured. MAC is missing. Bank account numbers contradictory. pay_item_ids are not yet assigned.

  • Property svn:keywords set to Id
File size: 12.8 KB
Line 
1## $Id: browser.py 14862 2017-10-06 09:19:26Z 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 = '1014261520'
35PROVIDER_BANK_ID = '117'
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    'certificate': ('111', 500.0, '1012808851', '117'),
53    'state_result': ('112', 500.0, '1012808851', '117'),
54    'transcript_local': ('113', 500.0, '1012808851', '117'),
55    'transcript_foreign': ('114', 500.0, '1012808851', '117'),
56    'ver_result': ('115', 500.0, '1012808851', '117'),
57    'change_course': ('116', 500.0, '1012808851', '117'),
58    'change_inst': ('117', 500.0, '1012808851', '117'),
59    'jamb_reject': ('118', 500.0, '1012808851', '117'),
60    'cert_of_cert': ('119', 500.0, '1012808851', '117'),
61    'ref_let': ('120', 500.0, '1012808851', '117'),
62    'proc_cert': ('121', 500.0, '1012808851', '117'),
63    'loss_idcard': ('122', 9.0, '1012808851', '117'),
64    'loss_examcard': ('123', 4.5, '1012808851', '117'),
65    'loss_result': ('124', 500.0, '1012808851', '117'),
66    'loss_receipt': ('125', 500.0, '1012808851', '117'),
67    'loss_clearance': ('126', 500.0, '1012808851', '117'),
68    'conv_brochure': ('127', 500.0, '1012808851', '117'),
69    'hnd_certificate': ('128', 500.0, '1012808851', '117'),
70    'hnd_state_result': ('129', 500.0, '1012808851', '117'),
71    'hnd_transcript_local': ('130', 500.0, '1012808851', '117'),
72    'hnd_transcript_foreign': ('131', 500.0, '1012808851', '117'),
73    'staff_loss_idcard': ('132', 9.0, '1012808851', '117'),
74    'hnd_conv_brochure': ('133', 500.0, '1012808851', '117'),
75    'pgd_state_result': ('134', 500.0, '1012808851', '117'),
76    'pgd_conv_brochure': ('135', 500.0, '1012808851', '117'),
77    'pgd_certificate': ('136', 500.0, '1012808851', '117'),
78    'log_book': ('137', 4.5, '1012808851', '117'),
79    'pgd_transcript_foreign': ('138', 500.0, '1012808851', '117'),
80    'pgd_transcript_local': ('139', 500.0, '1012808851', '117'),
81    'jamb_regularization': ('140', 500.0, '1012808851', '117'),
82    'utme_registration': ('142', 9.0, '1012808851', '117'),
83    'utme_cbt': ('143', 9.0, '1012808851', '117'),
84    'nysc_id_card': ('144', 9.0, '1012808851', '117'),
85    'ijmb_result': ('147', 500.0, '1012808851', '117'),
86    }
87
88
89# Not yet readily configured. MAC is missing. Bank account numbers are
90# contradictory. pay_item_ids are not yet assigned.
91
92class CustomInterswitchPageStudent(InterswitchPageStudent):
93    """ View which sends a POST request to the Interswitch
94    CollegePAY payment gateway.
95    """
96    grok.context(ICustomStudentOnlinePayment)
97    action = POST_ACTION
98    site_name = SITE_NAME
99    currency = CURRENCY
100    product_id = PRODUCT_ID
101    mac = ''  # must be provided by Interswitch
102
103    def update(self):
104        error = self.init_update()
105        if error:
106            self.flash(error, type='danger')
107            self.redirect(self.url(self.context, '@@index'))
108            return
109        student = self.student
110        xmldict = self.xmldict
111        # Provider data
112        xmldict['detail_ref'] = self.context.p_id
113        xmldict['provider_acct'] = PROVIDER_ACCT
114        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
115        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
116        # Institution data
117        xmldict['institution_acct'] = '0010761873'
118        xmldict['institution_bank_id'] = '11'
119        xmldict['institution_amt'] = '0.0'
120        provider_amt = 500.0
121
122        if self.context.p_category.startswith('schoolfee'):
123            self.pay_item_id = '102'
124        elif self.context.p_category == 'clearance':
125            self.pay_item_id = '103'
126        elif self.context.p_category == 'bed_allocation':
127            self.pay_item_id = '104'
128        elif self.context.p_category == 'hostel_maintenance':
129            self.pay_item_id = '105'
130        elif self.context.p_category == 'transfer':
131            self.pay_item_id = '106'
132        elif self.context.p_category == 'gown':
133            self.pay_item_id = '107'
134        elif self.context.p_category == 'transcript':
135            self.pay_item_id = '108'
136        elif self.context.p_category == 'late_registration':
137            self.pay_item_id = '109'
138        elif self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
139            self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
140            provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
141            xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
142            xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
143        xmldict['provider_amt'] = 100 * provider_amt
144        xmldict['institution_item_name'] = self.context.category
145        xmldict['institution_name'] = INSTITUTION_NAME
146        xmldict['institution_amt'] = 100 * (
147            self.context.amount_auth - provider_amt - GATEWAY_AMT)
148        # Interswitch amount is not part of the xml data
149        if provider_amt == 0:
150            xmltext = """<payment_item_detail>
151<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
152<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" />
153</item_details>
154</payment_item_detail>""" % xmldict
155        else:
156            xmltext = """<payment_item_detail>
157<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
158<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" />
159<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" />
160</item_details>
161</payment_item_detail>""" % xmldict
162        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
163        self.context.provider_amt = provider_amt
164        self.context.gateway_amt = GATEWAY_AMT
165
166        hashargs = (
167            self.context.p_id +
168            PRODUCT_ID +
169            self.pay_item_id +
170            str(int(self.amount_auth)) +
171            self.site_redirect_url +
172            self.mac)
173        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
174        return
175
176class CustomInterswitchPageApplicant(InterswitchPageApplicant):
177    """ View which sends a POST request to the Interswitch
178    CollegePAY payment gateway.
179    """
180    grok.context(ICustomApplicantOnlinePayment)
181    action = POST_ACTION
182    site_name = SITE_NAME
183    currency = CURRENCY
184    pay_item_id = '101' # must be provided by Interswitch
185    product_id = PRODUCT_ID
186    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
187
188    def update(self):
189        error = self.init_update()
190        if error:
191            self.flash(error, type='danger')
192            self.redirect(self.url(self.context, '@@index'))
193            return
194        xmldict = {}
195        provider_amt = 500.0
196        gateway_amt = GATEWAY_AMT
197        xmldict['institution_acct'] = '00000000'
198        xmldict['institution_bank_id'] = '00'
199        if self.applicant.__parent__.application_category in ('ndft', 'hndft'):
200            xmldict['institution_acct'] = '0010761873'
201            xmldict['institution_bank_id'] = '11'
202        elif self.applicant.__parent__.application_category in (
203            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
204            xmldict['institution_acct'] = '1015220292'
205            xmldict['institution_bank_id'] = '117'
206        elif self.applicant.applicant_id.startswith('special'):
207            if self.context.p_category in SPECIAL_PAYMENT_PARAMS.keys():
208                self.pay_item_id = SPECIAL_PAYMENT_PARAMS[self.context.p_category][0]
209                provider_amt = SPECIAL_PAYMENT_PARAMS[self.context.p_category][1]
210                xmldict['institution_acct'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][2]
211                xmldict['institution_bank_id'] = SPECIAL_PAYMENT_PARAMS[self.context.p_category][3]
212        if self.pay_item_id in ('122', '123', '132', '137', '141',
213                                '142', '143', '144', '146', '147',):
214                gateway_amt = round(0.015 * self.context.amount_auth, 2)
215        xmldict['detail_ref'] = self.context.p_id
216        xmldict['provider_amt'] = 100 * provider_amt
217        xmldict['provider_acct'] = PROVIDER_ACCT
218        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
219        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
220        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - gateway_amt)
221        xmldict['institution_item_name'] = self.context.category
222        xmldict['institution_name'] = INSTITUTION_NAME
223        # Interswitch amount is not part of the xml data
224        xmltext = """<payment_item_detail>
225<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
226<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" />
227<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" />
228</item_details>
229</payment_item_detail>""" % xmldict
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
234        hashargs = (
235            self.context.p_id +
236            PRODUCT_ID +
237            self.pay_item_id +
238            str(int(self.amount_auth)) +
239            self.site_redirect_url +
240            self.mac)
241        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
242        return
243
244class CustomInterswitchPaymentRequestWebservicePageStudent(
245    InterswitchPaymentRequestWebservicePageStudent):
246    """Request webservice view for the CollegePAY gateway
247    """
248    grok.context(ICustomStudentOnlinePayment)
249    product_id = PRODUCT_ID
250    gateway_host = HOST
251    gateway_url = URL
252
253class CustomInterswitchPaymentVerifyWebservicePageStudent(
254    InterswitchPaymentVerifyWebservicePageStudent):
255    """Payment verify view for the CollegePAY gateway
256    """
257    grok.context(ICustomStudentOnlinePayment)
258    product_id = PRODUCT_ID
259    gateway_host = HOST
260    gateway_url = URL
261
262class CustomInterswitchPaymentRequestWebservicePageApplicant(
263    InterswitchPaymentRequestWebservicePageApplicant):
264    """Request webservice view for the CollegePAY gateway
265    """
266    grok.context(ICustomApplicantOnlinePayment)
267    product_id = PRODUCT_ID
268    gateway_host = HOST
269    gateway_url = URL
270    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
271
272class CustomInterswitchPaymentVerifyWebservicePageApplicant(
273    InterswitchPaymentVerifyWebservicePageApplicant):
274    """Payment verify view for the CollegePAY gateway
275    """
276    grok.context(ICustomApplicantOnlinePayment)
277    product_id = PRODUCT_ID
278    gateway_host = HOST
279    gateway_url = URL
280    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
Note: See TracBrowser for help on using the repository browser.