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

Last change on this file since 16735 was 16735, checked in by Henrik Bettermann, 3 years ago

Surcharge is different on test server.

  • Property svn:keywords set to Id
File size: 10.8 KB
Line 
1## $Id: browser.py 16735 2021-12-03 13:45:46Z 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 = '6207' # 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 = 300.0
41MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch
42
43#POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
44POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
45#HOST = 'webpay.interswitchng.com'
46HOST = 'sandbox.interswitchng.com'
47#URL = '/paydirect/api/v1/gettransaction.json'
48URL = '/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        if not module_activated(
67            self.context.student.current_session, self.context):
68            self.flash(_('Forbidden'), type='danger')
69            self.redirect(self.url(self.context, '@@index'))
70            return
71        error = self.init_update()
72        if error:
73            self.flash(error, type='danger')
74            self.redirect(self.url(self.context, '@@index'))
75            return
76        # Already now it becomes an Interswitch payment. We set the net amount
77        # and add the gateway amount.
78        if not self.context.r_company:
79            self.context.net_amt = self.context.amount_auth
80            self.context.amount_auth += self.gateway_amt
81            self.context.gateway_amt = self.gateway_amt
82            self.context.r_company = u'interswitch'
83        student = self.student
84        xmldict = self.xmldict
85        # Provider data
86        xmldict['detail_ref'] = self.context.p_id
87        xmldict['provider_acct'] = PROVIDER_ACCT
88        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
89        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
90        # Institution data
91        xmldict['institution_acct'] = '1216063205'
92        xmldict['institution_bank_id'] = '117'
93        provider_amt = 0.0
94        self.pay_item_id = '101' # must be provided by Interswitch
95        xmldict['provider_amt'] = 100 * provider_amt
96        xmldict['institution_item_name'] = self.context.category
97        xmldict['institution_name'] = INSTITUTION_NAME
98        xmldict['institution_amt'] = 100 * self.context.net_amt
99        if not self.context.provider_amt:
100            self.context.provider_amt = provider_amt
101            self.context.amount_auth += provider_amt
102        if provider_amt == 0:
103            xmltext = """<payment_item_detail>
104<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
105<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" />
106</item_details>
107</payment_item_detail>""" % xmldict
108        else:
109            xmltext = """<payment_item_detail>
110<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
111<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" />
112<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" />
113</item_details>
114</payment_item_detail>""" % xmldict
115        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
116        self.context.provider_amt = provider_amt
117        self.amount_auth = int(100 * self.context.amount_auth)
118        hashargs = (
119            self.context.p_id +
120            PRODUCT_ID +
121            self.pay_item_id +
122            str(int(self.amount_auth)) +
123            self.site_redirect_url +
124            self.mac)
125        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
126        return
127
128class CustomInterswitchPageApplicant(InterswitchPageApplicant):
129    """ View which sends a POST request to the Interswitch
130    CollegePAY payment gateway.
131    """
132    grok.context(ICustomApplicantOnlinePayment)
133    action = POST_ACTION
134    site_name = SITE_NAME
135    currency = CURRENCY
136    pay_item_id = '101' # must be provided by Interswitch
137    product_id = PRODUCT_ID
138    mac = MAC
139    gateway_amt = GATEWAY_AMT
140
141    def update(self):
142        if not module_activated(
143            self.context.__parent__.__parent__.year, self.context):
144            self.flash(_('Forbidden'), type='danger')
145            self.redirect(self.url(self.context, '@@index'))
146            return
147        error = self.init_update()
148        if error:
149            self.flash(error, type='danger')
150            self.redirect(self.url(self.context, '@@index'))
151            return
152        # Already now it becomes an Interswitch payment. We set the net amount
153        # and add the gateway amount.
154        if not self.context.r_company:
155            self.context.net_amt = self.context.amount_auth
156            self.context.amount_auth += self.gateway_amt
157            self.context.gateway_amt = self.gateway_amt
158            self.context.r_company = u'interswitch'
159        xmldict = {}
160        provider_amt = 250.0
161        xmldict['institution_acct'] = '1216063205'
162        xmldict['institution_bank_id'] = '117'
163        xmldict['detail_ref'] = self.context.p_id
164        xmldict['provider_amt'] = 100 * provider_amt
165        xmldict['provider_acct'] = PROVIDER_ACCT
166        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
167        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
168        xmldict['institution_item_name'] = self.context.category
169        xmldict['institution_name'] = INSTITUTION_NAME
170        xmldict['institution_amt'] = 100 * self.context.net_amt
171        if not self.context.provider_amt:
172            self.context.provider_amt = provider_amt
173            self.context.amount_auth += provider_amt
174        xmltext = """<payment_item_detail>
175<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
176<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" />
177<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" />
178</item_details>
179</payment_item_detail>""" % xmldict
180        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
181        self.amount_auth = int(100 * self.context.amount_auth)
182        hashargs = (
183            self.context.p_id +
184            PRODUCT_ID +
185            self.pay_item_id +
186            str(int(self.amount_auth)) +
187            self.site_redirect_url +
188            self.mac)
189        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
190        return
191
192class CustomInterswitchPaymentRequestWebservicePageStudent(
193    InterswitchPaymentRequestWebservicePageStudent):
194    """Request webservice view for the CollegePAY gateway
195    """
196    grok.context(ICustomStudentOnlinePayment)
197    product_id = PRODUCT_ID
198    gateway_host = HOST
199    gateway_url = URL
200    mac = MAC
201
202class CustomInterswitchPaymentVerifyWebservicePageStudent(
203    InterswitchPaymentVerifyWebservicePageStudent):
204    """Payment verify view for the CollegePAY gateway
205    """
206    grok.context(ICustomStudentOnlinePayment)
207    product_id = PRODUCT_ID
208    gateway_host = HOST
209    gateway_url = URL
210    mac = MAC
211
212class CustomInterswitchPaymentRequestWebservicePageApplicant(
213    InterswitchPaymentRequestWebservicePageApplicant):
214    """Request webservice view for the CollegePAY gateway
215    """
216    grok.context(ICustomApplicantOnlinePayment)
217    product_id = PRODUCT_ID
218    gateway_host = HOST
219    gateway_url = URL
220    mac = MAC
221
222class CustomInterswitchPaymentVerifyWebservicePageApplicant(
223    InterswitchPaymentVerifyWebservicePageApplicant):
224    """Payment verify view for the CollegePAY gateway
225    """
226    grok.context(ICustomApplicantOnlinePayment)
227    product_id = PRODUCT_ID
228    gateway_host = HOST
229    gateway_url = URL
230    mac = MAC
231
232# PAYDirect
233
234from kofacustom.nigeria.interswitch.paydirectbrowser import (
235    PAYDirectPageStudent, PAYDirectPageApplicant,
236    StudentRefNumberSlip, ApplicantRefNumberSlip,
237    )
238
239from kofacustom.nigeria.interswitch.tests import (
240    PAYDIRECT_URL, PAYDIRECT_HOST, MERCHANT_ID)
241
242#PAYDIRECT_HOST = 'orion.interswitchng.com'
243#PAYDIRECT_URL = '/bookonhold/bookonhold.asmx'
244#MERCHANT_ID = ''
245
246class CustomPAYDirectPageStudent(PAYDirectPageStudent):
247    """Inform student how to proceed
248    """
249    grok.context(ICustomStudentOnlinePayment)
250    gateway_amt = GATEWAY_AMT
251    merchant_id = MERCHANT_ID
252    gateway_url = PAYDIRECT_URL
253    gateway_host = PAYDIRECT_HOST
254    https = True
255
256class CustomPAYDirectPageApplicant(PAYDirectPageApplicant):
257    """ Inform applicant how to proceed.
258    """
259    grok.context(ICustomApplicantOnlinePayment)
260    gateway_amt = GATEWAY_AMT
261    merchant_id = MERCHANT_ID
262    gateway_url = PAYDIRECT_URL
263    gateway_host = PAYDIRECT_HOST
264    https = True
265
266class CustomStudentRefNumberSlip(StudentRefNumberSlip):
267    """Deliver a PDF slip of the context.
268    """
269    merchant_id = MERCHANT_ID
270
271class CustomApplicantRefNumberSlip(ApplicantRefNumberSlip):
272    """Deliver a PDF slip of the context.
273    """
274    merchant_id = MERCHANT_ID
Note: See TracBrowser for help on using the repository browser.