1 | ## $Id: browser.py 15785 2019-11-08 12:30:14Z 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 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
23 | InterswitchPaymentRequestWebservicePageStudent, |
---|
24 | InterswitchPaymentVerifyWebservicePageApplicant, |
---|
25 | InterswitchPaymentVerifyWebservicePageStudent, |
---|
26 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
27 | ) |
---|
28 | from kofacustom.iuokada.students.interfaces import ICustomStudentOnlinePayment |
---|
29 | from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
30 | from kofacustom.iuokada.interfaces import MessageFactory as _ |
---|
31 | |
---|
32 | PRODUCT_ID = '7922' |
---|
33 | SITE_NAME = 'iuokada-kofa.waeup.org' |
---|
34 | PROVIDER_ACCT = '0773411069' |
---|
35 | PROVIDER_BANK_ID = '31' |
---|
36 | PROVIDER_ITEM_NAME = 'WAeAC' |
---|
37 | INSTITUTION_NAME = 'IUOkada' |
---|
38 | CURRENCY = '566' |
---|
39 | GATEWAY_AMT = 250.0 |
---|
40 | #MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch |
---|
41 | MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA' |
---|
42 | |
---|
43 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
44 | #POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay' |
---|
45 | HOST = 'webpay.interswitchng.com' |
---|
46 | #HOST = 'sandbox.interswitchng.com' |
---|
47 | URL = '/paydirect/api/v1/gettransaction.json' |
---|
48 | #URL = '/webpay/api/v1/gettransaction.json' |
---|
49 | |
---|
50 | httplib.HTTPSConnection.debuglevel = 0 |
---|
51 | HTTPS = True |
---|
52 | |
---|
53 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
54 | """ View which sends a POST request to the Interswitch |
---|
55 | CollegePAY payment gateway. |
---|
56 | """ |
---|
57 | grok.context(ICustomStudentOnlinePayment) |
---|
58 | action = POST_ACTION |
---|
59 | site_name = SITE_NAME |
---|
60 | currency = CURRENCY |
---|
61 | product_id = PRODUCT_ID |
---|
62 | mac = MAC |
---|
63 | gateway_amt = GATEWAY_AMT |
---|
64 | |
---|
65 | def update(self): |
---|
66 | error = self.init_update() |
---|
67 | if error: |
---|
68 | self.flash(error, type='danger') |
---|
69 | self.redirect(self.url(self.context, '@@index')) |
---|
70 | return |
---|
71 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
72 | # and add the gateway amount. |
---|
73 | if not self.context.r_company: |
---|
74 | self.context.net_amt = self.context.amount_auth |
---|
75 | self.context.amount_auth += self.gateway_amt |
---|
76 | self.context.gateway_amt = self.gateway_amt |
---|
77 | self.context.r_company = u'interswitch' |
---|
78 | student = self.student |
---|
79 | xmldict = self.xmldict |
---|
80 | # Provider data |
---|
81 | xmldict['detail_ref'] = self.context.p_id |
---|
82 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
83 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
84 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
85 | xmldict['institution_acct'] = '' |
---|
86 | xmldict['institution_bank_id'] = '' |
---|
87 | provider_amt = 0.0 |
---|
88 | self.pay_item_id = '' |
---|
89 | # Institution data |
---|
90 | if self.context.p_category in ( |
---|
91 | 'schoolfee', 'schoolfee40', 'secondinstal'): |
---|
92 | xmldict['institution_acct'] = '1011005811' |
---|
93 | xmldict['institution_bank_id'] = '117' |
---|
94 | self.pay_item_id = '101' |
---|
95 | elif self.context.p_category == 'book': |
---|
96 | xmldict['institution_acct'] = '1013249587' |
---|
97 | xmldict['institution_bank_id'] = '117' |
---|
98 | self.pay_item_id = '103' |
---|
99 | elif self.context.p_category == 'parentsconsult': |
---|
100 | xmldict['institution_acct'] = '1012355544' |
---|
101 | xmldict['institution_bank_id'] = '117' |
---|
102 | self.pay_item_id = '104' |
---|
103 | else: |
---|
104 | xmldict['institution_acct'] = '1011050158' |
---|
105 | xmldict['institution_bank_id'] = '117' |
---|
106 | self.pay_item_id = '102' |
---|
107 | if self.context.p_category == 'registration': |
---|
108 | provider_amt = 5000.0 |
---|
109 | xmldict['provider_amt'] = 100 * provider_amt |
---|
110 | xmldict['institution_item_name'] = self.context.category |
---|
111 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
112 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
113 | if not self.context.provider_amt: |
---|
114 | self.context.provider_amt = provider_amt |
---|
115 | self.context.amount_auth += provider_amt |
---|
116 | if provider_amt == 0: |
---|
117 | xmltext = """<payment_item_detail> |
---|
118 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
119 | <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" /> |
---|
120 | </item_details> |
---|
121 | </payment_item_detail>""" % xmldict |
---|
122 | else: |
---|
123 | xmltext = """<payment_item_detail> |
---|
124 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
125 | <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" /> |
---|
126 | <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" /> |
---|
127 | </item_details> |
---|
128 | </payment_item_detail>""" % xmldict |
---|
129 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
130 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
131 | hashargs = ( |
---|
132 | self.context.p_id + |
---|
133 | PRODUCT_ID + |
---|
134 | self.pay_item_id + |
---|
135 | str(int(self.amount_auth)) + |
---|
136 | self.site_redirect_url + |
---|
137 | self.mac) |
---|
138 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
139 | return |
---|
140 | |
---|
141 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
142 | """ View which sends a POST request to the Interswitch |
---|
143 | CollegePAY payment gateway. |
---|
144 | """ |
---|
145 | grok.context(ICustomApplicantOnlinePayment) |
---|
146 | action = POST_ACTION |
---|
147 | site_name = SITE_NAME |
---|
148 | currency = CURRENCY |
---|
149 | product_id = PRODUCT_ID |
---|
150 | mac = MAC |
---|
151 | gateway_amt = GATEWAY_AMT |
---|
152 | |
---|
153 | def update(self): |
---|
154 | error = self.init_update() |
---|
155 | if error: |
---|
156 | self.flash(error, type='danger') |
---|
157 | self.redirect(self.url(self.context, '@@index')) |
---|
158 | return |
---|
159 | # Already now it becomes an Interswitch payment. We set the net amount |
---|
160 | # and add the gateway amount. |
---|
161 | if not self.context.r_company: |
---|
162 | self.context.net_amt = self.context.amount_auth |
---|
163 | self.context.amount_auth += self.gateway_amt |
---|
164 | self.context.gateway_amt = self.gateway_amt |
---|
165 | self.context.r_company = u'interswitch' |
---|
166 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
167 | xmldict = {} |
---|
168 | provider_amt = 0.0 |
---|
169 | pay_item_id = '101' |
---|
170 | xmldict['institution_acct'] = '1011005811' |
---|
171 | xmldict['institution_bank_id'] = '117' |
---|
172 | xmldict['detail_ref'] = self.context.p_id |
---|
173 | xmldict['provider_amt'] = 100 * provider_amt |
---|
174 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
175 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
176 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
177 | xmldict['institution_item_name'] = self.context.category |
---|
178 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
179 | xmldict['institution_amt'] = 100 * self.context.net_amt |
---|
180 | if not self.context.provider_amt: |
---|
181 | self.context.provider_amt = provider_amt |
---|
182 | self.context.amount_auth += provider_amt |
---|
183 | if provider_amt == 0: |
---|
184 | xmltext = """<payment_item_detail> |
---|
185 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
186 | <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" /> |
---|
187 | </item_details> |
---|
188 | </payment_item_detail>""" % xmldict |
---|
189 | else: |
---|
190 | xmltext = """<payment_item_detail> |
---|
191 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
192 | <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" /> |
---|
193 | <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" /> |
---|
194 | </item_details> |
---|
195 | </payment_item_detail>""" % xmldict |
---|
196 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
197 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
198 | hashargs = ( |
---|
199 | self.context.p_id + |
---|
200 | PRODUCT_ID + |
---|
201 | pay_item_id + |
---|
202 | str(int(self.amount_auth)) + |
---|
203 | self.site_redirect_url + |
---|
204 | self.mac) |
---|
205 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
206 | return |
---|
207 | |
---|
208 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
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 |
---|
216 | mac = MAC |
---|
217 | |
---|
218 | class CustomInterswitchPaymentVerifyWebservicePageStudent( |
---|
219 | InterswitchPaymentVerifyWebservicePageStudent): |
---|
220 | """Payment verify view for the CollegePAY gateway |
---|
221 | """ |
---|
222 | grok.context(ICustomStudentOnlinePayment) |
---|
223 | product_id = PRODUCT_ID |
---|
224 | gateway_host = HOST |
---|
225 | gateway_url = URL |
---|
226 | mac = MAC |
---|
227 | |
---|
228 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
229 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
230 | """Request webservice view for the CollegePAY gateway |
---|
231 | """ |
---|
232 | grok.context(ICustomApplicantOnlinePayment) |
---|
233 | product_id = PRODUCT_ID |
---|
234 | gateway_host = HOST |
---|
235 | gateway_url = URL |
---|
236 | mac = MAC |
---|
237 | |
---|
238 | class CustomInterswitchPaymentVerifyWebservicePageApplicant( |
---|
239 | InterswitchPaymentVerifyWebservicePageApplicant): |
---|
240 | """Payment verify view for the CollegePAY gateway |
---|
241 | """ |
---|
242 | grok.context(ICustomApplicantOnlinePayment) |
---|
243 | product_id = PRODUCT_ID |
---|
244 | gateway_host = HOST |
---|
245 | gateway_url = URL |
---|
246 | mac = MAC |
---|