source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/interswitch/browser.py @ 15800

Last change on this file since 15800 was 15794, checked in by Henrik Bettermann, 5 years ago

Change bank account.

  • Property svn:keywords set to Id
File size: 10.7 KB
Line 
1## $Id: browser.py 15794 2019-11-11 06:51:45Z 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.iuokada.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.iuokada.interfaces import MessageFactory as _
31
32PRODUCT_ID = '7922'
33SITE_NAME = 'iuokada-kofa.waeup.org'
34PROVIDER_ACCT = '0773411069'
35PROVIDER_BANK_ID = '31'
36PROVIDER_ITEM_NAME = 'WAeAC'
37INSTITUTION_NAME = 'IUOkada'
38CURRENCY = '566'
39GATEWAY_AMT = 250.0
40#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch
41MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA'
42
43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
44#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
45HOST = 'webpay.interswitchng.com'
46#HOST = 'sandbox.interswitchng.com'
47URL = '/paydirect/api/v1/gettransaction.json'
48#URL = '/webpay/api/v1/gettransaction.json'
49
50httplib.HTTPSConnection.debuglevel = 0
51HTTPS = True
52
53class CustomInterswitchPageStudent(InterswitchPageStudent):
54    """ View which sends a POST request to the Interswitch
55    CollegePAY payment gateway.
56    """
57    grok.context(ICustomStudentOnlinePayment)
58    action = POST_ACTION
59    site_name = SITE_NAME
60    currency = CURRENCY
61    product_id = PRODUCT_ID
62    mac = MAC 
63    gateway_amt = GATEWAY_AMT
64
65    def update(self):
66        error = self.init_update()
67        if error:
68            self.flash(error, type='danger')
69            self.redirect(self.url(self.context, '@@index'))
70            return
71        # Already now it becomes an Interswitch payment. We set the net amount
72        # and add the gateway amount.
73        if not self.context.r_company:
74            self.context.net_amt = self.context.amount_auth
75            self.context.amount_auth += self.gateway_amt
76            self.context.gateway_amt = self.gateway_amt
77            self.context.r_company = u'interswitch'
78        student = self.student
79        xmldict = self.xmldict
80        # Provider data
81        xmldict['detail_ref'] = self.context.p_id
82        xmldict['provider_acct'] = PROVIDER_ACCT
83        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
84        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
85        xmldict['institution_acct'] = ''
86        xmldict['institution_bank_id'] = ''
87        provider_amt = 0.0
88        self.pay_item_id = ''
89        # Institution data
90        if self.context.p_category in (
91            'schoolfee', 'schoolfee40', 'secondinstal'):
92            xmldict['institution_acct'] = '1011005811'
93            xmldict['institution_bank_id'] = '117'
94            self.pay_item_id = '101'
95        elif self.context.p_category == 'book':
96            xmldict['institution_acct'] = '1013249587'
97            xmldict['institution_bank_id'] = '117'
98            self.pay_item_id = '103'
99        elif self.context.p_category == 'parentsconsult':
100            xmldict['institution_acct'] = '1012355544'
101            xmldict['institution_bank_id'] = '117'
102            self.pay_item_id = '104'
103        elif self.context.p_category in (
104            'municipal_fresh', 'municipal_returning',
105            'transcript_local', 'transcript_overseas'):
106            xmldict['institution_acct'] = '0040621193'
107            xmldict['institution_bank_id'] = '31'
108            self.pay_item_id = '105'
109        else:
110            xmldict['institution_acct'] = '1011050158'
111            xmldict['institution_bank_id'] = '117'
112            self.pay_item_id = '102'
113        if self.context.p_category == 'registration':
114            provider_amt = 5000.0
115        xmldict['provider_amt'] = 100 * provider_amt
116        xmldict['institution_item_name'] = self.context.category
117        xmldict['institution_name'] = INSTITUTION_NAME
118        xmldict['institution_amt'] = 100 * self.context.net_amt
119        if not self.context.provider_amt:
120            self.context.provider_amt = provider_amt
121            self.context.amount_auth += provider_amt
122        if provider_amt == 0:
123            xmltext = """<payment_item_detail>
124<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
125<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" />
126</item_details>
127</payment_item_detail>""" % xmldict
128        else:
129            xmltext = """<payment_item_detail>
130<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
131<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" />
132<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" />
133</item_details>
134</payment_item_detail>""" % xmldict
135        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
136        self.amount_auth = int(100 * self.context.amount_auth)
137        hashargs = (
138            self.context.p_id +
139            PRODUCT_ID +
140            self.pay_item_id +
141            str(int(self.amount_auth)) +
142            self.site_redirect_url +
143            self.mac)
144        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
145        return
146
147class CustomInterswitchPageApplicant(InterswitchPageApplicant):
148    """ View which sends a POST request to the Interswitch
149    CollegePAY payment gateway.
150    """
151    grok.context(ICustomApplicantOnlinePayment)
152    action = POST_ACTION
153    site_name = SITE_NAME
154    currency = CURRENCY
155    product_id = PRODUCT_ID
156    mac = MAC
157    gateway_amt = GATEWAY_AMT
158
159    def update(self):
160        error = self.init_update()
161        if error:
162            self.flash(error, type='danger')
163            self.redirect(self.url(self.context, '@@index'))
164            return
165        # Already now it becomes an Interswitch payment. We set the net amount
166        # and add the gateway amount.
167        if not self.context.r_company:
168            self.context.net_amt = self.context.amount_auth
169            self.context.amount_auth += self.gateway_amt
170            self.context.gateway_amt = self.gateway_amt
171            self.context.r_company = u'interswitch'
172        self.amount_auth = int(100 * self.context.amount_auth)
173        xmldict = {}
174        provider_amt = 0.0
175        self.pay_item_id = '101'
176        xmldict['institution_acct'] = '1011005811'
177        xmldict['institution_bank_id'] = '117'
178        xmldict['detail_ref'] = self.context.p_id
179        xmldict['provider_amt'] = 100 * provider_amt
180        xmldict['provider_acct'] = PROVIDER_ACCT
181        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
182        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
183        xmldict['institution_item_name'] = self.context.category
184        xmldict['institution_name'] = INSTITUTION_NAME
185        xmldict['institution_amt'] = 100 * self.context.net_amt
186        if not self.context.provider_amt:
187            self.context.provider_amt = provider_amt
188            self.context.amount_auth += provider_amt
189        if provider_amt == 0:
190            xmltext = """<payment_item_detail>
191<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
192<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" />
193</item_details>
194</payment_item_detail>""" % xmldict
195        else:
196            xmltext = """<payment_item_detail>
197<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
198<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" />
199<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" />
200</item_details>
201</payment_item_detail>""" % xmldict
202        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
203        self.amount_auth = int(100 * self.context.amount_auth)
204        hashargs = (
205            self.context.p_id +
206            PRODUCT_ID +
207            self.pay_item_id +
208            str(int(self.amount_auth)) +
209            self.site_redirect_url +
210            self.mac)
211        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
212        return
213
214class CustomInterswitchPaymentRequestWebservicePageStudent(
215    InterswitchPaymentRequestWebservicePageStudent):
216    """Request webservice view for the CollegePAY gateway
217    """
218    grok.context(ICustomStudentOnlinePayment)
219    product_id = PRODUCT_ID
220    gateway_host = HOST
221    gateway_url = URL
222    mac = MAC
223
224class CustomInterswitchPaymentVerifyWebservicePageStudent(
225    InterswitchPaymentVerifyWebservicePageStudent):
226    """Payment verify view for the CollegePAY gateway
227    """
228    grok.context(ICustomStudentOnlinePayment)
229    product_id = PRODUCT_ID
230    gateway_host = HOST
231    gateway_url = URL
232    mac = MAC
233
234class CustomInterswitchPaymentRequestWebservicePageApplicant(
235    InterswitchPaymentRequestWebservicePageApplicant):
236    """Request webservice view for the CollegePAY gateway
237    """
238    grok.context(ICustomApplicantOnlinePayment)
239    product_id = PRODUCT_ID
240    gateway_host = HOST
241    gateway_url = URL
242    mac = MAC
243
244class CustomInterswitchPaymentVerifyWebservicePageApplicant(
245    InterswitchPaymentVerifyWebservicePageApplicant):
246    """Payment verify view for the CollegePAY gateway
247    """
248    grok.context(ICustomApplicantOnlinePayment)
249    product_id = PRODUCT_ID
250    gateway_host = HOST
251    gateway_url = URL
252    mac = MAC
Note: See TracBrowser for help on using the repository browser.