1 | ## $Id: browser.py 12478 2015-01-15 22:12:25Z 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 waeup.kofa.interfaces import CLEARED |
---|
22 | from kofacustom.nigeria.interswitch.browser import ( |
---|
23 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
24 | InterswitchPaymentRequestWebservicePageStudent, |
---|
25 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
26 | ) |
---|
27 | from kofacustom.wdu.students.interfaces import ICustomStudentOnlinePayment |
---|
28 | from kofacustom.wdu.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
29 | from kofacustom.wdu.interfaces import MessageFactory as _ |
---|
30 | |
---|
31 | PRODUCT_ID = '6207' |
---|
32 | SITE_NAME = 'wdu.waeup.org' |
---|
33 | PROVIDER_ACCT = '0137712635' |
---|
34 | PROVIDER_BANK_ID = '10' |
---|
35 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
36 | INSTITUTION_NAME = 'WDU' |
---|
37 | CURRENCY = '566' |
---|
38 | GATEWAY_AMT = 300.0 |
---|
39 | |
---|
40 | POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay' |
---|
41 | #POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay' |
---|
42 | |
---|
43 | #HOST = 'webpay.interswitchng.com' |
---|
44 | HOST = 'stageserv.interswitchng.com' |
---|
45 | HTTPS = True |
---|
46 | |
---|
47 | #URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
48 | URL = '/test_paydirect/services/TransactionQueryWS.asmx' |
---|
49 | |
---|
50 | httplib.HTTPSConnection.debuglevel = 0 |
---|
51 | |
---|
52 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
53 | """ View which sends a POST request to the Interswitch |
---|
54 | CollegePAY payment gateway. |
---|
55 | """ |
---|
56 | grok.context(ICustomStudentOnlinePayment) |
---|
57 | action = POST_ACTION |
---|
58 | site_name = SITE_NAME |
---|
59 | currency = CURRENCY |
---|
60 | product_id = PRODUCT_ID |
---|
61 | mac = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' |
---|
62 | |
---|
63 | def update(self): |
---|
64 | error = self.init_update() |
---|
65 | if error: |
---|
66 | self.flash(error, type='danger') |
---|
67 | self.redirect(self.url(self.context, '@@index')) |
---|
68 | return |
---|
69 | student = self.student |
---|
70 | xmldict = self.xmldict |
---|
71 | # Provider data |
---|
72 | xmldict['detail_ref'] = self.context.p_id |
---|
73 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
74 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
75 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
76 | xmldict['institution_acct_1'] = '4742014159' |
---|
77 | xmldict['institution_bank_id_1'] = '47' |
---|
78 | xmldict['institution_amt_1'] = '0.0' |
---|
79 | xmldict['institution_acct_2'] = '0029688237' |
---|
80 | xmldict['institution_bank_id_2'] = '11' |
---|
81 | xmldict['institution_amt_2'] = '0.0' |
---|
82 | provider_amt = 4000.0 |
---|
83 | self.pay_item_id = '101' |
---|
84 | # other charges + tech fee |
---|
85 | if self.context.student.state == CLEARED: |
---|
86 | institution_amt_2 = 207500.0 + 1000.0 |
---|
87 | else : |
---|
88 | institution_amt_2 = 150500.0 + 1000.0 |
---|
89 | xmldict['provider_amt'] = 100 * provider_amt |
---|
90 | xmldict['institution_item_name'] = self.category |
---|
91 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
92 | xmldict['institution_amt_1'] = 100 * ( |
---|
93 | self.context.amount_auth - provider_amt - GATEWAY_AMT - institution_amt_2) |
---|
94 | xmldict['institution_amt_2'] = 100 * institution_amt_2 |
---|
95 | |
---|
96 | # Interswitch amount is not part of the xml data |
---|
97 | xmltext = """<payment_item_detail> |
---|
98 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
99 | <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id_1)s" acct_num="%(institution_acct_1)s" /> |
---|
100 | <item_detail item_id="2" item_name="other charges and tech fee" item_amt="%(institution_amt_2)d" bank_id="%(institution_bank_id_2)s" acct_num="%(institution_acct_2)s" /> |
---|
101 | <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" /> |
---|
102 | </item_details> |
---|
103 | </payment_item_detail>""" % xmldict |
---|
104 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
105 | self.context.provider_amt = provider_amt |
---|
106 | self.context.gateway_amt = GATEWAY_AMT |
---|
107 | |
---|
108 | hashargs = ( |
---|
109 | self.context.p_id + |
---|
110 | PRODUCT_ID + |
---|
111 | self.pay_item_id + |
---|
112 | str(int(self.amount_auth)) + |
---|
113 | self.site_redirect_url + |
---|
114 | self.mac) |
---|
115 | self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
116 | return |
---|
117 | |
---|
118 | |
---|
119 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
120 | InterswitchPaymentRequestWebservicePageStudent): |
---|
121 | """ Request webservice view for the CollegePAY gateway |
---|
122 | """ |
---|
123 | grok.context(ICustomStudentOnlinePayment) |
---|
124 | product_id = PRODUCT_ID |
---|
125 | gateway_host = HOST |
---|
126 | gateway_url = URL |
---|
127 | https = HTTPS |
---|
128 | |
---|
129 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
130 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
131 | """ Request webservice view for the CollegePAY gateway |
---|
132 | """ |
---|
133 | grok.context(ICustomApplicantOnlinePayment) |
---|
134 | product_id = PRODUCT_ID |
---|
135 | gateway_host = HOST |
---|
136 | gateway_url = URL |
---|
137 | https = HTTPS |
---|