source: main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/interswitch/browser.py @ 14097

Last change on this file since 14097 was 14097, checked in by Henrik Bettermann, 8 years ago

Change app. taypes and categories.

Configure Interswitch test environment parameters.

  • Property svn:keywords set to Id
File size: 8.1 KB
Line 
1## $Id: browser.py 14097 2016-08-19 16:02:00Z 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 kofacustom.nigeria.interswitch.browser import (
22    InterswitchPaymentRequestWebservicePageApplicant,
23    InterswitchPaymentRequestWebservicePageStudent,
24    InterswitchPaymentVerifyWebservicePageApplicant,
25    InterswitchPaymentVerifyWebservicePageStudent,
26    InterswitchPageStudent, InterswitchPageApplicant,
27    )
28from kofacustom.coewarri.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.coewarri.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.coewarri.interfaces import MessageFactory as _
31
32PRODUCT_ID = '6207'
33SITE_NAME = 'coewarri-kofa.waeup.org'
34PROVIDER_ACCT = '0137712635'
35PROVIDER_BANK_ID = '10'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'COE Warri'
38CURRENCY = '566'
39GATEWAY_AMT = 300.0
40POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
41#POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
42
43#HOST = 'webpay.interswitchng.com'
44HOST = 'stageserv.interswitchng.com'
45HTTPS = True
46
47#URL = '/paydirect/api/v1/gettransaction.json'
48URL = '/test_paydirect/api/v1/gettransaction.json'
49
50httplib.HTTPSConnection.debuglevel = 0
51HTTPS = True
52
53class CustomInterswitchPageStudent(InterswitchPageStudent):
54    """ View which sends a POST request to the Interswitch
55    CollegePAY payment gateway.
56    """
57    grok.context(ICustomStudentOnlinePayment)
58    action = POST_ACTION
59    site_name = SITE_NAME
60    currency = CURRENCY
61    product_id = PRODUCT_ID
62    mac = ''
63
64    def update(self):
65        error = self.init_update()
66        if error:
67            self.flash(error, type='danger')
68            self.redirect(self.url(self.context, '@@index'))
69            return
70        student = self.student
71        xmldict = self.xmldict
72        # Provider data
73        xmldict['detail_ref'] = self.context.p_id
74        xmldict['provider_acct'] = PROVIDER_ACCT
75        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
76        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
77        # Institution data
78        xmldict['institution_acct'] = '00000000'
79        xmldict['institution_bank_id'] = '00'
80        xmldict['institution_amt'] = '0.0'
81        provider_amt = 0.0
82        self.pay_item_id = '0000'
83        xmldict['provider_amt'] = 100 * provider_amt
84        xmldict['institution_item_name'] = self.context.category
85        xmldict['institution_name'] = INSTITUTION_NAME
86        xmldict['institution_amt'] = 100 * (
87            self.context.amount_auth - provider_amt - GATEWAY_AMT)
88        # Interswitch amount is not part of the xml data
89        if provider_amt == 0:
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_details>
94</payment_item_detail>""" % xmldict
95        else:
96            xmltext = """<payment_item_detail>
97<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
98<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" />
99<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" />
100</item_details>
101</payment_item_detail>""" % xmldict
102        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
103        self.context.provider_amt = provider_amt
104        self.context.gateway_amt = GATEWAY_AMT
105
106        hashargs = (
107            self.context.p_id +
108            PRODUCT_ID +
109            self.pay_item_id +
110            str(int(self.amount_auth)) +
111            self.site_redirect_url +
112            self.mac)
113        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
114        return
115
116class CustomInterswitchPageApplicant(InterswitchPageApplicant):
117    """ View which sends a POST request to the Interswitch
118    CollegePAY payment gateway.
119    """
120    grok.context(ICustomApplicantOnlinePayment)
121    action = POST_ACTION
122    site_name = SITE_NAME
123    currency = CURRENCY
124    pay_item_id = '101'
125    product_id = PRODUCT_ID
126    mac = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
127
128    def update(self):
129        error = self.init_update()
130        if error:
131            self.flash(error, type='danger')
132            self.redirect(self.url(self.context, '@@index'))
133            return
134        xmldict = {}
135        provider_amt = 500.0
136        xmldict['institution_acct'] = '1005154149'
137        xmldict['institution_bank_id'] = '7'
138        xmldict['detail_ref'] = self.context.p_id
139        xmldict['provider_amt'] = 100 * provider_amt
140        xmldict['provider_acct'] = PROVIDER_ACCT
141        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
142        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
143        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
144        xmldict['institution_item_name'] = self.context.category
145        xmldict['institution_name'] = INSTITUTION_NAME
146        # Interswitch amount is not part of the xml data
147        xmltext = """<payment_item_detail>
148<item_details detail_ref="%(detail_ref)s" college="%(institution_name)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        return
166
167class CustomInterswitchPaymentRequestWebservicePageStudent(
168    InterswitchPaymentRequestWebservicePageStudent):
169    """Request webservice view for the CollegePAY gateway
170    """
171    grok.context(ICustomStudentOnlinePayment)
172    product_id = PRODUCT_ID
173    gateway_host = HOST
174    gateway_url = URL
175
176class CustomInterswitchPaymentVerifyWebservicePageStudent(
177    InterswitchPaymentVerifyWebservicePageStudent):
178    """Payment verify view for the CollegePAY gateway
179    """
180    grok.context(ICustomStudentOnlinePayment)
181    product_id = PRODUCT_ID
182    gateway_host = HOST
183    gateway_url = URL
184
185class CustomInterswitchPaymentRequestWebservicePageApplicant(
186    InterswitchPaymentRequestWebservicePageApplicant):
187    """Request webservice view for the CollegePAY gateway
188    """
189    grok.context(ICustomApplicantOnlinePayment)
190    product_id = PRODUCT_ID
191    gateway_host = HOST
192    gateway_url = URL
193
194class CustomInterswitchPaymentVerifyWebservicePageApplicant(
195    InterswitchPaymentVerifyWebservicePageApplicant):
196    """Payment verify view for the CollegePAY gateway
197    """
198    grok.context(ICustomApplicantOnlinePayment)
199    product_id = PRODUCT_ID
200    gateway_host = HOST
201    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.