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

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

Go live.

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