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

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

Adjust provider_amt and change bank account.

  • Property svn:keywords set to Id
File size: 8.7 KB
Line 
1## $Id: browser.py 15321 2019-02-04 19:21:17Z 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        # Institution data
79        xmldict['institution_acct'] = '1020855036'
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            provider_amt = 500.0
86        elif self.context.p_category.startswith('schoolfee'):
87            self.pay_item_id = '103'
88            if self.context.p_category in ('schoolfee_1', 'schoolfee_2') \
89                and not self.context.p_item == 'Balance':
90                provider_amt = 2000.0
91            if self.context.p_category == 'schoolfee' \
92                and not self.context.p_item == 'Balance':
93                provider_amt = 4000.0
94        xmldict['provider_amt'] = 100 * provider_amt
95        xmldict['institution_amt'] = 100 * (
96            self.context.amount_auth - provider_amt - GATEWAY_AMT)
97
98        # Interswitch amount is not part of the xml data
99        if provider_amt == 0:
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_details>
104</payment_item_detail>""" % xmldict
105        else:
106            xmltext = """<payment_item_detail>
107<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
108<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" />
109<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" />
110</item_details>
111</payment_item_detail>""" % xmldict
112        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
113        self.context.provider_amt = provider_amt
114        self.context.gateway_amt = GATEWAY_AMT
115
116        hashargs = (
117            self.context.p_id +
118            PRODUCT_ID +
119            self.pay_item_id +
120            str(int(self.amount_auth)) +
121            self.site_redirect_url +
122            self.mac)
123        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
124        return
125
126class CustomInterswitchPageApplicant(InterswitchPageApplicant):
127    """ View which sends a POST request to the Interswitch
128    CollegePAY payment gateway.
129    """
130    grok.context(ICustomApplicantOnlinePayment)
131    action = POST_ACTION
132    site_name = SITE_NAME
133    currency = CURRENCY
134    pay_item_id = '101'
135    product_id = PRODUCT_ID
136    mac = MAC
137
138    def update(self):
139        error = self.init_update()
140        if error:
141            self.flash(error, type='danger')
142            self.redirect(self.url(self.context, '@@index'))
143            return
144        xmldict = {}
145        provider_amt = 500.0
146        xmldict['institution_acct'] = '1020855036'
147        xmldict['institution_bank_id'] = '7'
148        xmldict['detail_ref'] = self.context.p_id
149        xmldict['provider_amt'] = 100 * provider_amt
150        xmldict['provider_acct'] = PROVIDER_ACCT
151        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
152        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
153        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
154        xmldict['institution_item_name'] = self.context.category
155        xmldict['institution_name'] = INSTITUTION_NAME
156        # Interswitch amount is not part of the xml data
157        xmltext = """<payment_item_detail>
158<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
159<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" />
160<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" />
161</item_details>
162</payment_item_detail>""" % xmldict
163        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
164        self.context.provider_amt = provider_amt
165        self.context.gateway_amt = GATEWAY_AMT
166
167        hashargs = (
168            self.context.p_id +
169            PRODUCT_ID +
170            self.pay_item_id +
171            str(int(self.amount_auth)) +
172            self.site_redirect_url +
173            self.mac)
174        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
175        return
176
177class CustomInterswitchPaymentRequestWebservicePageStudent(
178    InterswitchPaymentRequestWebservicePageStudent):
179    """Request webservice view for the CollegePAY gateway
180    """
181    grok.context(ICustomStudentOnlinePayment)
182    product_id = PRODUCT_ID
183    gateway_host = HOST
184    gateway_url = URL
185    mac = MAC
186
187class CustomInterswitchPaymentVerifyWebservicePageStudent(
188    InterswitchPaymentVerifyWebservicePageStudent):
189    """Payment verify view for the CollegePAY gateway
190    """
191    grok.context(ICustomStudentOnlinePayment)
192    product_id = PRODUCT_ID
193    gateway_host = HOST
194    gateway_url = URL
195    mac = MAC
196
197class CustomInterswitchPaymentRequestWebservicePageApplicant(
198    InterswitchPaymentRequestWebservicePageApplicant):
199    """Request webservice view for the CollegePAY gateway
200    """
201    grok.context(ICustomApplicantOnlinePayment)
202    product_id = PRODUCT_ID
203    gateway_host = HOST
204    gateway_url = URL
205    mac = MAC
206
207class CustomInterswitchPaymentVerifyWebservicePageApplicant(
208    InterswitchPaymentVerifyWebservicePageApplicant):
209    """Payment verify view for the CollegePAY gateway
210    """
211    grok.context(ICustomApplicantOnlinePayment)
212    product_id = PRODUCT_ID
213    gateway_host = HOST
214    gateway_url = URL
215    mac = MAC
Note: See TracBrowser for help on using the repository browser.