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

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

Set Interswitch amount at 250 Nairas (only set at 300 for the tests).

File size: 8.0 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    grok.template('applicant_goto_interswitch')
62    action = POST_ACTION
63    site_name = SITE_NAME
64    currency = CURRENCY
65    pay_item_id = '101'
66    product_id = PRODUCT_ID
67    mac = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
68
69    def update(self):
70
71        super(CustomInterswitchPageApplicant, self).update()
72        xmldict = {}
73        provider_amt = 1000.0
74        xmldict['institution_acct'] = '1010835352'
75        xmldict['institution_bank_id'] = '117'
76        xmldict['detail_ref'] = self.context.p_id
77        xmldict['provider_amt'] = 100 * provider_amt
78        xmldict['provider_acct'] = PROVIDER_ACCT
79        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
80        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
81        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
82        xmldict['institution_item_name'] = self.context.p_category
83        xmldict['institution_name'] = INSTITUTION_NAME
84        # Interswitch amount is not part of the xml data
85        xmltext = """<payment_item_detail>
86<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
87<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" />
88<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" />
89</item_details>
90</payment_item_detail>""" % xmldict
91        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
92        self.context.provider_amt = provider_amt
93        self.context.gateway_amt = GATEWAY_AMT
94
95        hashargs = (
96            self.context.p_id +
97            PRODUCT_ID +
98            self.pay_item_id +
99            str(int(self.amount_auth)) +
100            self.site_redirect_url +
101            self.mac)
102        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
103
104        return
105
106class CustomInterswitchPageStudent(InterswitchPageStudent):
107    """ View which sends a POST request to the Interswitch
108    CollegePAY payment gateway.
109    """
110    grok.context(ICustomStudentOnlinePayment)
111    action = POST_ACTION
112    site_name = SITE_NAME
113    currency = CURRENCY
114    product_id = PRODUCT_ID
115    pay_item_id = '101'
116    mac = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
117
118    def update(self):
119        error = self.init_update()
120        if error:
121            self.flash(error, type='danger')
122            self.redirect(self.url(self.context, '@@index'))
123            return
124        student = self.student
125        xmldict = self.xmldict
126        # Provider data
127        xmldict['detail_ref'] = self.context.p_id
128        xmldict['provider_acct'] = PROVIDER_ACCT
129        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
130        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
131        # Institution data
132        xmldict['institution_acct'] = '00000000'
133        xmldict['institution_bank_id'] = '00'
134        xmldict['institution_amt'] = '0.0'
135        provider_amt = 0.0
136        xmldict['provider_amt'] = 100 * provider_amt
137        xmldict['institution_item_name'] = self.category
138        xmldict['institution_name'] = INSTITUTION_NAME
139        xmldict['institution_amt'] = 100 * (
140            self.context.amount_auth - provider_amt - GATEWAY_AMT)
141        # Interswitch amount is not part of the xml data
142        if provider_amt == 0:
143            xmltext = """<payment_item_detail>
144<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
145<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" />
146</item_details>
147</payment_item_detail>""" % xmldict
148        else:
149            xmltext = """<payment_item_detail>
150<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
151<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" />
152<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" />
153</item_details>
154</payment_item_detail>""" % xmldict
155        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
156        self.context.provider_amt = provider_amt
157        self.context.gateway_amt = GATEWAY_AMT
158
159        hashargs = (
160            self.context.p_id +
161            PRODUCT_ID +
162            self.pay_item_id +
163            str(int(self.amount_auth)) +
164            self.site_redirect_url +
165            self.mac)
166        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
167
168        return
169
170
171class CustomInterswitchPaymentRequestWebservicePageApplicant(
172    InterswitchPaymentRequestWebservicePageApplicant):
173    """ Request webservice view for the CollegePAY gateway
174    """
175    grok.context(ICustomApplicantOnlinePayment)
176    product_id = PRODUCT_ID
177    gateway_host = HOST
178    gateway_url = URL
179    https = HTTPS
180
181class CustomInterswitchPaymentRequestWebservicePageStudent(
182    InterswitchPaymentRequestWebservicePageStudent):
183    """ Request webservice view for the CollegePAY gateway
184    """
185    grok.context(ICustomStudentOnlinePayment)
186    product_id = PRODUCT_ID
187    gateway_host = HOST
188    gateway_url = URL
189    https = HTTPS
Note: See TracBrowser for help on using the repository browser.