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