source: main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py @ 14257

Last change on this file since 14257 was 10434, checked in by Henrik Bettermann, 11 years ago

Change pay_item_id.

  • Property svn:keywords set to Id
File size: 14.3 KB
Line 
1## $Id: browser.py 10434 2013-07-22 11:31:14Z 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 grok
20from zope.interface import Interface
21from zope.component import getUtility, queryAdapter
22from kofacustom.nigeria.interswitch.browser import (
23    InterswitchPaymentRequestWebservicePageStudent,
24    InterswitchPaymentRequestWebservicePageApplicant
25    )
26from waeup.kofa.browser.layout import KofaPage
27from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils
28from waeup.kofa.utils.helpers import to_timezone
29from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment
30from waeup.futminna.applicants.interfaces import ICustomApplicantOnlinePayment
31from waeup.futminna.interfaces import MessageFactory as _
32
33PRODUCT_ID = '117'
34SITE_NAME = 'futminna-kofa.waeup.org'
35PROVIDER_ACCT = '1010764827'
36PROVIDER_BANK_ID = '117'
37PROVIDER_ITEM_NAME = 'BT Education'
38INSTITUTION_NAME = 'FUTMinna'
39CURRENCY = '566'
40GATEWAY_AMT = 300.0
41#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
42#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
44#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
45
46HOST = 'webpay.interswitchng.com'
47#HOST = 'testwebpay.interswitchng.com'
48URL = '/paydirect/services/TransactionQueryWs.asmx'
49#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
50httplib.HTTPConnection.debuglevel = 0
51
52def interswitch_img_url(view):
53    static = view.static
54    if static is None or static.get(
55        'interswitch_verve_mastercard.gif', None) is None:
56        static = queryAdapter(
57            view.request, Interface, name='waeup.futminna.interswitch')
58    return static['interswitch_verve_mastercard.gif']()
59
60class InterswitchPageStudent(KofaPage):
61    """ View which sends a POST request to the Interswitch
62    CollegePAY payment gateway.
63    """
64    grok.context(ICustomStudentOnlinePayment)
65    grok.name('goto_interswitch')
66    grok.template('student_goto_interswitch')
67    grok.require('waeup.payStudent')
68    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
69    submit_button = _('Submit')
70    action = POST_ACTION
71    site_name = SITE_NAME
72    currency = CURRENCY
73    pay_item_id = ''
74    product_id = PRODUCT_ID
75
76    def update(self):
77        #if self.context.p_state != 'unpaid':
78        if self.context.p_state == 'paid':
79            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
80            self.redirect(self.url(self.context, '@@index'))
81            return
82
83        student = self.student = self.context.student
84        certificate = getattr(student['studycourse'],'certificate',None)
85        self.amount_auth = 100 * self.context.amount_auth
86        xmldict = {}
87        if certificate is not None:
88            xmldict['department'] = certificate.__parent__.__parent__.code
89            xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code
90        else:
91            xmldict['department'] = None
92            xmldict['faculty'] = None
93        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[
94            self.context.p_category]
95        tz = getUtility(IKofaUtils).tzinfo
96        self.local_date_time = to_timezone(
97            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
98        self.site_redirect_url = self.url(self.context, 'request_webservice')
99        # Provider data
100        xmldict['detail_ref'] = self.context.p_id
101        xmldict['provider_acct'] = PROVIDER_ACCT
102        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
103        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
104        provider_amt = 1500.0
105        xmldict['provider_amt'] = 100 * provider_amt
106
107        # Institution data. Account numbers were changed to the new
108        # NUBAN 10 digit number system
109        xmldict['institution_acct'] = ''
110        xmldict['institution_bank_id'] = ''
111        xmldict['institution_acct'] = '000000000000'
112        xmldict['institution_bank_id'] = '00'
113        xmldict['institution_name'] = INSTITUTION_NAME
114       
115        if self.context.p_category == 'schoolfee':
116            xmldict['institution_amt'] = 100 * (
117                self.context.amount_auth - provider_amt - GATEWAY_AMT)
118            if self.context.student.current_mode in ('pg_ft','pgd_ft'):
119                self.pay_item_id = "11703"
120            elif self.context.student.state == CLEARED and \
121                self.context.student.current_level == 100:
122                self.pay_item_id = "11700"
123            elif self.context.student.state == CLEARED and \
124                self.context.student.current_level == 200:
125                self.pay_item_id = "11701"
126            elif self.context.student.state == CLEARED and \
127                self.context.student.current_level == 300:
128                self.pay_item_id = "11702"
129            elif self.context.student.state == RETURNING and \
130                self.context.student.current_level in (100,110):
131                self.pay_item_id = "11701"
132            elif self.context.student.state == RETURNING and \
133                self.context.student.current_level in (200,210):
134                self.pay_item_id = "11702"
135            elif self.context.student.state == RETURNING and \
136                self.context.student.current_level in (300,310):
137                self.pay_item_id = "11703"
138            elif self.context.student.state == RETURNING and \
139                self.context.student.current_level in (400,410,500,510,600):
140                self.pay_item_id = "11704"
141
142            if self.context.student.current_mode == 'jm_ft':
143                xmldict['institution_acct'] = "000000000000"
144                xmldict['institution_bank_id'] = '00'
145            elif self.context.student.current_mode == 'pg_ft':
146                xmldict['institution_acct'] = "2005910931"
147                xmldict['institution_bank_id'] = '8'
148            elif self.context.student.state == CLEARED and \
149                self.context.student.current_level == 100:
150                xmldict['institution_acct'] = "0021030851"
151                xmldict['institution_bank_id'] = '31'
152            elif self.context.student.state == CLEARED and \
153                self.context.student.current_level == 200:
154                xmldict['institution_acct'] = "0005646299"
155                xmldict['institution_bank_id'] = '47'
156            elif self.context.student.state == CLEARED and \
157                self.context.student.current_level == 300:
158                xmldict['institution_acct'] = "1010500151"
159                xmldict['institution_bank_id'] = '117'
160            elif self.context.student.state == RETURNING and \
161                self.context.student.current_level in (100,110):
162                xmldict['institution_acct'] = "0005646299"
163                xmldict['institution_bank_id'] = '47'
164            elif self.context.student.current_level in (200,210):
165                xmldict['institution_acct'] = "1010500151"
166                xmldict['institution_bank_id'] = '117'
167            elif self.context.student.current_level in (300,310):
168                xmldict['institution_acct'] = "2005910931"
169                xmldict['institution_bank_id'] = '8'
170            elif self.context.student.current_level in (400,410,500,510,600):
171                xmldict['institution_acct'] = "0027490487"
172                xmldict['institution_bank_id'] = '10'
173
174        elif self.context.p_category == 'clearance':
175            xmldict['institution_amt'] = 100 * (
176                self.context.amount_auth - GATEWAY_AMT)
177            xmldict['institution_acct'] = "1750005063"
178            xmldict['institution_bank_id'] = '120'
179            self.pay_item_id = "11706"
180            provider_amt = 0.0
181
182        elif 'maintenance' in self.context.p_category:
183            xmldict['institution_amt'] = 100 * (
184                self.context.amount_auth - GATEWAY_AMT)
185            xmldict['institution_acct'] = "2018856637"
186            xmldict['institution_bank_id'] = '8'
187            self.pay_item_id = "11705"
188            provider_amt = 0.0
189
190        # Interswitch amount is not part of the xml data
191        if self.context.p_category == 'schoolfee':
192            xmltext = """<payment_item_detail>
193<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
194<item_detail item_id="1" item_name="School Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
195<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" />
196</item_details>
197</payment_item_detail>""" % xmldict
198
199        elif self.context.p_category == 'clearance':
200            xmltext = """<payment_item_detail>
201<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
202<item_detail item_id="1" item_name="Acceptance Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
203</item_details>
204</payment_item_detail>""" % xmldict
205
206        elif 'maintenance' in self.context.p_category:
207            xmltext = """<payment_item_detail>
208<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
209<item_detail item_id="1" item_name="Hostel Maintenance Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
210</item_details>
211</payment_item_detail>""" % xmldict
212
213
214        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
215        self.context.provider_amt = provider_amt
216        self.context.gateway_amt = GATEWAY_AMT
217        return
218
219class InterswitchPageApplicant(KofaPage):
220    """ View which sends a POST request to the Interswitch
221    CollegePAY payment gateway.
222    """
223    grok.context(ICustomApplicantOnlinePayment)
224    grok.require('waeup.payApplicant')
225    grok.template('applicant_goto_interswitch')
226    grok.name('goto_interswitch')
227    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
228    submit_button = _('Submit')
229    action = POST_ACTION
230    site_name = SITE_NAME
231    currency = CURRENCY
232    pay_item_id = '11707'
233    product_id = PRODUCT_ID
234    #mac = ''
235
236    def interswitch_img_url(self):
237        return interswitch_img_url(self)
238
239    def update(self):
240        if self.context.p_state != 'unpaid':
241            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
242            self.redirect(self.url(self.context, '@@index'))
243            return
244        if self.context.__parent__.__parent__.expired \
245            and self.context.__parent__.__parent__.strict_deadline:
246            self.flash(_("Payment ticket can't be send to CollegePAY. "
247                         "Application period has expired."))
248            self.redirect(self.url(self.context, '@@index'))
249            return
250        self.applicant = self.context.__parent__
251        self.amount_auth = 100 * self.context.amount_auth
252        xmldict = {}
253        self.category = getUtility(
254            IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
255        tz = getUtility(IKofaUtils).tzinfo
256        self.local_date_time = to_timezone(
257            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
258        self.site_redirect_url = self.url(self.context, 'request_webservice')
259        provider_amt = 500.0
260        if self.applicant.applicant_id.startswith('pg'):
261            xmldict['institution_acct'] = '2005910931'
262            xmldict['institution_bank_id'] = '8'
263        else:
264            xmldict['institution_acct'] = '00000000000'
265            xmldict['institution_bank_id'] = '00'
266        xmldict['detail_ref'] = self.context.p_id
267        xmldict['provider_amt'] = 100 * provider_amt
268        xmldict['provider_acct'] = PROVIDER_ACCT
269        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
270        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
271        xmldict['institution_amt'] = 100 * (
272            self.context.amount_auth - provider_amt - GATEWAY_AMT)
273        xmldict['institution_item_name'] = self.context.p_category
274        xmldict['institution_name'] = INSTITUTION_NAME
275
276        #hashargs = (
277        #    self.context.p_id +
278        #    PRODUCT_ID +
279        #    self.pay_item_id +
280        #    str(int(self.amount_auth)) +
281        #    self.site_redirect_url +
282        #    self.mac)
283        #self.hashvalue = hashlib.sha512(hashargs).hexdigest()
284
285        # Interswitch amount is not part of the xml data
286        xmltext = """<payment_item_detail>
287<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
288<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" />
289<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" />
290</item_details>
291</payment_item_detail>""" % xmldict
292        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
293        self.context.provider_amt = provider_amt
294        self.context.gateway_amt = GATEWAY_AMT
295        return
296
297class InterswitchPaymentRequestWebservicePageStudent(
298    InterswitchPaymentRequestWebservicePageStudent):
299    """ Request webservice view for the CollegePAY gateway
300    """
301    grok.context(ICustomStudentOnlinePayment)
302    product_id = PRODUCT_ID
303    gateway_host = HOST
304    gateway_url = URL
305
306class InterswitchPaymentRequestWebservicePageApplicant(
307    InterswitchPaymentRequestWebservicePageApplicant):
308    """ Request webservice view for the CollegePAY gateway
309    """
310    grok.context(ICustomApplicantOnlinePayment)
311    product_id = PRODUCT_ID
312    gateway_host = HOST
313    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.