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

Last change on this file since 9769 was 9750, checked in by Henrik Bettermann, 12 years ago

Import helper functions from kofacustom.nigeria.

  • Property svn:keywords set to Id
File size: 11.2 KB
Line 
1## $Id: browser.py 9750 2012-12-01 06:48:05Z 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.component import getUtility
21from kofacustom.nigeria.interswitch.helpers import query_interswitch
22from waeup.kofa.browser.layout import KofaPage, UtilityView
23from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils
24from waeup.kofa.utils.helpers import to_timezone
25from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent
26from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment
27from waeup.futminna.interfaces import MessageFactory as _
28
29PRODUCT_ID = '117'
30SITE_NAME = 'futminna-kofa.waeup.org'
31PROVIDER_ACCT = '0026781725'
32PROVIDER_BANK_ID = '31'
33PROVIDER_ITEM_NAME = 'BT Education'
34INSTITUTION_NAME = 'FUTMinna'
35CURRENCY = '566'
36#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
37#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
38POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
39#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
40
41HOST = 'webpay.interswitchng.com'
42#HOST = 'testwebpay.interswitchng.com'
43URL = '/paydirect/services/TransactionQueryWs.asmx'
44#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
45httplib.HTTPConnection.debuglevel = 0
46
47class InterswitchActionButtonStudent(APABStudent):
48    grok.order(1)
49    grok.context(ICustomStudentOnlinePayment)
50    grok.require('waeup.payStudent')
51    icon = 'actionicon_pay.png'
52    text = _('CollegePAY')
53    target = 'goto_interswitch'
54
55    @property
56    def target_url(self):
57        if self.context.p_state != 'unpaid':
58            return ''
59        return self.view.url(self.view.context, self.target)
60
61class InterswitchRequestWebserviceActionButtonStudent(APABStudent):
62    grok.order(2)
63    grok.context(ICustomStudentOnlinePayment)
64    grok.require('waeup.payStudent')
65    icon = 'actionicon_call.png'
66    text = _('Requery CollegePAY')
67    target = 'request_webservice'
68
69class InterswitchPageStudent(KofaPage):
70    """ View which sends a POST request to the Interswitch
71    CollegePAY payment gateway.
72    """
73    grok.context(ICustomStudentOnlinePayment)
74    grok.name('goto_interswitch')
75    grok.template('student_goto_interswitch')
76    grok.require('waeup.payStudent')
77    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
78    submit_button = _('Submit')
79    action = POST_ACTION
80    site_name = SITE_NAME
81    currency = CURRENCY
82    pay_item_id = ''
83    product_id = PRODUCT_ID
84
85    def update(self):
86        #if self.context.p_state != 'unpaid':
87        if self.context.p_state == 'paid':
88            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
89            self.redirect(self.url(self.context, '@@index'))
90            return
91
92        student = self.student = self.context.student
93        certificate = getattr(student['studycourse'],'certificate',None)
94        self.amount_auth = 100 * self.context.amount_auth
95        xmldict = {}
96        if certificate is not None:
97            xmldict['department'] = certificate.__parent__.__parent__.code
98            xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code
99        else:
100            xmldict['department'] = None
101            xmldict['faculty'] = None
102        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[
103            self.context.p_category]
104        tz = getUtility(IKofaUtils).tzinfo
105        self.local_date_time = to_timezone(
106            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
107        self.site_redirect_url = self.url(self.context, 'request_webservice')
108        # Provider data
109        xmldict['detail_ref'] = self.context.p_id
110        xmldict['provider_acct'] = PROVIDER_ACCT
111        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
112        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
113        provider_amt = 1500
114        xmldict['provider_amt'] = 100 * provider_amt
115
116        # Institution data. Account numbers were changed to the new
117        # NUBAN 10 digit number system
118        xmldict['institution_acct'] = ''
119        xmldict['institution_bank_id'] = ''
120        xmldict['institution_acct'] = '000000000000'
121        xmldict['institution_bank_id'] = '00'
122        xmldict['institution_name'] = INSTITUTION_NAME
123       
124        if self.context.p_category == 'schoolfee':
125            xmldict['institution_amt'] = 100 * (
126                self.context.amount_auth - provider_amt - 300)
127            if self.context.student.current_mode in ('pg_ft'):
128                self.pay_item_id = "11703"
129            elif self.context.student.state == CLEARED and \
130                self.context.student.current_level == 100:
131                self.pay_item_id = "11700"
132            elif self.context.student.state == CLEARED and \
133                self.context.student.current_level == 200:
134                self.pay_item_id = "11701"
135            elif self.context.student.state == CLEARED and \
136                self.context.student.current_level == 300:
137                self.pay_item_id = "11702"
138            elif self.context.student.state == RETURNING and \
139                self.context.student.current_level in (100,110):
140                self.pay_item_id = "11701"
141            elif self.context.student.state == RETURNING and \
142                self.context.student.current_level in (200,210):
143                self.pay_item_id = "11702"
144            elif self.context.student.state == RETURNING and \
145                self.context.student.current_level in (300,310):
146                self.pay_item_id = "11703"
147            elif self.context.student.state == RETURNING and \
148                self.context.student.current_level in (400,410,500,510,600):
149                self.pay_item_id = "11704"
150
151            if self.context.student.current_mode == 'jm_ft':
152                xmldict['institution_acct'] = "000000000000"
153                xmldict['institution_bank_id'] = '00'
154            elif self.context.student.current_mode == 'pg_ft':
155                xmldict['institution_acct'] = "2005910931"
156                xmldict['institution_bank_id'] = '8'
157            elif self.context.student.state == CLEARED and \
158                self.context.student.current_level == 100:
159                xmldict['institution_acct'] = "0021030851"
160                xmldict['institution_bank_id'] = '31'
161            elif self.context.student.state == CLEARED and \
162                self.context.student.current_level == 200:
163                xmldict['institution_acct'] = "0005646299"
164                xmldict['institution_bank_id'] = '47'
165            elif self.context.student.state == CLEARED and \
166                self.context.student.current_level == 300:
167                xmldict['institution_acct'] = "1010500151"
168                xmldict['institution_bank_id'] = '117'
169            elif self.context.student.state == RETURNING and \
170                self.context.student.current_level in (100,110):
171                xmldict['institution_acct'] = "0005646299"
172                xmldict['institution_bank_id'] = '47'
173            elif self.context.student.current_level in (200,210):
174                xmldict['institution_acct'] = "1010500151"
175                xmldict['institution_bank_id'] = '117'
176            elif self.context.student.current_level in (300,310):
177                xmldict['institution_acct'] = "2005910931"
178                xmldict['institution_bank_id'] = '8'
179            elif self.context.student.current_level in (400,410,500,510,600):
180                xmldict['institution_acct'] = "0027490487"
181                xmldict['institution_bank_id'] = '10'
182
183        elif self.context.p_category == 'clearance':
184            xmldict['institution_amt'] = 100 * (
185                self.context.amount_auth - 300)
186            xmldict['institution_acct'] = "1750005063"
187            xmldict['institution_bank_id'] = '120'
188            self.pay_item_id = "11706"
189
190        elif 'maintenance' in self.context.p_category:
191            xmldict['institution_amt'] = 100 * (
192                self.context.amount_auth - 300)
193            xmldict['institution_acct'] = "2018856637"
194            xmldict['institution_bank_id'] = '8'
195            self.pay_item_id = "11705"
196
197        # Interswitch amount is not part of the xml data
198        if self.context.p_category == 'schoolfee':
199            xmltext = """<payment_item_detail>
200<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
201<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" />
202<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" />
203</item_details>
204</payment_item_detail>""" % xmldict
205
206        elif self.context.p_category == 'clearance':
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="Acceptance 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        elif 'maintenance' in self.context.p_category:
214            xmltext = """<payment_item_detail>
215<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
216<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" />
217</item_details>
218</payment_item_detail>""" % xmldict
219
220
221        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
222        return
223
224class InterswitchPaymentRequestWebservicePageStudent(UtilityView, grok.View):
225    """ Request webservice view for the CollegePAY gateway
226    """
227    grok.context(ICustomStudentOnlinePayment)
228    grok.name('request_webservice')
229    grok.require('waeup.payStudent')
230
231    def update(self):
232        if self.context.p_state == 'paid':
233            self.flash(_('This ticket has already been paid.'))
234            return
235        student = self.context.student
236        success, msg, log = query_interswitch(
237            self.context, PRODUCT_ID, HOST, URL)
238        student.writeLogMessage(self, log)
239        if not success:
240            self.flash(msg)
241            return
242        success, msg, log = self.context.doAfterStudentPayment()
243        if log is not None:
244            student.writeLogMessage(self, log)
245        self.flash(msg)
246        return
247
248    def render(self):
249        self.redirect(self.url(self.context, '@@index'))
250        return
Note: See TracBrowser for help on using the repository browser.