source: main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py @ 13778

Last change on this file since 13778 was 13771, checked in by Henrik Bettermann, 9 years ago

Implement TSA settlement through First Bank.

  • Property svn:keywords set to Id
File size: 8.7 KB
Line 
1## $Id: browser.py 13771 2016-03-09 10:05:00Z 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 grok
20from zope.component import getUtility
21from waeup.kofa.students.interfaces import IStudentsUtils
22from kofacustom.nigeria.interswitch.browser import (
23    InterswitchPaymentRequestWebservicePageApplicant,
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
29from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
30from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment
31from waeup.uniben.interfaces import MessageFactory as _
32
33PRODUCT_ID = '57'
34SITE_NAME = 'uniben-kofa.waeup.org'
35PROVIDER_ACCT = '1010764827'
36PROVIDER_BANK_ID = '117'
37PROVIDER_ITEM_NAME = 'BT Education'
38INSTITUTION_NAME = 'Uniben'
39INSTITUTION_ACCT = '2017506430'
40INSTITUTION_BANK_ID = '8'
41CURRENCY = '566'
42GATEWAY_AMT = 150.0
43#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
44#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
45POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
46#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
47
48HOST = 'webpay.interswitchng.com'
49#HOST = 'testwebpay.interswitchng.com'
50URL = '/paydirect/services/TransactionQueryWs.asmx'
51#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
52httplib.HTTPConnection.debuglevel = 0
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
64    def update(self):
65        error = self.init_update()
66        if error:
67            self.flash(error, type='danger')
68            self.redirect(self.url(self.context, '@@index'))
69            return
70        student = self.student
71        xmldict = self.xmldict
72        # Provider data
73        xmldict['detail_ref'] = self.context.p_id
74        xmldict['provider_acct'] = PROVIDER_ACCT
75        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
76        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
77        # Institution data
78        xmldict['institution_acct'] = INSTITUTION_ACCT
79        xmldict['institution_bank_id'] = INSTITUTION_BANK_ID
80        xmldict['institution_amt'] = '0.0'
81        provider_amt = 0.0
82        self.pay_item_id = '0000'
83        if self.context.p_category == 'schoolfee':
84            if not self.context.p_item == 'Balance':
85                provider_amt = 1500.0
86            if student.current_mode.endswith('_ft'):
87                self.pay_item_id = '5700'
88            elif student.current_mode.endswith('_pt'):
89                self.pay_item_id = '5701'
90            elif student.faccode == 'JUPEB':
91                self.pay_item_id = '5718'
92        elif self.context.p_category == 'clearance':
93            self.pay_item_id = '5702'
94            provider_amt = 1500.0
95        elif self.context.p_category == 'gown':
96            self.pay_item_id = '5704'
97        elif self.context.p_category.startswith('bed_allocation'):
98            self.pay_item_id = '5716'
99        elif self.context.p_category.startswith('hostel_maintenance'):
100            self.pay_item_id = '5705'
101
102        xmldict['provider_amt'] = 100 * provider_amt
103        xmldict['institution_item_name'] = self.category
104        xmldict['institution_name'] = INSTITUTION_NAME
105        xmldict['institution_amt'] = 100 * (
106            self.context.amount_auth - provider_amt - GATEWAY_AMT)
107
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.context.gateway_amt = GATEWAY_AMT
124        return
125
126class CustomInterswitchPageApplicant(InterswitchPageApplicant):
127    """ View which sends a POST request to the Interswitch
128    CollegePAY payment gateway.
129    """
130    grok.context(ICustomApplicantOnlinePayment)
131    action = POST_ACTION
132    site_name = SITE_NAME
133    currency = CURRENCY
134    pay_item_id = '5703'
135    product_id = PRODUCT_ID
136
137    def update(self):
138        error = self.init_update()
139        if error:
140            self.flash(error, type='danger')
141            self.redirect(self.url(self.context, '@@index'))
142            return
143        xmldict = {}
144        provider_amt = 400.0
145        if self.applicant.applicant_id.startswith('cbt'):
146            provider_amt = 200.0
147        xmldict['institution_acct'] = INSTITUTION_ACCT
148        xmldict['institution_bank_id'] = INSTITUTION_BANK_ID
149        xmldict['detail_ref'] = self.context.p_id
150        xmldict['provider_amt'] = 100 * provider_amt
151        xmldict['provider_acct'] = PROVIDER_ACCT
152        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
153        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
154        xmldict['institution_amt'] = 100 * (
155            self.context.amount_auth - provider_amt - GATEWAY_AMT)
156        xmldict['institution_item_name'] = self.context.p_category
157        xmldict['institution_name'] = INSTITUTION_NAME
158        # Interswitch amount is not part of the xml data
159        xmltext = """<payment_item_detail>
160<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
161<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" />
162<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" />
163</item_details>
164</payment_item_detail>""" % xmldict
165        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
166        self.context.provider_amt = provider_amt
167        self.context.gateway_amt = GATEWAY_AMT
168        return
169
170class CustomInterswitchPaymentRequestWebservicePageStudent(
171    InterswitchPaymentRequestWebservicePageStudent):
172    """Request webservice view for the CollegePAY gateway
173    """
174    grok.context(ICustomStudentOnlinePayment)
175    product_id = PRODUCT_ID
176    gateway_host = HOST
177    gateway_url = URL
178
179class CustomInterswitchPaymentVerifyWebservicePageStudent(
180    InterswitchPaymentVerifyWebservicePageStudent):
181    """Payment verify view for the CollegePAY gateway
182    """
183    grok.context(ICustomStudentOnlinePayment)
184    product_id = PRODUCT_ID
185    gateway_host = HOST
186    gateway_url = URL
187
188class CustomInterswitchPaymentRequestWebservicePageApplicant(
189    InterswitchPaymentRequestWebservicePageApplicant):
190    """Request webservice view for the CollegePAY gateway
191    """
192    grok.context(ICustomApplicantOnlinePayment)
193    product_id = PRODUCT_ID
194    gateway_host = HOST
195    gateway_url = URL
196
197class CustomInterswitchPaymentVerifyWebservicePageApplicant(
198    InterswitchPaymentVerifyWebservicePageApplicant):
199    """Payment verify view for the CollegePAY gateway
200    """
201    grok.context(ICustomApplicantOnlinePayment)
202    product_id = PRODUCT_ID
203    gateway_host = HOST
204    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.