1 | ## $Id: browser.py 9789 2012-12-07 16:37:15Z 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 hashlib |
---|
20 | import grok |
---|
21 | from zope.interface import Interface |
---|
22 | from zope.component import getUtility, queryAdapter |
---|
23 | from kofacustom.nigeria.interswitch.browser import ( |
---|
24 | InterswitchPaymentRequestWebservicePageStudent |
---|
25 | ) |
---|
26 | from waeup.kofa.browser.layout import KofaPage, UtilityView |
---|
27 | from waeup.kofa.interfaces import IKofaUtils |
---|
28 | from waeup.kofa.utils.helpers import to_timezone |
---|
29 | from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment |
---|
30 | from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
31 | from waeup.kwarapoly.interfaces import MessageFactory as _ |
---|
32 | |
---|
33 | PRODUCT_ID = '3930' |
---|
34 | SITE_NAME = 'kwarapoly-kofa.waeup.org' |
---|
35 | PROVIDER_ACCT = '1010764827' |
---|
36 | PROVIDER_BANK_ID = '117' |
---|
37 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
38 | INSTITUTION_NAME = 'KwaraPoly' |
---|
39 | CURRENCY = '566' |
---|
40 | GATEWAY_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' |
---|
43 | |
---|
44 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
45 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
46 | |
---|
47 | HOST = 'webpay.interswitchng.com' |
---|
48 | #HOST = 'testwebpay.interswitchng.com' |
---|
49 | |
---|
50 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
51 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
52 | httplib.HTTPConnection.debuglevel = 0 |
---|
53 | |
---|
54 | def interswitch_img_url(view): |
---|
55 | static = view.static |
---|
56 | if static is None or static.get( |
---|
57 | 'interswitch_verve_mastercard.gif', None) is None: |
---|
58 | static = queryAdapter( |
---|
59 | view.request, Interface, name='waeup.kwarapoly.interswitch') |
---|
60 | return static['interswitch_verve_mastercard.gif']() |
---|
61 | |
---|
62 | class InterswitchPageStudent(KofaPage): |
---|
63 | """ View which sends a POST request to the Interswitch |
---|
64 | CollegePAY payment gateway. |
---|
65 | """ |
---|
66 | grok.context(ICustomStudentOnlinePayment) |
---|
67 | grok.name('goto_interswitch') |
---|
68 | grok.template('student_goto_interswitch') |
---|
69 | grok.require('waeup.payStudent') |
---|
70 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
71 | submit_button = _('Submit') |
---|
72 | action = POST_ACTION |
---|
73 | site_name = SITE_NAME |
---|
74 | currency = CURRENCY |
---|
75 | product_id = PRODUCT_ID |
---|
76 | mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D' |
---|
77 | |
---|
78 | def interswitch_img_url(self): |
---|
79 | return interswitch_img_url(self) |
---|
80 | |
---|
81 | def update(self): |
---|
82 | #if self.context.p_state != 'unpaid': |
---|
83 | if self.context.p_state == 'paid': |
---|
84 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
85 | self.redirect(self.url(self.context, '@@index')) |
---|
86 | return |
---|
87 | |
---|
88 | student = self.student = self.context.student |
---|
89 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
90 | self.amount_auth = 100 * self.context.amount_auth |
---|
91 | xmldict = {} |
---|
92 | if certificate is not None: |
---|
93 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
94 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
95 | else: |
---|
96 | xmldict['department'] = None |
---|
97 | xmldict['faculty'] = None |
---|
98 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
99 | tz = getUtility(IKofaUtils).tzinfo |
---|
100 | self.local_date_time = to_timezone( |
---|
101 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
102 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
103 | # Provider data |
---|
104 | xmldict['detail_ref'] = self.context.p_id |
---|
105 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
106 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
107 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
108 | # Institution data |
---|
109 | xmldict['institution_acct'] = "0000000000000" |
---|
110 | xmldict['institution_bank_id'] = '0' |
---|
111 | xmldict['institution_item_name'] = self.category |
---|
112 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
113 | self.pay_item_id = '000' |
---|
114 | if self.context.p_category == 'schoolfee': |
---|
115 | provider_amt = 1200.0 |
---|
116 | xmldict['provider_amt'] = 100 * provider_amt |
---|
117 | self.pay_item_id = '101' |
---|
118 | dalash_amt = 1800.0 |
---|
119 | xmldict['dalash_amt'] = 100 * dalash_amt |
---|
120 | xmldict['institution_amt'] = 100 * ( |
---|
121 | self.context.amount_auth - provider_amt - |
---|
122 | GATEWAY_AMT - dalash_amt) |
---|
123 | if xmldict['faculty'] in ('CPGS',): |
---|
124 | xmldict['institution_acct'] = "1771180233" |
---|
125 | xmldict['institution_bank_id'] = '120' |
---|
126 | elif xmldict['faculty'] in ('IBAS',): |
---|
127 | xmldict['institution_acct'] = "0006772436" |
---|
128 | xmldict['institution_bank_id'] = '121' |
---|
129 | elif xmldict['faculty'] in ('IETS',): |
---|
130 | xmldict['institution_acct'] = "0106259811" |
---|
131 | xmldict['institution_bank_id'] = '10' |
---|
132 | elif xmldict['faculty'] in ('IFMS',): |
---|
133 | xmldict['institution_acct'] = "2013910271" |
---|
134 | xmldict['institution_bank_id'] = '8' |
---|
135 | elif xmldict['faculty'] in ('ITCH',): |
---|
136 | #acct. number changed from Zenith to FBN by gbenga Nov. 11, 2012 |
---|
137 | xmldict['institution_acct'] = "2013910271" |
---|
138 | xmldict['institution_bank_id'] = '8' |
---|
139 | |
---|
140 | elif 'maintenance' in self.context.p_category: |
---|
141 | self.pay_item_id = '102' |
---|
142 | xmldict['institution_acct'] = "0039050937" |
---|
143 | xmldict['institution_bank_id'] = '31' |
---|
144 | xmldict['institution_amt'] = 100 * ( |
---|
145 | self.context.amount_auth - GATEWAY_AMT) |
---|
146 | dalash_amt = 0.0 |
---|
147 | provider_amt = 0.0 |
---|
148 | |
---|
149 | hashargs = ( |
---|
150 | self.context.p_id + |
---|
151 | PRODUCT_ID + |
---|
152 | self.pay_item_id + |
---|
153 | str(int(self.amount_auth)) + |
---|
154 | self.site_redirect_url + |
---|
155 | self.mac) |
---|
156 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
157 | |
---|
158 | # Interswitch amount is not part of the xml data |
---|
159 | |
---|
160 | if self.context.p_category == 'schoolfee': |
---|
161 | xmltext = """<payment_item_detail> |
---|
162 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
163 | <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" /> |
---|
164 | <item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" /> |
---|
165 | <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" /> |
---|
166 | </item_details> |
---|
167 | </payment_item_detail>""" % xmldict |
---|
168 | |
---|
169 | elif 'maintenance' in self.context.p_category: |
---|
170 | xmltext = """<payment_item_detail> |
---|
171 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
172 | <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" /> |
---|
173 | </item_details> |
---|
174 | </payment_item_detail>""" % xmldict |
---|
175 | |
---|
176 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
177 | self.context.provider_amt = provider_amt |
---|
178 | self.context.gateway_amt = GATEWAY_AMT |
---|
179 | self.context.thirdparty_amt = dalash_amt |
---|
180 | return |
---|
181 | |
---|
182 | class InterswitchPaymentRequestWebservicePageStudent( |
---|
183 | InterswitchPaymentRequestWebservicePageStudent): |
---|
184 | """ Request webservice view for the CollegePAY gateway |
---|
185 | """ |
---|
186 | grok.context(ICustomStudentOnlinePayment) |
---|
187 | product_id = PRODUCT_ID |
---|
188 | gateway_host = HOST |
---|
189 | gateway_url = URL |
---|