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

Last change on this file since 15335 was 15335, checked in by Henrik Bettermann, 6 years ago

Substract share_amt too.

  • Property svn:keywords set to Id
File size: 9.5 KB
Line 
1## $Id: browser.py 15335 2019-02-18 18:54:55Z 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 = '6667'
33SITE_NAME = 'coewarri-kofa.waeup.org'
34PROVIDER_ACCT = '0427773399'
35PROVIDER_BANK_ID = '10'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'COE Warri'
38CURRENCY = '566'
39GATEWAY_AMT = 250.0
40MAC = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94'
41
42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
43#POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
44HOST = 'webpay.interswitchng.com'
45#HOST = 'stageserv.interswitchng.com'
46URL = '/paydirect/api/v1/gettransaction.json'
47#URL = '/test_paydirect/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        self.pay_item_id = '0000'
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        provider_amt = 0.0
78        share_amt = 0.0
79        # Institution data
80        xmldict['institution_acct'] = '1019684470'
81        xmldict['institution_bank_id'] = '7'
82        xmldict['institution_item_name'] = self.context.category
83        xmldict['institution_name'] = INSTITUTION_NAME
84        if self.context.p_category == 'clearance':
85            self.pay_item_id = '102'
86            provider_amt = 500.0
87        elif self.context.p_category.startswith('schoolfee'):
88            self.pay_item_id = '103'
89            if self.context.p_category in ('schoolfee_1', 'schoolfee_2') \
90                and not self.context.p_item == 'Balance':
91                provider_amt = 1400.0
92                share_amt = 600.0
93            if self.context.p_category == 'schoolfee' \
94                and not self.context.p_item == 'Balance':
95                provider_amt = 2800.0
96                share_amt = 1200.0
97        xmldict['provider_amt'] = 100 * provider_amt
98        xmldict['share_amt'] = 100 * share_amt
99        xmldict['institution_amt'] = 100 * (
100            self.context.amount_auth - provider_amt - share_amt - GATEWAY_AMT)
101
102        # Interswitch amount is not part of the xml data
103        if provider_amt == 0:
104            xmltext = """<payment_item_detail>
105<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
106<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" />
107</item_details>
108</payment_item_detail>""" % xmldict
109        elif share_amt == 0:
110            xmltext = """<payment_item_detail>
111<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
112<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" />
113<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" />
114</item_details>
115</payment_item_detail>""" % xmldict
116        else:
117            xmltext = """<payment_item_detail>
118<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
119<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" />
120<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" />
121<item_detail item_id="3" item_name="Tech Fee Share" item_amt="%(share_amt)d" bank_id="307" acct_num="5100189030" />
122</item_details>
123</payment_item_detail>""" % xmldict
124        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
125        self.context.provider_amt = provider_amt
126        self.context.gateway_amt = GATEWAY_AMT
127
128        hashargs = (
129            self.context.p_id +
130            PRODUCT_ID +
131            self.pay_item_id +
132            str(int(self.amount_auth)) +
133            self.site_redirect_url +
134            self.mac)
135        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
136        return
137
138class CustomInterswitchPageApplicant(InterswitchPageApplicant):
139    """ View which sends a POST request to the Interswitch
140    CollegePAY payment gateway.
141    """
142    grok.context(ICustomApplicantOnlinePayment)
143    action = POST_ACTION
144    site_name = SITE_NAME
145    currency = CURRENCY
146    pay_item_id = '101'
147    product_id = PRODUCT_ID
148    mac = MAC
149
150    def update(self):
151        error = self.init_update()
152        if error:
153            self.flash(error, type='danger')
154            self.redirect(self.url(self.context, '@@index'))
155            return
156        xmldict = {}
157        provider_amt = 500.0
158        xmldict['institution_acct'] = '1019684470'
159        xmldict['institution_bank_id'] = '7'
160        xmldict['detail_ref'] = self.context.p_id
161        xmldict['provider_amt'] = 100 * provider_amt
162        xmldict['provider_acct'] = PROVIDER_ACCT
163        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
164        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
165        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
166        xmldict['institution_item_name'] = self.context.category
167        xmldict['institution_name'] = INSTITUTION_NAME
168        # Interswitch amount is not part of the xml data
169        xmltext = """<payment_item_detail>
170<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
171<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" />
172<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" />
173</item_details>
174</payment_item_detail>""" % xmldict
175        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
176        self.context.provider_amt = provider_amt
177        self.context.gateway_amt = GATEWAY_AMT
178
179        hashargs = (
180            self.context.p_id +
181            PRODUCT_ID +
182            self.pay_item_id +
183            str(int(self.amount_auth)) +
184            self.site_redirect_url +
185            self.mac)
186        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
187        return
188
189class CustomInterswitchPaymentRequestWebservicePageStudent(
190    InterswitchPaymentRequestWebservicePageStudent):
191    """Request webservice view for the CollegePAY gateway
192    """
193    grok.context(ICustomStudentOnlinePayment)
194    product_id = PRODUCT_ID
195    gateway_host = HOST
196    gateway_url = URL
197    mac = MAC
198
199class CustomInterswitchPaymentVerifyWebservicePageStudent(
200    InterswitchPaymentVerifyWebservicePageStudent):
201    """Payment verify view for the CollegePAY gateway
202    """
203    grok.context(ICustomStudentOnlinePayment)
204    product_id = PRODUCT_ID
205    gateway_host = HOST
206    gateway_url = URL
207    mac = MAC
208
209class CustomInterswitchPaymentRequestWebservicePageApplicant(
210    InterswitchPaymentRequestWebservicePageApplicant):
211    """Request webservice view for the CollegePAY gateway
212    """
213    grok.context(ICustomApplicantOnlinePayment)
214    product_id = PRODUCT_ID
215    gateway_host = HOST
216    gateway_url = URL
217    mac = MAC
218
219class CustomInterswitchPaymentVerifyWebservicePageApplicant(
220    InterswitchPaymentVerifyWebservicePageApplicant):
221    """Payment verify view for the CollegePAY gateway
222    """
223    grok.context(ICustomApplicantOnlinePayment)
224    product_id = PRODUCT_ID
225    gateway_host = HOST
226    gateway_url = URL
227    mac = MAC
Note: See TracBrowser for help on using the repository browser.