source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/interswitch/browser.py @ 17117

Last change on this file since 17117 was 17117, checked in by Henrik Bettermann, 2 years ago

Configure JUPEB school fee.

  • Property svn:keywords set to Id
File size: 12.8 KB
Line 
1## $Id: browser.py 17117 2022-10-05 08:51:03Z 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    module_activated,
23    InterswitchPaymentRequestWebservicePageApplicant,
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
29from kofacustom.unidel.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.unidel.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.unidel.interfaces import MessageFactory as _
32
33PRODUCT_ID = '22153701' # must be provided by Interswitch
34SITE_NAME = 'unidel.waeup.org'
35PROVIDER_ACCT = '0213065415'
36PROVIDER_BANK_ID = '47'
37PROVIDER_ITEM_NAME = 'WAeAC'
38INSTITUTION_NAME = 'UNIDEL'
39CURRENCY = '566'
40GATEWAY_AMT = 250.0
41#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
42MAC = 'Lfj58PyWS6MvPz65zIbofZNoAn89fZAjtnsEWbTof73OyHQH7rpJPHWD2m4cekDoowJ8nqQCn6ay2lopzKBOekFsMfzkXG6KYGRuyhMQq4bK7wDNaWqpxeZl3fMumNmi'
43
44POST_ACTION = 'https://webpay.interswitchng.com/collections/w/pay'
45#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
46HOST = 'webpay.interswitchng.com'
47#HOST = 'sandbox.interswitchng.com'
48URL = '/collections/api/v1/gettransaction.json'
49#URL = '/webpay/api/v1/gettransaction.json'
50
51httplib.HTTPSConnection.debuglevel = 0
52HTTPS = True
53
54class CustomInterswitchPageStudent(InterswitchPageStudent):
55    """ View which sends a POST request to the Interswitch
56    CollegePAY payment gateway.
57    """
58    grok.context(ICustomStudentOnlinePayment)
59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
63    mac = MAC
64    gateway_amt = GATEWAY_AMT
65
66    def update(self):
67        if not module_activated(
68            self.context.student.current_session, self.context):
69            self.flash(_('Forbidden'), type='danger')
70            self.redirect(self.url(self.context, '@@index'))
71            return
72        error = self.init_update()
73        if error:
74            self.flash(error, type='danger')
75            self.redirect(self.url(self.context, '@@index'))
76            return
77        student = self.student
78        xmldict = self.xmldict
79        # Provider data
80        xmldict['detail_ref'] = self.context.p_id
81        xmldict['provider_acct'] = PROVIDER_ACCT
82        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
83        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
84        # Institution data
85        xmldict['institution_acct'] = '000000000'
86        xmldict['institution_bank_id'] = '000'
87        provider_amt = 0.0
88        tech_fee = 0.0
89        if self.context.p_category == 'clearance':
90            provider_amt = 500.0
91            xmldict['institution_acct'] = '1216063205'
92            xmldict['institution_bank_id'] = '117'
93            if student.is_jupeb:
94                xmldict['institution_acct'] = '1011431799'
95        if self.context.p_category == 'schoolfee':
96            provider_amt = 2800.0
97            tech_fee = 1200.0
98            xmldict['institution_acct'] = '1011739172'
99            xmldict['institution_bank_id'] = '117'
100            if student.is_jupeb:
101                xmldict['institution_acct'] = '2001627961'
102                xmldict['institution_bank_id'] = '8'
103        if self.context.p_category == 'hostel_maintenance':
104            xmldict['institution_acct'] = '1012551384'
105            xmldict['institution_bank_id'] = '117'
106        self.pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
107        # Already now it becomes an Interswitch payment. We set the net amount
108        # and add gateway amount and other surcharges.
109        if not self.context.r_company:
110            self.context.r_company = u'interswitch'
111            self.context.net_amt = self.context.amount_auth
112            self.context.gateway_amt = self.gateway_amt
113            self.context.amount_auth += self.gateway_amt
114            self.context.provider_amt = provider_amt
115            self.context.amount_auth += provider_amt
116            self.context.amount_auth += tech_fee
117        xmldict['provider_amt'] = 100 * provider_amt
118        xmldict['tech_fee'] = 100 * tech_fee
119        xmldict['institution_item_name'] = self.context.category
120        xmldict['institution_name'] = INSTITUTION_NAME
121        xmldict['institution_amt'] = 100 * self.context.net_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        elif tech_fee == 0:
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        else:
136            xmltext = """<payment_item_detail>
137<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
138<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" />
139<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" />
140<item_detail item_id="3" item_name="Technology Fee" item_amt="%(tech_fee)d" bank_id="47" acct_num="0213065415" />
141</item_details>
142</payment_item_detail>""" % xmldict
143        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
144        self.context.provider_amt = provider_amt
145        self.amount_auth = int(100 * self.context.amount_auth)
146        hashargs = (
147            self.context.p_id +
148            PRODUCT_ID +
149            self.pay_item_id +
150            str(int(self.amount_auth)) +
151            self.site_redirect_url +
152            self.mac)
153        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
154        return
155
156class CustomInterswitchPageApplicant(InterswitchPageApplicant):
157    """ View which sends a POST request to the Interswitch
158    CollegePAY payment gateway.
159    """
160    grok.context(ICustomApplicantOnlinePayment)
161    action = POST_ACTION
162    site_name = SITE_NAME
163    currency = CURRENCY
164    pay_item_id = 'Default_Payable_MX47126' # must be provided by Interswitch
165    product_id = PRODUCT_ID
166    mac = MAC
167    gateway_amt = GATEWAY_AMT
168
169    def update(self):
170        if not module_activated(
171            self.context.__parent__.__parent__.year, self.context):
172            self.flash(_('Forbidden'), type='danger')
173            self.redirect(self.url(self.context, '@@index'))
174            return
175        error = self.init_update()
176        if error:
177            self.flash(error, type='danger')
178            self.redirect(self.url(self.context, '@@index'))
179            return
180        # Already now it becomes an Interswitch payment. We set the net amount
181        # and add the gateway amount.
182        if not self.context.r_company:
183            self.context.net_amt = self.context.amount_auth
184            self.context.amount_auth += self.gateway_amt
185            self.context.gateway_amt = self.gateway_amt
186            self.context.r_company = u'interswitch'
187        xmldict = {}
188        provider_amt = 250.0
189        xmldict['institution_acct'] = '1216063205'
190        xmldict['institution_bank_id'] = '117'
191        if self.context.__parent__.__parent__.prefix in (
192                                    'pre', 'jupeb', 'dp_ft', 'dp_pt'):
193            xmldict['institution_acct'] = '1011431799'
194            xmldict['institution_bank_id'] = '117'
195            provider_amt = 500.0           
196        xmldict['detail_ref'] = self.context.p_id
197        xmldict['provider_amt'] = 100 * provider_amt
198        xmldict['provider_acct'] = PROVIDER_ACCT
199        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
200        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
201        xmldict['institution_item_name'] = self.context.category
202        xmldict['institution_name'] = INSTITUTION_NAME
203        xmldict['institution_amt'] = 100 * self.context.net_amt
204        if not self.context.provider_amt:
205            self.context.provider_amt = provider_amt
206            self.context.amount_auth += provider_amt
207        xmltext = """<payment_item_detail>
208<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
209<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" />
210<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" />
211</item_details>
212</payment_item_detail>""" % xmldict
213        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
214        self.amount_auth = int(100 * self.context.amount_auth)
215        hashargs = (
216            self.context.p_id +
217            PRODUCT_ID +
218            self.pay_item_id +
219            str(int(self.amount_auth)) +
220            self.site_redirect_url +
221            self.mac)
222        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
223        return
224
225class CustomInterswitchPaymentRequestWebservicePageStudent(
226    InterswitchPaymentRequestWebservicePageStudent):
227    """Request webservice view for the CollegePAY gateway
228    """
229    grok.context(ICustomStudentOnlinePayment)
230    product_id = PRODUCT_ID
231    gateway_host = HOST
232    gateway_url = URL
233    mac = MAC
234
235class CustomInterswitchPaymentVerifyWebservicePageStudent(
236    InterswitchPaymentVerifyWebservicePageStudent):
237    """Payment verify view for the CollegePAY gateway
238    """
239    grok.context(ICustomStudentOnlinePayment)
240    product_id = PRODUCT_ID
241    gateway_host = HOST
242    gateway_url = URL
243    mac = MAC
244
245class CustomInterswitchPaymentRequestWebservicePageApplicant(
246    InterswitchPaymentRequestWebservicePageApplicant):
247    """Request webservice view for the CollegePAY gateway
248    """
249    grok.context(ICustomApplicantOnlinePayment)
250    product_id = PRODUCT_ID
251    gateway_host = HOST
252    gateway_url = URL
253    mac = MAC
254
255class CustomInterswitchPaymentVerifyWebservicePageApplicant(
256    InterswitchPaymentVerifyWebservicePageApplicant):
257    """Payment verify view for the CollegePAY gateway
258    """
259    grok.context(ICustomApplicantOnlinePayment)
260    product_id = PRODUCT_ID
261    gateway_host = HOST
262    gateway_url = URL
263    mac = MAC
264
265# PAYDirect
266
267from kofacustom.nigeria.interswitch.paydirectbrowser import (
268    PAYDirectPageStudent, PAYDirectPageApplicant,
269    StudentRefNumberSlip, ApplicantRefNumberSlip,
270    )
271
272from kofacustom.nigeria.interswitch.tests import (
273    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
274
275#PAYDIRECT_HOST = 'orion.interswitchng.com'
276#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
277#MERCHANT_ID = ''
278
279class CustomPAYDirectPageStudent(PAYDirectPageStudent):
280    """Inform student how to proceed
281    """
282    grok.context(ICustomStudentOnlinePayment)
283    gateway_amt = GATEWAY_AMT
284    merchant_id = MERCHANT_ID
285    gateway_url = PAYDIRECT_URL
286    gateway_host = PAYDIRECT_HOST
287    https = True
288
289class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
290    """ Inform applicant how to proceed.
291    """
292    grok.context(ICustomApplicantOnlinePayment)
293    gateway_amt = GATEWAY_AMT
294    merchant_id = MERCHANT_ID
295    gateway_url = PAYDIRECT_URL
296    gateway_host = PAYDIRECT_HOST
297    https = True
298
299class CustomStudentRefNumberSlip(StudentRefNumberSlip):
300    """Deliver a PDF slip of the context.
301    """
302    merchant_id = MERCHANT_ID
303
304class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
305    """Deliver a PDF slip of the context.
306    """
307    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.