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

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

Set mac key.

Enable installment payment.

  • Property svn:keywords set to Id
File size: 9.0 KB
Line 
1## $Id: browser.py 14342 2016-12-14 11:06:52Z 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
40
41POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
42#POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
43HOST = 'webpay.interswitchng.com'
44#HOST = 'stageserv.interswitchng.com'
45URL = '/paydirect/api/v1/gettransaction.json'
46#URL = '/test_paydirect/api/v1/gettransaction.json'
47
48httplib.HTTPSConnection.debuglevel = 0
49HTTPS = True
50
51class CustomInterswitchPageStudent(InterswitchPageStudent):
52    """ View which sends a POST request to the Interswitch
53    CollegePAY payment gateway.
54    """
55    grok.context(ICustomStudentOnlinePayment)
56    action = POST_ACTION
57    site_name = SITE_NAME
58    currency = CURRENCY
59    product_id = PRODUCT_ID
60    mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94'
61
62    def update(self):
63        error = self.init_update()
64        if error:
65            self.flash(error, type='danger')
66            self.redirect(self.url(self.context, '@@index'))
67            return
68        student = self.student
69        xmldict = self.xmldict
70        self.pay_item_id = '0000'
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 = 500.0
77        # Institution data
78        xmldict['institution_acct'] = '1019684470'
79        xmldict['institution_bank_id'] = '7'
80        xmldict['institution_item_name'] = self.context.category
81        xmldict['institution_name'] = INSTITUTION_NAME
82        if self.context.p_category == 'clearance':
83            self.pay_item_id = '102'
84        elif self.context.p_category.startswith('schoolfee'):
85            self.pay_item_id = '103'
86            if self.context.p_category in ('schoolfee', 'schoolfee_1'):
87                provider_amt = 4000.0
88        xmldict['provider_amt'] = 100 * provider_amt
89        xmldict['institution_amt'] = 100 * (
90            self.context.amount_auth - provider_amt - GATEWAY_AMT)
91
92        # Interswitch amount is not part of the xml data
93        if provider_amt == 0:
94            xmltext = """<payment_item_detail>
95<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
96<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" />
97</item_details>
98</payment_item_detail>""" % xmldict
99        else:
100            xmltext = """<payment_item_detail>
101<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
102<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" />
103<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" />
104</item_details>
105</payment_item_detail>""" % xmldict
106        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
107        self.context.provider_amt = provider_amt
108        self.context.gateway_amt = GATEWAY_AMT
109
110        hashargs = (
111            self.context.p_id +
112            PRODUCT_ID +
113            self.pay_item_id +
114            str(int(self.amount_auth)) +
115            self.site_redirect_url +
116            self.mac)
117        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
118        return
119
120class CustomInterswitchPageApplicant(InterswitchPageApplicant):
121    """ View which sends a POST request to the Interswitch
122    CollegePAY payment gateway.
123    """
124    grok.context(ICustomApplicantOnlinePayment)
125    action = POST_ACTION
126    site_name = SITE_NAME
127    currency = CURRENCY
128    pay_item_id = '101'
129    product_id = PRODUCT_ID
130    mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94'
131
132    def update(self):
133        error = self.init_update()
134        if error:
135            self.flash(error, type='danger')
136            self.redirect(self.url(self.context, '@@index'))
137            return
138        xmldict = {}
139        provider_amt = 500.0
140        xmldict['institution_acct'] = '1019684470'
141        xmldict['institution_bank_id'] = '7'
142        xmldict['detail_ref'] = self.context.p_id
143        xmldict['provider_amt'] = 100 * provider_amt
144        xmldict['provider_acct'] = PROVIDER_ACCT
145        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
146        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
147        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
148        xmldict['institution_item_name'] = self.context.category
149        xmldict['institution_name'] = INSTITUTION_NAME
150        # Interswitch amount is not part of the xml data
151        xmltext = """<payment_item_detail>
152<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
153<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" />
154<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" />
155</item_details>
156</payment_item_detail>""" % xmldict
157        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
158        self.context.provider_amt = provider_amt
159        self.context.gateway_amt = GATEWAY_AMT
160
161        hashargs = (
162            self.context.p_id +
163            PRODUCT_ID +
164            self.pay_item_id +
165            str(int(self.amount_auth)) +
166            self.site_redirect_url +
167            self.mac)
168        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
169        return
170
171class CustomInterswitchPaymentRequestWebservicePageStudent(
172    InterswitchPaymentRequestWebservicePageStudent):
173    """Request webservice view for the CollegePAY gateway
174    """
175    grok.context(ICustomStudentOnlinePayment)
176    product_id = PRODUCT_ID
177    gateway_host = HOST
178    gateway_url = URL
179    mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94'
180
181class CustomInterswitchPaymentVerifyWebservicePageStudent(
182    InterswitchPaymentVerifyWebservicePageStudent):
183    """Payment verify view for the CollegePAY gateway
184    """
185    grok.context(ICustomStudentOnlinePayment)
186    product_id = PRODUCT_ID
187    gateway_host = HOST
188    gateway_url = URL
189    mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94'
190
191class CustomInterswitchPaymentRequestWebservicePageApplicant(
192    InterswitchPaymentRequestWebservicePageApplicant):
193    """Request webservice view for the CollegePAY gateway
194    """
195    grok.context(ICustomApplicantOnlinePayment)
196    product_id = PRODUCT_ID
197    gateway_host = HOST
198    gateway_url = URL
199    mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94'
200
201class CustomInterswitchPaymentVerifyWebservicePageApplicant(
202    InterswitchPaymentVerifyWebservicePageApplicant):
203    """Payment verify view for the CollegePAY gateway
204    """
205    grok.context(ICustomApplicantOnlinePayment)
206    product_id = PRODUCT_ID
207    gateway_host = HOST
208    gateway_url = URL
209    mac = '9309B5CBF1BFB09693C6F5F578046E3FCAB0A2538C3FE4221A6E63AFD348DE888E655F9C7E9F112151A702B6B09E6A7ACC5B3BF3C701F0C1B0D8EA6C1872AE94'
Note: See TracBrowser for help on using the repository browser.