source: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/interswitch/browser.py @ 15030

Last change on this file since 15030 was 15026, checked in by Henrik Bettermann, 7 years ago

Change account number.

  • Property svn:keywords set to Id
File size: 8.5 KB
Line 
1## $Id: browser.py 15026 2018-05-25 10:31:41Z 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.edopoly.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.edopoly.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.edopoly.interfaces import MessageFactory as _
31
32PRODUCT_ID = '7571' # must be provided by Interswitch
33SITE_NAME = 'edopoly-kofa.waeup.org'
34PROVIDER_ACCT = '0773411069'
35PROVIDER_BANK_ID = '31'
36PROVIDER_ITEM_NAME = 'WAeAC'
37INSTITUTION_NAME = 'EdoPoly'
38CURRENCY = '566'
39GATEWAY_AMT = 250.0
40MAC = '672ABFB2F3755A7793DE545BDA00F44878DF59140B43A1E7DF16245D299F3108AFF65502F16D95256B3242B43CBC3F512A208EB1BA977080D65328800C49912C'
41
42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
43#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
44HOST = 'webpay.interswitchng.com'
45#HOST = 'sandbox.interswitchng.com'
46URL = '/paydirect/api/v1/gettransaction.json'
47#URL = '/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        provider_amt = 0.0
77        if self.context.p_category == 'ict_entre':
78            provider_amt = 3000.0
79        if self.context.p_category == 'clearance':
80            provider_amt = 1500.0
81        if self.context.p_category in ('transcript', 'certificate'):
82            provider_amt = 2000.0
83        # Institution data
84        xmldict['institution_acct'] = '0068241848'
85        xmldict['institution_bank_id'] = '121'
86        xmldict['institution_amt'] = '0.0'
87        self.pay_item_id = '101' # must be provided by Interswitch
88        xmldict['provider_amt'] = 100 * provider_amt
89        xmldict['institution_item_name'] = self.context.category
90        xmldict['institution_name'] = INSTITUTION_NAME
91        xmldict['institution_amt'] = 100 * (
92            self.context.amount_auth - provider_amt - GATEWAY_AMT)
93        # Interswitch amount is not part of the xml data
94        if provider_amt == 0:
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_details>
99</payment_item_detail>""" % xmldict
100        else:
101            xmltext = """<payment_item_detail>
102<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
103<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" />
104<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" />
105</item_details>
106</payment_item_detail>""" % xmldict
107        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
108        self.context.provider_amt = provider_amt
109        self.context.gateway_amt = GATEWAY_AMT
110
111        hashargs = (
112            self.context.p_id +
113            PRODUCT_ID +
114            self.pay_item_id +
115            str(int(self.amount_auth)) +
116            self.site_redirect_url +
117            self.mac)
118        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
119        return
120
121class CustomInterswitchPageApplicant(InterswitchPageApplicant):
122    """ View which sends a POST request to the Interswitch
123    CollegePAY payment gateway.
124    """
125    grok.context(ICustomApplicantOnlinePayment)
126    action = POST_ACTION
127    site_name = SITE_NAME
128    currency = CURRENCY
129    pay_item_id = '101' # must be provided by Interswitch
130    product_id = PRODUCT_ID
131    mac = MAC
132
133    def update(self):
134        error = self.init_update()
135        if error:
136            self.flash(error, type='danger')
137            self.redirect(self.url(self.context, '@@index'))
138            return
139        xmldict = {}
140        provider_amt = 1000.0
141        xmldict['institution_acct'] = '1015666713'
142        xmldict['institution_bank_id'] = '121'
143        xmldict['detail_ref'] = self.context.p_id
144        xmldict['provider_amt'] = 100 * provider_amt
145        xmldict['provider_acct'] = PROVIDER_ACCT
146        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
147        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
148        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
149        xmldict['institution_item_name'] = self.context.category
150        xmldict['institution_name'] = INSTITUTION_NAME
151        # Interswitch amount is not part of the xml data
152        xmltext = """<payment_item_detail>
153<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
154<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" />
155<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" />
156</item_details>
157</payment_item_detail>""" % xmldict
158        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
159        self.context.provider_amt = provider_amt
160        self.context.gateway_amt = GATEWAY_AMT
161
162        hashargs = (
163            self.context.p_id +
164            PRODUCT_ID +
165            self.pay_item_id +
166            str(int(self.amount_auth)) +
167            self.site_redirect_url +
168            self.mac)
169        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
170        return
171
172class CustomInterswitchPaymentRequestWebservicePageStudent(
173    InterswitchPaymentRequestWebservicePageStudent):
174    """Request webservice view for the CollegePAY gateway
175    """
176    grok.context(ICustomStudentOnlinePayment)
177    product_id = PRODUCT_ID
178    gateway_host = HOST
179    gateway_url = URL
180    mac = MAC
181
182class CustomInterswitchPaymentVerifyWebservicePageStudent(
183    InterswitchPaymentVerifyWebservicePageStudent):
184    """Payment verify view for the CollegePAY gateway
185    """
186    grok.context(ICustomStudentOnlinePayment)
187    product_id = PRODUCT_ID
188    gateway_host = HOST
189    gateway_url = URL
190    mac = MAC
191
192class CustomInterswitchPaymentRequestWebservicePageApplicant(
193    InterswitchPaymentRequestWebservicePageApplicant):
194    """Request webservice view for the CollegePAY gateway
195    """
196    grok.context(ICustomApplicantOnlinePayment)
197    product_id = PRODUCT_ID
198    gateway_host = HOST
199    gateway_url = URL
200    mac = MAC
201
202class CustomInterswitchPaymentVerifyWebservicePageApplicant(
203    InterswitchPaymentVerifyWebservicePageApplicant):
204    """Payment verify view for the CollegePAY gateway
205    """
206    grok.context(ICustomApplicantOnlinePayment)
207    product_id = PRODUCT_ID
208    gateway_host = HOST
209    gateway_url = URL
210    mac = MAC
Note: See TracBrowser for help on using the repository browser.