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

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

Increase Interswitch amount.

File size: 7.9 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 = '6207'
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 = 300.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'
45POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
46
47#HOST = 'webpay.interswitchng.com'
48HOST = 'stageserv.interswitchng.com'
49HTTPS = True
50
51#URL = '/paydirect/services/TransactionQueryWs.asmx'
52URL = '/test_paydirect/services/TransactionQueryWS.asmx'
53httplib.HTTPSConnection.debuglevel = 0
54
55class 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
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 = '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
170class 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    https = HTTPS
179
180class CustomInterswitchPaymentRequestWebservicePageStudent(
181    InterswitchPaymentRequestWebservicePageStudent):
182    """ Request webservice view for the CollegePAY gateway
183    """
184    grok.context(ICustomStudentOnlinePayment)
185    product_id = PRODUCT_ID
186    gateway_host = HOST
187    gateway_url = URL
188    https = HTTPS
Note: See TracBrowser for help on using the repository browser.