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

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

Implement payment by instalments.

  • Property svn:keywords set to Id
File size: 8.4 KB
Line 
1## $Id: browser.py 14344 2016-12-14 16:57:13Z 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 = '0137712635'
35PROVIDER_BANK_ID = '10'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'COE Warri'
38CURRENCY = '566'
39GATEWAY_AMT = 300.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 = 500.0
78        # Institution data
79        xmldict['institution_acct'] = '1019684470'
80        xmldict['institution_bank_id'] = '7'
81        xmldict['institution_item_name'] = self.context.category
82        xmldict['institution_name'] = INSTITUTION_NAME
83        if self.context.p_category == 'clearance':
84            self.pay_item_id = '102'
85        elif self.context.p_category.startswith('schoolfee'):
86            self.pay_item_id = '103'
87            if self.context.p_category in ('schoolfee', 'schoolfee_1'):
88                provider_amt = 4000.0
89        xmldict['provider_amt'] = 100 * provider_amt
90        xmldict['institution_amt'] = 100 * (
91            self.context.amount_auth - provider_amt - GATEWAY_AMT)
92
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'
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 = 500.0
141        xmldict['institution_acct'] = '1019684470'
142        xmldict['institution_bank_id'] = '7'
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.