1 | ## $Id: browser.py 11647 2014-05-14 05:22:23Z 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 grok |
---|
20 | from kofacustom.nigeria.interswitch.browser import ( |
---|
21 | InterswitchPaymentRequestWebservicePageApplicant, |
---|
22 | InterswitchPaymentRequestWebservicePageStudent, |
---|
23 | InterswitchPageStudent, InterswitchPageApplicant, |
---|
24 | ) |
---|
25 | from kofacustom.skeleton.students.interfaces import ICustomStudentOnlinePayment |
---|
26 | from kofacustom.skeleton.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
27 | from kofacustom.skeleton.interfaces import MessageFactory as _ |
---|
28 | |
---|
29 | PRODUCT_ID = '57' |
---|
30 | SITE_NAME = 'skeleton-kofa.waeup.org' |
---|
31 | PROVIDER_ACCT = '00000000' |
---|
32 | PROVIDER_BANK_ID = '00' |
---|
33 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
34 | INSTITUTION_NAME = 'Skeleton' |
---|
35 | CURRENCY = '566' |
---|
36 | GATEWAY_AMT = 150.0 |
---|
37 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
38 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
39 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
40 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
41 | |
---|
42 | HOST = 'webpay.interswitchng.com' |
---|
43 | #HOST = 'testwebpay.interswitchng.com' |
---|
44 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
45 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
46 | httplib.HTTPConnection.debuglevel = 0 |
---|
47 | |
---|
48 | class CustomInterswitchPageStudent(InterswitchPageStudent): |
---|
49 | """ View which sends a POST request to the Interswitch |
---|
50 | CollegePAY payment gateway. |
---|
51 | """ |
---|
52 | grok.context(ICustomStudentOnlinePayment) |
---|
53 | action = POST_ACTION |
---|
54 | site_name = SITE_NAME |
---|
55 | currency = CURRENCY |
---|
56 | product_id = PRODUCT_ID |
---|
57 | |
---|
58 | def update(self): |
---|
59 | error = self.init_update() |
---|
60 | if error: |
---|
61 | self.flash(error, type='danger') |
---|
62 | self.redirect(self.url(self.context, '@@index')) |
---|
63 | return |
---|
64 | student = self.student |
---|
65 | xmldict = self.xmldict |
---|
66 | # Provider data |
---|
67 | xmldict['detail_ref'] = self.context.p_id |
---|
68 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
69 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
70 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
71 | # Institution data |
---|
72 | xmldict['institution_acct'] = '00000000' |
---|
73 | xmldict['institution_bank_id'] = '00' |
---|
74 | xmldict['institution_amt'] = '0.0' |
---|
75 | provider_amt = 0.0 |
---|
76 | self.pay_item_id = '0000' |
---|
77 | xmldict['provider_amt'] = 100 * provider_amt |
---|
78 | xmldict['institution_item_name'] = self.category |
---|
79 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
80 | xmldict['institution_amt'] = 100 * ( |
---|
81 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
82 | # Interswitch amount is not part of the xml data |
---|
83 | if provider_amt == 0: |
---|
84 | xmltext = """<payment_item_detail> |
---|
85 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)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_details> |
---|
88 | </payment_item_detail>""" % xmldict |
---|
89 | else: |
---|
90 | xmltext = """<payment_item_detail> |
---|
91 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
92 | <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" /> |
---|
93 | <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" /> |
---|
94 | </item_details> |
---|
95 | </payment_item_detail>""" % xmldict |
---|
96 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
97 | self.context.provider_amt = provider_amt |
---|
98 | self.context.gateway_amt = GATEWAY_AMT |
---|
99 | return |
---|
100 | |
---|
101 | class CustomInterswitchPageApplicant(InterswitchPageApplicant): |
---|
102 | """ View which sends a POST request to the Interswitch |
---|
103 | CollegePAY payment gateway. |
---|
104 | """ |
---|
105 | grok.context(ICustomApplicantOnlinePayment) |
---|
106 | action = POST_ACTION |
---|
107 | site_name = SITE_NAME |
---|
108 | currency = CURRENCY |
---|
109 | pay_item_id = '0000' |
---|
110 | product_id = PRODUCT_ID |
---|
111 | |
---|
112 | def update(self): |
---|
113 | super(CustomInterswitchPageApplicant, self).update() |
---|
114 | xmldict = {} |
---|
115 | provider_amt = 400.0 |
---|
116 | xmldict['institution_acct'] = '00000000000' |
---|
117 | xmldict['institution_bank_id'] = '00' |
---|
118 | xmldict['detail_ref'] = self.context.p_id |
---|
119 | xmldict['provider_amt'] = 100 * provider_amt |
---|
120 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
121 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
122 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
123 | xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
124 | xmldict['institution_item_name'] = self.context.p_category |
---|
125 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
126 | # Interswitch amount is not part of the xml data |
---|
127 | xmltext = """<payment_item_detail> |
---|
128 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s"> |
---|
129 | <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" /> |
---|
130 | <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" /> |
---|
131 | </item_details> |
---|
132 | </payment_item_detail>""" % xmldict |
---|
133 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
134 | self.context.provider_amt = provider_amt |
---|
135 | self.context.gateway_amt = GATEWAY_AMT |
---|
136 | return |
---|
137 | |
---|
138 | class CustomInterswitchPaymentRequestWebservicePageStudent( |
---|
139 | InterswitchPaymentRequestWebservicePageStudent): |
---|
140 | """ Request webservice view for the CollegePAY gateway |
---|
141 | """ |
---|
142 | grok.context(ICustomStudentOnlinePayment) |
---|
143 | product_id = PRODUCT_ID |
---|
144 | gateway_host = HOST |
---|
145 | gateway_url = URL |
---|
146 | |
---|
147 | class CustomInterswitchPaymentRequestWebservicePageApplicant( |
---|
148 | InterswitchPaymentRequestWebservicePageApplicant): |
---|
149 | """ Request webservice view for the CollegePAY gateway |
---|
150 | """ |
---|
151 | grok.context(ICustomApplicantOnlinePayment) |
---|
152 | product_id = PRODUCT_ID |
---|
153 | gateway_host = HOST |
---|
154 | gateway_url = URL |
---|