source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser.py @ 11574

Last change on this file since 11574 was 11557, checked in by Henrik Bettermann, 10 years ago

Change bank account numbers for special payments.

  • Property svn:keywords set to Id
File size: 18.0 KB
Line 
1## $Id: browser.py 11557 2014-04-01 12:48:51Z 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 zope.interface import Interface
22from zope.component import getUtility, queryAdapter
23from kofacustom.nigeria.interswitch.browser import (
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentRequestWebservicePageApplicant
26    )
27from waeup.kofa.browser.layout import KofaPage, UtilityView
28from waeup.kofa.interfaces import IKofaUtils
29from waeup.kofa.utils.helpers import to_timezone
30from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment
31from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment
32from waeup.kwarapoly.interfaces import MessageFactory as _
33
34PRODUCT_ID = '3930'
35SITE_NAME = 'kwarapoly.waeup.org'
36PROVIDER_ACCT = '1010764827'
37PROVIDER_BANK_ID = '117'
38PROVIDER_ITEM_NAME = 'BT Education'
39INSTITUTION_NAME = 'KwaraPoly'
40CURRENCY = '566'
41GATEWAY_AMT = 300.0
42#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
43#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
44
45POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
46#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
47
48HOST = 'webpay.interswitchng.com'
49#HOST = 'testwebpay.interswitchng.com'
50
51URL = '/paydirect/services/TransactionQueryWs.asmx'
52#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
53httplib.HTTPConnection.debuglevel = 0
54
55class InterswitchPageStudent(KofaPage):
56    """ View which sends a POST request to the Interswitch
57    CollegePAY payment gateway.
58    """
59    grok.context(ICustomStudentOnlinePayment)
60    grok.name('goto_interswitch')
61    grok.template('student_goto_interswitch')
62    grok.require('waeup.payStudent')
63    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
64    submit_button = _('Submit')
65    action = POST_ACTION
66    site_name = SITE_NAME
67    currency = CURRENCY
68    product_id = PRODUCT_ID
69    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
70
71    def interswitch_img_url(self):
72        return interswitch_img_url(self)
73
74    def update(self):
75        #if self.context.p_state != 'unpaid':
76        if self.context.p_state == 'paid':
77            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
78            self.redirect(self.url(self.context, '@@index'))
79            return
80
81        student = self.student = self.context.student
82        certificate = getattr(student['studycourse'],'certificate',None)
83        self.amount_auth = 100 * self.context.amount_auth
84        xmldict = {}
85        if certificate is not None:
86            xmldict['department'] = certificate.__parent__.__parent__.code
87            xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code
88        else:
89            xmldict['department'] = None
90            xmldict['faculty'] = None
91        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
92        tz = getUtility(IKofaUtils).tzinfo
93        self.local_date_time = to_timezone(
94            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
95        self.site_redirect_url = self.url(self.context, 'request_webservice')
96        # Provider data
97        xmldict['detail_ref'] = self.context.p_id
98        xmldict['provider_acct'] = PROVIDER_ACCT
99        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
100        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
101        # Institution data
102        xmldict['institution_item_name'] = self.category
103        xmldict['institution_name'] = INSTITUTION_NAME
104        xmldict['institution_amt'] = 0.0
105        dalash_amt = 200.0
106        provider_amt = 300.0
107        gateway_amt = GATEWAY_AMT
108        self.pay_item_id = '000'
109        xmldict['institution_acct'] = "7000016724"
110        xmldict['institution_bank_id'] = "9"
111        if self.context.p_category == 'schoolfee':
112            self.pay_item_id = '101'
113            dalash_amt = 1800.0
114            provider_amt = 1200.0
115            if xmldict['faculty'] in ('CPGS',):
116                xmldict['institution_acct'] = "1771180233"
117                xmldict['institution_bank_id'] = '120'
118            elif xmldict['faculty'] in ('IBAS',):
119                xmldict['institution_acct'] = "2013910271"
120                xmldict['institution_bank_id'] = '8'
121                self.pay_item_id = '107'
122            elif xmldict['faculty'] in ('IETS',):
123                xmldict['institution_acct'] = "2013910271"
124                xmldict['institution_bank_id'] = '8'
125                self.pay_item_id = '109'
126            elif xmldict['faculty'] in ('IFMS',):
127                xmldict['institution_acct'] = "0106259811"
128                xmldict['institution_bank_id'] = '10'
129                self.pay_item_id = '106'
130            elif xmldict['faculty'] in ('ITCH',):
131                xmldict['institution_acct'] = "1771180233"
132                xmldict['institution_bank_id'] = '120'
133                self.pay_item_id = '110'
134            elif xmldict['faculty'] in ('IICT',):
135                xmldict['institution_acct'] = "2013910271"
136                xmldict['institution_bank_id'] = '8'
137                self.pay_item_id = '108'
138        elif self.context.p_category == 'certificate':
139            self.pay_item_id = '111'
140        elif self.context.p_category == 'state_result':
141            self.pay_item_id = '112'
142        elif self.context.p_category == 'transcript_local':
143            self.pay_item_id = '113'
144        elif self.context.p_category == 'transcript_foreign':
145            self.pay_item_id = '114'
146        elif self.context.p_category == 'ver_result':
147            self.pay_item_id = '115'
148        elif self.context.p_category == 'change_course':
149            self.pay_item_id = '116'
150        elif self.context.p_category == 'change_inst':
151            self.pay_item_id = '117'
152        elif self.context.p_category == 'jamb_reject':
153            self.pay_item_id = '118'
154        elif self.context.p_category == 'cert_of_cert':
155            self.pay_item_id = '119'
156        elif self.context.p_category == 'ref_let':
157            self.pay_item_id = '120'
158        elif self.context.p_category == 'proc_cert':
159            self.pay_item_id = '121'
160        elif self.context.p_category == 'loss_idcard':
161            self.pay_item_id = '122'
162            dalash_amt = 6.0
163            xmldict['dalash_amt'] = 100 * dalash_amt
164            provider_amt = 9.0
165            gateway_amt = 15.0
166        elif self.context.p_category == 'loss_examcard':
167            self.pay_item_id = '123'
168            dalash_amt = 3.0
169            xmldict['dalash_amt'] = 100 * dalash_amt
170            provider_amt = 4.5
171            gateway_amt = 7.5
172        elif self.context.p_category == 'loss_result':
173            self.pay_item_id = '124'
174        elif self.context.p_category == 'loss_receipt':
175            self.pay_item_id = '125'
176        elif self.context.p_category == 'loss_clearance':
177            self.pay_item_id = '126'
178        elif self.context.p_category == 'conv_brochure':
179            self.pay_item_id = '127'
180        elif 'maintenance' in self.context.p_category:
181            self.pay_item_id = '102'
182            xmldict['institution_acct'] = "0039050937"
183            xmldict['institution_bank_id'] = '31'
184            dalash_amt = 0.0
185            provider_amt = 0.0
186        else:
187            xmldict['institution_acct'] = "0000000000000"
188            xmldict['institution_bank_id'] = '0'
189
190        xmldict['dalash_amt'] = 100 * dalash_amt
191        xmldict['provider_amt'] = 100 * provider_amt
192        xmldict['institution_amt'] = 100 * (
193                self.context.amount_auth - provider_amt -
194                gateway_amt - dalash_amt)
195
196        hashargs = (
197            self.context.p_id +
198            PRODUCT_ID +
199            self.pay_item_id +
200            str(int(self.amount_auth)) +
201            self.site_redirect_url +
202            self.mac)
203        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
204
205        # Interswitch amount is not part of the xml data
206
207        if 'maintenance' in self.context.p_category:
208            xmltext = """<payment_item_detail>
209<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
210<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" />
211</item_details>
212</payment_item_detail>""" % xmldict
213
214        else:
215            xmltext = """<payment_item_detail>
216<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
217<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" />
218<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
219<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" />
220</item_details>
221</payment_item_detail>""" % xmldict
222
223        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
224        self.context.provider_amt = provider_amt
225        self.context.gateway_amt = gateway_amt
226        self.context.thirdparty_amt = dalash_amt
227        return
228
229class InterswitchPageApplicant(KofaPage):
230    """ View which sends a POST request to the Interswitch
231    CollegePAY payment gateway.
232    """
233    grok.context(ICustomApplicantOnlinePayment)
234    grok.require('waeup.payApplicant')
235    grok.template('applicant_goto_interswitch')
236    grok.name('goto_interswitch')
237    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
238    submit_button = _('Submit')
239    action = POST_ACTION
240    site_name = SITE_NAME
241    currency = CURRENCY
242    pay_item_id = '103'
243    product_id = PRODUCT_ID
244    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
245
246    def interswitch_img_url(self):
247        return interswitch_img_url(self)
248
249    def update(self):
250        if self.context.p_state != 'unpaid':
251            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
252            self.redirect(self.url(self.context, '@@index'))
253            return
254        if self.context.__parent__.__parent__.expired \
255            and self.context.__parent__.__parent__.strict_deadline:
256            self.flash(_("Payment ticket can't be send to CollegePAY. "
257                         "Application period has expired."))
258            self.redirect(self.url(self.context, '@@index'))
259            return
260        self.applicant = self.context.__parent__
261        self.amount_auth = 100 * self.context.amount_auth
262        xmldict = {}
263        self.category = getUtility(
264            IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
265        tz = getUtility(IKofaUtils).tzinfo
266        self.local_date_time = to_timezone(
267            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
268        self.site_redirect_url = self.url(self.context, 'request_webservice')
269        provider_amt = 300.0
270        dalash_amt = 200.0
271        if self.applicant.applicant_id.startswith('hnd'):
272            xmldict['institution_acct'] = '7000016724'
273            xmldict['institution_bank_id'] = '9'
274        elif self.applicant.applicant_id.startswith('nd'):
275            xmldict['institution_acct'] = '2014191363'
276            xmldict['institution_bank_id'] = '8'
277        elif self.applicant.applicant_id.startswith('pgft'):
278            xmldict['institution_acct'] = '7000016724'
279            xmldict['institution_bank_id'] = '9'
280        elif self.applicant.applicant_id.startswith('prejambites'):
281            xmldict['institution_acct'] = '0106259811'
282            xmldict['institution_bank_id'] = '10'
283            self.pay_item_id = '104'
284            provider_amt = 0.0
285            dalash_amt = 0.0
286        elif self.applicant.applicant_id.startswith('pre'):
287            xmldict['institution_acct'] = '2013910271'
288            xmldict['institution_bank_id'] = '8'
289            provider_amt = 0.0
290            dalash_amt = 0.0
291        elif self.applicant.applicant_id.startswith('special'):
292            xmldict['institution_acct'] = "7000016724"
293            xmldict['institution_bank_id'] = '9'
294            if self.applicant.special_application == 'certificate':
295                self.pay_item_id = '111'
296            elif self.applicant.special_application == 'state_result':
297                self.pay_item_id = '112'
298            elif self.applicant.special_application == 'transcript_local':
299                self.pay_item_id = '113'
300            elif self.applicant.special_application == 'transcript_foreign':
301                self.pay_item_id = '114'
302            elif self.applicant.special_application == 'ver_result':
303                self.pay_item_id = '115'
304            elif self.applicant.special_application == 'change_course':
305                self.pay_item_id = '116'
306            elif self.applicant.special_application == 'change_inst':
307                self.pay_item_id = '117'
308            elif self.applicant.special_application == 'jamb_reject':
309                self.pay_item_id = '118'
310            elif self.applicant.special_application == 'cert_of_cert':
311                self.pay_item_id = '119'
312            elif self.applicant.special_application == 'ref_let':
313                self.pay_item_id = '120'
314            elif self.applicant.special_application == 'proc_cert':
315                self.pay_item_id = '121'
316            elif self.applicant.special_application == 'loss_idcard':
317                self.pay_item_id = '122'
318                dalash_amt = 6.0
319                xmldict['dalash_amt'] = 100 * dalash_amt
320                provider_amt = 9.0
321                gateway_amt = 15.0
322            elif self.applicant.special_application == 'loss_examcard':
323                self.pay_item_id = '123'
324                dalash_amt = 3.0
325                xmldict['dalash_amt'] = 100 * dalash_amt
326                provider_amt = 4.5
327                gateway_amt = 7.5
328            elif self.applicant.special_application == 'loss_result':
329                self.pay_item_id = '124'
330            elif self.applicant.special_application == 'loss_receipt':
331                self.pay_item_id = '125'
332            elif self.applicant.special_application == 'loss_clearance':
333                self.pay_item_id = '126'
334            elif self.applicant.special_application == 'conv_brochure':
335                self.pay_item_id = '127'
336            else:
337                xmldict['institution_acct'] = '00000000000'
338                xmldict['institution_bank_id'] = '00'
339        else:
340            xmldict['institution_acct'] = '00000000000'
341            xmldict['institution_bank_id'] = '00'
342        xmldict['dalash_amt'] = 100 * dalash_amt
343        xmldict['detail_ref'] = self.context.p_id
344        xmldict['provider_amt'] = 100 * provider_amt
345        xmldict['provider_acct'] = PROVIDER_ACCT
346        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
347        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
348        xmldict['institution_amt'] = 100 * (
349            self.context.amount_auth - provider_amt - GATEWAY_AMT - dalash_amt)
350        xmldict['institution_item_name'] = self.context.p_category
351        xmldict['institution_name'] = INSTITUTION_NAME
352
353        hashargs = (
354            self.context.p_id +
355            PRODUCT_ID +
356            self.pay_item_id +
357            str(int(self.amount_auth)) +
358            self.site_redirect_url +
359            self.mac)
360        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
361
362        # Interswitch amount is not part of the xml data
363
364        if not self.applicant.applicant_id.startswith('pre'):
365            xmltext = """<payment_item_detail>
366<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
367<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" />
368<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
369<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" />
370</item_details>
371</payment_item_detail>""" % xmldict
372
373        else:
374            xmltext = """<payment_item_detail>
375<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
376<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" />
377</item_details>
378</payment_item_detail>""" % xmldict
379
380        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
381        self.context.provider_amt = provider_amt
382        self.context.gateway_amt = GATEWAY_AMT
383        self.context.thirdparty_amt = dalash_amt
384        return
385
386class InterswitchPaymentRequestWebservicePageStudent(
387    InterswitchPaymentRequestWebservicePageStudent):
388    """ Request webservice view for the CollegePAY gateway
389    """
390    grok.context(ICustomStudentOnlinePayment)
391    product_id = PRODUCT_ID
392    gateway_host = HOST
393    gateway_url = URL
394
395class InterswitchPaymentRequestWebservicePageApplicant(
396    InterswitchPaymentRequestWebservicePageApplicant):
397    """ Request webservice view for the CollegePAY gateway
398    """
399    grok.context(ICustomApplicantOnlinePayment)
400    product_id = PRODUCT_ID
401    gateway_host = HOST
402    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.