1 | ## $Id: browser.py 11797 2014-09-19 16:00:43Z 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 queryAdapter |
---|
23 | from kofacustom.nigeria.interswitch.browser import ( |
---|
24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
25 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
26 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
27 | ) |
---|
28 | from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment |
---|
29 | from waeup.aaue.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
30 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
31 | |
---|
32 | PRODUCT_ID = '6207' |
---|
33 | SITE_NAME = 'aaue.waeup.org' |
---|
34 | PROVIDER_ACCT = '1010764827' |
---|
35 | PROVIDER_BANK_ID = '117' |
---|
36 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
37 | INSTITUTION_NAME = 'AAU Ekpoma' |
---|
38 | CURRENCY = '566' |
---|
39 | GATEWAY_AMT = 250.0 |
---|
40 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
41 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
42 | |
---|
43 | #POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
44 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
45 | POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay' |
---|
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 | |
---|
55 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
56 | """ View which sends a POST request to the Interswitch |
---|
57 | CollegePAY payment gateway. |
---|
58 | """ |
---|
59 | grok.context(ICustomApplicantOnlinePayment) |
---|
60 | grok.template('applicant_goto_interswitch') |
---|
61 | action = POST_ACTION |
---|
62 | site_name = SITE_NAME |
---|
63 | currency = CURRENCY |
---|
64 | pay_item_id = '101' |
---|
65 | product_id = PRODUCT_ID |
---|
66 | mac = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' |
---|
67 | |
---|
68 | def update(self): |
---|
69 | |
---|
70 | super(CustomInterswitchPageApplicant, self).update() |
---|
71 | xmldict = {} |
---|
72 | provider_amt = 1000.0 |
---|
73 | xmldict['institution_acct'] = '1010835352' |
---|
74 | xmldict['institution_bank_id'] = '117' |
---|
75 | xmldict['detail_ref'] = self.context.p_id |
---|
76 | xmldict['provider_amt'] = 100 * provider_amt |
---|
77 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
78 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
79 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
80 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
81 | xmldict['institution_item_name'] = self.context.p_category |
---|
82 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
83 | # Interswitch amount is not part of the xml data |
---|
84 | xmltext = """<payment_item_detail> |
---|
85 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
86 | <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" /> |
---|
87 | <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" /> |
---|
88 | </item_details> |
---|
89 | </payment_item_detail>""" % xmldict |
---|
90 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
91 | self.context.provider_amt = provider_amt |
---|
92 | self.context.gateway_amt = GATEWAY_AMT |
---|
93 | |
---|
94 | hashargs = ( |
---|
95 | self.context.p_id + |
---|
96 | PRODUCT_ID + |
---|
97 | self.pay_item_id + |
---|
98 | str(int(self.amount_auth)) + |
---|
99 | self.site_redirect_url + |
---|
100 | self.mac) |
---|
101 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
102 | |
---|
103 | return |
---|
104 | |
---|
105 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
106 | """ View which sends a POST request to the Interswitch |
---|
107 | CollegePAY payment gateway. |
---|
108 | """ |
---|
109 | grok.context(ICustomStudentOnlinePayment) |
---|
110 | action = POST_ACTION |
---|
111 | site_name = SITE_NAME |
---|
112 | currency = CURRENCY |
---|
113 | product_id = PRODUCT_ID |
---|
114 | pay_item_id = '101' |
---|
115 | mac = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' |
---|
116 | |
---|
117 | def update(self): |
---|
118 | error = self.init_update() |
---|
119 | if error: |
---|
120 | self.flash(error, type='danger') |
---|
121 | self.redirect(self.url(self.context, '@@index')) |
---|
122 | return |
---|
123 | student = self.student |
---|
124 | xmldict = self.xmldict |
---|
125 | # Provider data |
---|
126 | xmldict['detail_ref'] = self.context.p_id |
---|
127 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
128 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
129 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
130 | # Institution data |
---|
131 | xmldict['institution_acct'] = '00000000' |
---|
132 | xmldict['institution_bank_id'] = '00' |
---|
133 | xmldict['institution_amt'] = '0.0' |
---|
134 | provider_amt = 0.0 |
---|
135 | xmldict['provider_amt'] = 100 * provider_amt |
---|
136 | xmldict['institution_item_name'] = self.category |
---|
137 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
138 | xmldict['institution_amt'] = 100 * ( |
---|
139 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
140 | # Interswitch amount is not part of the xml data |
---|
141 | if provider_amt == 0: |
---|
142 | xmltext = """<payment_item_detail> |
---|
143 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
144 | <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" /> |
---|
145 | </item_details> |
---|
146 | </payment_item_detail>""" % xmldict |
---|
147 | else: |
---|
148 | xmltext = """<payment_item_detail> |
---|
149 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
150 | <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" /> |
---|
151 | <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" /> |
---|
152 | </item_details> |
---|
153 | </payment_item_detail>""" % xmldict |
---|
154 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
155 | self.context.provider_amt = provider_amt |
---|
156 | self.context.gateway_amt = GATEWAY_AMT |
---|
157 | |
---|
158 | hashargs = ( |
---|
159 | self.context.p_id + |
---|
160 | PRODUCT_ID + |
---|
161 | self.pay_item_id + |
---|
162 | str(int(self.amount_auth)) + |
---|
163 | self.site_redirect_url + |
---|
164 | self.mac) |
---|
165 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
166 | |
---|
167 | return |
---|
168 | |
---|
169 | |
---|
170 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
171 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
172 | """ Request webservice view for the CollegePAY gateway |
---|
173 | """ |
---|
174 | grok.context(ICustomApplicantOnlinePayment) |
---|
175 | product_id = PRODUCT_ID |
---|
176 | gateway_host = HOST |
---|
177 | gateway_url = URL |
---|
178 | |
---|
179 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
180 | InterswitchPaymentRequestWebservicePageStudent): |
---|
181 | """ Request webservice view for the CollegePAY gateway |
---|
182 | """ |
---|
183 | grok.context(ICustomStudentOnlinePayment) |
---|
184 | product_id = PRODUCT_ID |
---|
185 | gateway_host = HOST |
---|
186 | gateway_url = URL |
---|