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

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

Remove trash.

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