source: main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py @ 12707

Last change on this file since 12707 was 12480, checked in by Henrik Bettermann, 10 years ago

Remove obsolete customized pagetemplates.

Disable student payments with Interswitch.

File size: 8.1 KB
Line 
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##
18import httplib
19import hashlib
20import grok
21from zope.interface import Interface
22from zope.component import queryAdapter
23from kofacustom.nigeria.interswitch.browser import (
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentRequestWebservicePageApplicant,
26    InterswitchPageStudent, InterswitchPageApplicant,
27    )
28from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment
29from waeup.aaue.applicants.interfaces import ICustomApplicantOnlinePayment
30from waeup.aaue.interfaces import MessageFactory as _
31
32PRODUCT_ID = '5040'
33SITE_NAME = 'aaue.waeup.org'
34PROVIDER_ACCT = '1010764827'
35PROVIDER_BANK_ID = '117'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'AAU Ekpoma'
38CURRENCY = '566'
39GATEWAY_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'
46POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
47
48HOST = 'webpay.interswitchng.com'
49#HOST = 'stageserv.interswitchng.com'
50HTTPS = True
51
52URL = '/paydirect/services/TransactionQueryWs.asmx'
53#URL = '/test_paydirect/services/TransactionQueryWS.asmx'
54httplib.HTTPSConnection.debuglevel = 0
55
56class CustomInterswitchPageApplicant(InterswitchPageApplicant):
57    """ View which sends a POST request to the Interswitch
58    CollegePAY payment gateway.
59    """
60    grok.context(ICustomApplicantOnlinePayment)
61    action = POST_ACTION
62    site_name = SITE_NAME
63    currency = CURRENCY
64    pay_item_id = '101'
65    product_id = PRODUCT_ID
66    mac = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
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
105class 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 = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
116
117    def update(self):
118
119        self.flash('Payment method not yet configured.', type='danger')
120        self.redirect(self.url(self.context, '@@index'))
121        return
122
123
124        error = self.init_update()
125        if error:
126            self.flash(error, type='danger')
127            self.redirect(self.url(self.context, '@@index'))
128            return
129        student = self.student
130        xmldict = self.xmldict
131        # Provider data
132        xmldict['detail_ref'] = self.context.p_id
133        xmldict['provider_acct'] = PROVIDER_ACCT
134        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
135        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
136        # Institution data
137        xmldict['institution_acct'] = '00000000'
138        xmldict['institution_bank_id'] = '00'
139        xmldict['institution_amt'] = '0.0'
140        provider_amt = 0.0
141        xmldict['provider_amt'] = 100 * provider_amt
142        xmldict['institution_item_name'] = self.category
143        xmldict['institution_name'] = INSTITUTION_NAME
144        xmldict['institution_amt'] = 100 * (
145            self.context.amount_auth - provider_amt - GATEWAY_AMT)
146        # Interswitch amount is not part of the xml data
147        if provider_amt == 0:
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_details>
152</payment_item_detail>""" % xmldict
153        else:
154            xmltext = """<payment_item_detail>
155<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
156<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" />
157<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" />
158</item_details>
159</payment_item_detail>""" % xmldict
160        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
161        self.context.provider_amt = provider_amt
162        self.context.gateway_amt = GATEWAY_AMT
163
164        hashargs = (
165            self.context.p_id +
166            PRODUCT_ID +
167            self.pay_item_id +
168            str(int(self.amount_auth)) +
169            self.site_redirect_url +
170            self.mac)
171        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
172
173        return
174
175
176class CustomInterswitchPaymentRequestWebservicePageApplicant(
177    InterswitchPaymentRequestWebservicePageApplicant):
178    """ Request webservice view for the CollegePAY gateway
179    """
180    grok.context(ICustomApplicantOnlinePayment)
181    product_id = PRODUCT_ID
182    gateway_host = HOST
183    gateway_url = URL
184    https = HTTPS
185
186class CustomInterswitchPaymentRequestWebservicePageStudent(
187    InterswitchPaymentRequestWebservicePageStudent):
188    """ Request webservice view for the CollegePAY gateway
189    """
190    grok.context(ICustomStudentOnlinePayment)
191    product_id = PRODUCT_ID
192    gateway_host = HOST
193    gateway_url = URL
194    https = HTTPS
Note: See TracBrowser for help on using the repository browser.