source: main/kofacustom.lpng/trunk/src/kofacustom/lpng/interswitch/browser.py @ 17225

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

No fixed gateway charge.

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