1 | ## $Id: browser.py 16790 2022-02-09 17:31:29Z 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 kofacustom.nigeria.interswitch.browser import ( |
---|
22 | module_activated, |
---|
23 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
25 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
26 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
27 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
28 | ) |
---|
29 | from kofacustom.unidel.students.interfaces import ICustomStudentOnlinePayment |
---|
30 | from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
31 | from kofacustom.unidel.interfaces import MessageFactory as _ |
---|
32 | |
---|
33 | PRODUCT_ID = '22153701' # must be provided by Interswitch |
---|
34 | SITE_NAME = 'unidel.waeup.org' |
---|
35 | PROVIDER_ACCT = '0213065415' |
---|
36 | PROVIDER_BANK_ID = '47' |
---|
37 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
38 | INSTITUTION_NAME = 'UNIDEL' |
---|
39 | CURRENCY = '566' |
---|
40 | GATEWAY_AMT = 250.0 |
---|
41 | #MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' |
---|
42 | MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi' |
---|
43 | |
---|
44 | POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay' |
---|
45 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
46 | HOST = 'webpay.interswitchng.com' |
---|
47 | #HOST = 'sandbox.interswitchng.com' |
---|
48 | URL = '/collections/api/v1/gettransaction.json' |
---|
49 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
50 | |
---|
51 | httplib.HTTPSConnection.debuglevel = 0 |
---|
52 | HTTPS = True |
---|
53 | |
---|
54 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
55 | """ View which sends a POST request to the Interswitch |
---|
56 | CollegePAY payment gateway. |
---|
57 | """ |
---|
58 | grok.context(ICustomStudentOnlinePayment) |
---|
59 | action = POST_ACTION |
---|
60 | site_name = SITE_NAME |
---|
61 | currency = CURRENCY |
---|
62 | product_id = PRODUCT_ID |
---|
63 | mac = MAC |
---|
64 | gateway_amt = GATEWAY_AMT |
---|
65 | |
---|
66 | def update(self): |
---|
67 | if not module_activated( |
---|
68 | self.context.student.current_session, self.context): |
---|
69 | self.flash(_('Forbidden'), type='danger') |
---|
70 | self.redirect(self.url(self.context, '@@index')) |
---|
71 | return |
---|
72 | error = self.init_update() |
---|
73 | if error: |
---|
74 | self.flash(error, type='danger') |
---|
75 | self.redirect(self.url(self.context, '@@index')) |
---|
76 | return |
---|
77 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
78 | # and add the gateway amount. |
---|
79 | if not self.context.r_company: |
---|
80 | self.context.net_amt = self.context.amount_auth |
---|
81 | self.context.amount_auth += self.gateway_amt |
---|
82 | self.context.gateway_amt = self.gateway_amt |
---|
83 | self.context.r_company = u'interswitch' |
---|
84 | student = self.student |
---|
85 | xmldict = self.xmldict |
---|
86 | # Provider data |
---|
87 | xmldict['detail_ref'] = self.context.p_id |
---|
88 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
89 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
90 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
91 | # Institution data |
---|
92 | xmldict['institution_acct'] = '1216063205' |
---|
93 | xmldict['institution_bank_id'] = '117' |
---|
94 | provider_amt = 0.0 |
---|
95 | if self.context.p_category == 'clearance': |
---|
96 | provider_amt = 500.0 |
---|
97 | self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
98 | xmldict['provider_amt'] = 100 * provider_amt |
---|
99 | xmldict['institution_item_name'] = self.context.category |
---|
100 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
101 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
102 | if not self.context.provider_amt: |
---|
103 | self.context.provider_amt = provider_amt |
---|
104 | self.context.amount_auth += provider_amt |
---|
105 | if provider_amt == 0: |
---|
106 | xmltext = """<payment_item_detail> |
---|
107 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
108 | <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" /> |
---|
109 | </item_details> |
---|
110 | </payment_item_detail>""" % xmldict |
---|
111 | else: |
---|
112 | xmltext = """<payment_item_detail> |
---|
113 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
114 | <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" /> |
---|
115 | <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" /> |
---|
116 | </item_details> |
---|
117 | </payment_item_detail>""" % xmldict |
---|
118 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
119 | self.context.provider_amt = provider_amt |
---|
120 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
121 | hashargs = ( |
---|
122 | self.context.p_id + |
---|
123 | PRODUCT_ID + |
---|
124 | self.pay_item_id + |
---|
125 | str(int(self.amount_auth)) + |
---|
126 | self.site_redirect_url + |
---|
127 | self.mac) |
---|
128 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
129 | return |
---|
130 | |
---|
131 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
132 | """ View which sends a POST request to the Interswitch |
---|
133 | CollegePAY payment gateway. |
---|
134 | """ |
---|
135 | grok.context(ICustomApplicantOnlinePayment) |
---|
136 | action = POST_ACTION |
---|
137 | site_name = SITE_NAME |
---|
138 | currency = CURRENCY |
---|
139 | pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch |
---|
140 | product_id = PRODUCT_ID |
---|
141 | mac = MAC |
---|
142 | gateway_amt = GATEWAY_AMT |
---|
143 | |
---|
144 | def update(self): |
---|
145 | if not module_activated( |
---|
146 | self.context.__parent__.__parent__.year, self.context): |
---|
147 | self.flash(_('Forbidden'), type='danger') |
---|
148 | self.redirect(self.url(self.context, '@@index')) |
---|
149 | return |
---|
150 | error = self.init_update() |
---|
151 | if error: |
---|
152 | self.flash(error, type='danger') |
---|
153 | self.redirect(self.url(self.context, '@@index')) |
---|
154 | return |
---|
155 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
156 | # and add the gateway amount. |
---|
157 | if not self.context.r_company: |
---|
158 | self.context.net_amt = self.context.amount_auth |
---|
159 | self.context.amount_auth += self.gateway_amt |
---|
160 | self.context.gateway_amt = self.gateway_amt |
---|
161 | self.context.r_company = u'interswitch' |
---|
162 | xmldict = {} |
---|
163 | provider_amt = 250.0 |
---|
164 | xmldict['institution_acct'] = '1216063205' |
---|
165 | xmldict['institution_bank_id'] = '117' |
---|
166 | xmldict['detail_ref'] = self.context.p_id |
---|
167 | xmldict['provider_amt'] = 100 * provider_amt |
---|
168 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
169 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
170 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
171 | xmldict['institution_item_name'] = self.context.category |
---|
172 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
173 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
174 | if not self.context.provider_amt: |
---|
175 | self.context.provider_amt = provider_amt |
---|
176 | self.context.amount_auth += provider_amt |
---|
177 | xmltext = """<payment_item_detail> |
---|
178 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
179 | <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" /> |
---|
180 | <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" /> |
---|
181 | </item_details> |
---|
182 | </payment_item_detail>""" % xmldict |
---|
183 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
184 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
185 | hashargs = ( |
---|
186 | self.context.p_id + |
---|
187 | PRODUCT_ID + |
---|
188 | self.pay_item_id + |
---|
189 | str(int(self.amount_auth)) + |
---|
190 | self.site_redirect_url + |
---|
191 | self.mac) |
---|
192 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
193 | return |
---|
194 | |
---|
195 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
196 | InterswitchPaymentRequestWebservicePageStudent): |
---|
197 | """Request webservice view for the CollegePAY gateway |
---|
198 | """ |
---|
199 | grok.context(ICustomStudentOnlinePayment) |
---|
200 | product_id = PRODUCT_ID |
---|
201 | gateway_host = HOST |
---|
202 | gateway_url = URL |
---|
203 | mac = MAC |
---|
204 | |
---|
205 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
206 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
207 | """Payment verify view for the CollegePAY gateway |
---|
208 | """ |
---|
209 | grok.context(ICustomStudentOnlinePayment) |
---|
210 | product_id = PRODUCT_ID |
---|
211 | gateway_host = HOST |
---|
212 | gateway_url = URL |
---|
213 | mac = MAC |
---|
214 | |
---|
215 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
216 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
217 | """Request webservice view for the CollegePAY gateway |
---|
218 | """ |
---|
219 | grok.context(ICustomApplicantOnlinePayment) |
---|
220 | product_id = PRODUCT_ID |
---|
221 | gateway_host = HOST |
---|
222 | gateway_url = URL |
---|
223 | mac = MAC |
---|
224 | |
---|
225 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
226 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
227 | """Payment verify view for the CollegePAY gateway |
---|
228 | """ |
---|
229 | grok.context(ICustomApplicantOnlinePayment) |
---|
230 | product_id = PRODUCT_ID |
---|
231 | gateway_host = HOST |
---|
232 | gateway_url = URL |
---|
233 | mac = MAC |
---|
234 | |
---|
235 | # PAYDirect |
---|
236 | |
---|
237 | from kofacustom.nigeria.interswitch.paydirectbrowser import ( |
---|
238 | PAYDirectPageStudent, PAYDirectPageApplicant, |
---|
239 | StudentRefNumberSlip, ApplicantRefNumberSlip, |
---|
240 | ) |
---|
241 | |
---|
242 | from kofacustom.nigeria.interswitch.tests import ( |
---|
243 | PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID) |
---|
244 | |
---|
245 | #PAYDIRECT_HOST = 'orion.interswitchng.com' |
---|
246 | #PAYDIRECT_URL = '/bookonhold/bookonhold.asmx' |
---|
247 | #MERCHANT_ID = '' |
---|
248 | |
---|
249 | class CustomPAYDirectPageStudent(PAYDirectPageStudent): |
---|
250 | """Inform student how to proceed |
---|
251 | """ |
---|
252 | grok.context(ICustomStudentOnlinePayment) |
---|
253 | gateway_amt = GATEWAY_AMT |
---|
254 | merchant_id = MERCHANT_ID |
---|
255 | gateway_url = PAYDIRECT_URL |
---|
256 | gateway_host = PAYDIRECT_HOST |
---|
257 | https = True |
---|
258 | |
---|
259 | class CustomPAYDirectPageApplicant(PAYDirectPageApplicant): |
---|
260 | """ Inform applicant how to proceed. |
---|
261 | """ |
---|
262 | grok.context(ICustomApplicantOnlinePayment) |
---|
263 | gateway_amt = GATEWAY_AMT |
---|
264 | merchant_id = MERCHANT_ID |
---|
265 | gateway_url = PAYDIRECT_URL |
---|
266 | gateway_host = PAYDIRECT_HOST |
---|
267 | https = True |
---|
268 | |
---|
269 | class CustomStudentRefNumberSlip(StudentRefNumberSlip): |
---|
270 | """Deliver a PDF slip of the context. |
---|
271 | """ |
---|
272 | merchant_id = MERCHANT_ID |
---|
273 | |
---|
274 | class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip): |
---|
275 | """Deliver a PDF slip of the context. |
---|
276 | """ |
---|
277 | merchant_id = MERCHANT_ID |
---|