source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/interswitch/browser.py @ 15684

Last change on this file since 15684 was 15684, checked in by Henrik Bettermann, 5 years ago

Configuration for testing without xml split data.

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