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