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

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

Configure acceptance fee.

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