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

Last change on this file since 9789 was 9783, checked in by Henrik Bettermann, 12 years ago

pyflakes

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