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

Last change on this file since 9782 was 9782, checked in by Henrik Bettermann, 13 years ago

Use classes defined in kofacustom.nigeria.

Remove trash.

  • Property svn:keywords set to Id
File size: 12.1 KB
Line 
1## $Id: browser.py 9782 2012-12-07 08:23:58Z 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 kofacustom.nigeria.interswitch.helpers import (
22    query_interswitch, write_payments_log)
23from kofacustom.nigeria.interswitch.browser import (
24    InterswitchPaymentRequestWebservicePageApplicant,
25    InterswitchPaymentRequestWebservicePageStudent
26    )
27from waeup.kofa.browser.layout import KofaPage, UtilityView
28from waeup.kofa.interfaces import IKofaUtils
29from waeup.kofa.utils.helpers import to_timezone
30from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent
31from waeup.kofa.applicants.viewlets import ApprovePaymentActionButton as APABApplicant
32from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
33from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment
34from waeup.uniben.interfaces import MessageFactory as _
35
36PRODUCT_ID = '57'
37SITE_NAME = 'uniben-kofa.waeup.org'
38PROVIDER_ACCT = '1010764827'
39PROVIDER_BANK_ID = '117'
40PROVIDER_ITEM_NAME = 'BT Education'
41INSTITUTION_NAME = 'Uniben'
42CURRENCY = '566'
43GATEWAY_AMT = 150.0
44#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
45#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
46POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
47#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
48
49HOST = 'webpay.interswitchng.com'
50#HOST = 'testwebpay.interswitchng.com'
51URL = '/paydirect/services/TransactionQueryWs.asmx'
52#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
53httplib.HTTPConnection.debuglevel = 0
54
55class InterswitchPageStudent(KofaPage):
56    """ View which sends a POST request to the Interswitch
57    CollegePAY payment gateway.
58    """
59    grok.context(ICustomStudentOnlinePayment)
60    grok.name('goto_interswitch')
61    grok.template('student_goto_interswitch')
62    grok.require('waeup.payStudent')
63    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
64    submit_button = _('Submit')
65    action = POST_ACTION
66    site_name = SITE_NAME
67    currency = CURRENCY
68    product_id = PRODUCT_ID
69
70    def update(self):
71        #if self.context.p_state != 'unpaid':
72        if self.context.p_state == 'paid':
73            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
74            self.redirect(self.url(self.context, '@@index'))
75            return
76
77        student = self.student = self.context.student
78        certificate = getattr(student['studycourse'],'certificate',None)
79        self.amount_auth = 100 * self.context.amount_auth
80        xmldict = {}
81        if certificate is not None:
82            xmldict['department'] = certificate.__parent__.__parent__.code
83            xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code
84        else:
85            xmldict['department'] = None
86            xmldict['faculty'] = None
87        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
88        tz = getUtility(IKofaUtils).tzinfo
89        self.local_date_time = to_timezone(
90            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
91        self.site_redirect_url = self.url(self.context, 'request_webservice')
92        # Provider data
93        xmldict['detail_ref'] = self.context.p_id
94        xmldict['provider_acct'] = PROVIDER_ACCT
95        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
96        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
97        # Institution data
98        xmldict['institution_acct'] = '000000000000'
99        xmldict['institution_bank_id'] = '00'
100        xmldict['institution_amt'] = '0.0'
101        if self.context.p_category == 'schoolfee':
102            provider_amt = 1500.0
103            if student.current_mode.endswith('_ft'):
104                self.pay_item_id = '5700'
105                if student.current_mode in ('ug_ft','de_ft','ct_ft','ume_ft'):
106                    xmldict['institution_acct'] = '2017506430'
107                    xmldict['institution_bank_id'] = '8'
108                elif student.current_mode in ('dp_ft'):
109                    xmldict['institution_acct'] = '9201805071'
110                    xmldict['institution_bank_id'] = '17'
111                elif student.current_mode in ('pg_ft'):
112                    xmldict['institution_acct'] = '5330832799'
113                    xmldict['institution_bank_id'] = '51'
114            elif student.current_mode.endswith('_pt'):
115                self.pay_item_id = '5701'
116                if student.current_mode in ('ug_pt','de_pt','ct_pt'):
117                    xmldict['institution_acct'] = '0122009929'
118                    xmldict['institution_bank_id'] = '16'
119                elif student.current_mode in ('dp_pt'):
120                    xmldict['institution_acct'] = '9201805071'
121                    xmldict['institution_bank_id'] = '17'
122                elif student.current_mode in ('pg_pt'):
123                    xmldict['institution_acct'] = '0031716047'
124                    xmldict['institution_bank_id'] = '10'
125        elif self.context.p_category == 'clearance':
126            self.pay_item_id = '5702'
127            provider_amt = 1500.0
128            if student.current_mode == 'pg_ft':
129                xmldict['institution_acct'] = '5330832799'
130                xmldict['institution_bank_id'] = '51'
131            elif student.current_mode == 'pg_pt':
132                xmldict['institution_acct'] = '0031716047'
133                xmldict['institution_bank_id'] = '10'
134            elif student.current_mode == 'dp_pt':
135                xmldict['institution_acct'] = '9201805071'
136                xmldict['institution_bank_id'] = '17'
137            else:
138                xmldict['institution_bank_id'] = '7'
139                xmldict['institution_acct'] = '1003475516'
140        elif self.context.p_category == 'gown':
141            self.pay_item_id = '5704'
142            provider_amt = 0.0
143            xmldict['institution_bank_id'] = '7'
144            xmldict['institution_acct'] = '1016232382'
145        elif self.context.p_category.startswith('hostel_maintenance'):
146            self.pay_item_id = '5705'
147            provider_amt = 0.0
148            xmldict['institution_bank_id'] = '129'
149            xmldict['institution_acct'] = '0014414547'
150
151        xmldict['provider_amt'] = 100 * provider_amt
152        xmldict['institution_item_name'] = self.category
153        xmldict['institution_name'] = INSTITUTION_NAME
154        xmldict['institution_amt'] = 100 * (
155            self.context.amount_auth - provider_amt - GATEWAY_AMT)
156        # Interswitch amount is not part of the xml data
157        if provider_amt == 0:
158            xmltext = """<payment_item_detail>
159<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
160<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" />
161</item_details>
162</payment_item_detail>""" % xmldict
163        else:
164            xmltext = """<payment_item_detail>
165<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
166<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" />
167<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" />
168</item_details>
169</payment_item_detail>""" % xmldict
170        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
171        self.context.provider_amt = provider_amt
172        self.context.gateway_amt = GATEWAY_AMT
173        return
174
175class InterswitchPageApplicant(KofaPage):
176    """ View which sends a POST request to the Interswitch
177    CollegePAY payment gateway.
178    """
179    grok.context(ICustomApplicantOnlinePayment)
180    grok.require('waeup.payApplicant')
181    grok.template('applicant_goto_interswitch')
182    grok.name('goto_interswitch')
183    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
184    submit_button = _('Submit')
185    action = POST_ACTION
186    site_name = SITE_NAME
187    currency = CURRENCY
188    pay_item_id = '5703'
189    product_id = PRODUCT_ID
190
191    def update(self):
192        if self.context.p_state != 'unpaid':
193            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
194            self.redirect(self.url(self.context, '@@index'))
195            return
196        if self.context.__parent__.__parent__.expired \
197            and self.context.__parent__.__parent__.strict_deadline:
198            self.flash(_("Payment ticket can't be send to CollegePAY. "
199                         "Application period has expired."))
200            self.redirect(self.url(self.context, '@@index'))
201            return
202        self.applicant = self.context.__parent__
203        self.amount_auth = 100 * self.context.amount_auth
204        xmldict = {}
205        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
206        tz = getUtility(IKofaUtils).tzinfo
207        self.local_date_time = to_timezone(
208            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
209        self.site_redirect_url = self.url(self.context, 'request_webservice')
210        provider_amt = 400.0
211        if self.applicant.applicant_id.startswith('pg'):
212            xmldict['institution_acct'] = '0031716030'
213            xmldict['institution_bank_id'] = '10'
214        elif self.applicant.applicant_id.startswith('dp'):
215            xmldict['institution_acct'] = '9201805071'
216            xmldict['institution_bank_id'] = '17'
217        else:
218            xmldict['institution_acct'] = '6220032503'
219            xmldict['institution_bank_id'] = '51'
220        xmldict['detail_ref'] = self.context.p_id
221        xmldict['provider_amt'] = 100 * provider_amt
222        xmldict['provider_acct'] = PROVIDER_ACCT
223        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
224        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
225        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
226        xmldict['institution_item_name'] = self.context.p_category
227        xmldict['institution_name'] = INSTITUTION_NAME
228        # Interswitch amount is not part of the xml data
229        xmltext = """<payment_item_detail>
230<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
231<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" />
232<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" />
233</item_details>
234</payment_item_detail>""" % xmldict
235        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
236        self.context.provider_amt = provider_amt
237        self.context.gateway_amt = GATEWAY_AMT
238        return
239
240class InterswitchPaymentRequestWebservicePageStudent(
241    InterswitchPaymentRequestWebservicePageStudent):
242    """ Request webservice view for the CollegePAY gateway
243    """
244    grok.context(ICustomStudentOnlinePayment)
245    product_id = PRODUCT_ID
246    gateway_host = HOST
247    gateway_url = URL
248
249class InterswitchPaymentRequestWebservicePageApplicant(
250    InterswitchPaymentRequestWebservicePageApplicant):
251    """ Request webservice view for the CollegePAY gateway
252    """
253    grok.context(ICustomApplicantOnlinePayment)
254    product_id = PRODUCT_ID
255    gateway_host = HOST
256    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.