source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser.py @ 10009

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

Changes according to r9775.

Use classes defined in kofacustom.nigeria.

  • Property svn:keywords set to Id
File size: 8.3 KB
RevLine 
[7894]1## $Id: browser.py 9789 2012-12-07 16:37:15Z 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
[9392]19import hashlib
[7894]20import grok
[9464]21from zope.interface import Interface
22from zope.component import getUtility, queryAdapter
[9789]23from kofacustom.nigeria.interswitch.browser import (
24    InterswitchPaymentRequestWebservicePageStudent
25    )
[7894]26from waeup.kofa.browser.layout import KofaPage, UtilityView
[9751]27from waeup.kofa.interfaces import IKofaUtils
[8281]28from waeup.kofa.utils.helpers import to_timezone
[9347]29from waeup.kwarapoly.students.interfaces import ICustomStudentOnlinePayment
30from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment
31from waeup.kwarapoly.interfaces import MessageFactory as _
[7894]32
[9487]33PRODUCT_ID = '3930'
[9347]34SITE_NAME = 'kwarapoly-kofa.waeup.org'
[9387]35PROVIDER_ACCT = '1010764827'
36PROVIDER_BANK_ID = '117'
[8263]37PROVIDER_ITEM_NAME = 'BT Education'
[9347]38INSTITUTION_NAME = 'KwaraPoly'
[7894]39CURRENCY = '566'
[9789]40GATEWAY_AMT = 300.0
[8401]41#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
[8293]42#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
[9392]43
[9487]44POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
45#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[7894]46
[9487]47HOST = 'webpay.interswitchng.com'
48#HOST = 'testwebpay.interswitchng.com'
[9392]49
[9487]50URL = '/paydirect/services/TransactionQueryWs.asmx'
51#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
[7898]52httplib.HTTPConnection.debuglevel = 0
53
[9464]54def interswitch_img_url(view):
55    static = view.static
56    if static is None or static.get(
57        'interswitch_verve_mastercard.gif', None) is None:
58        static = queryAdapter(
[9751]59            view.request, Interface, name='waeup.kwarapoly.interswitch')
[9464]60    return static['interswitch_verve_mastercard.gif']()
61
[8256]62class InterswitchPageStudent(KofaPage):
[7894]63    """ View which sends a POST request to the Interswitch
64    CollegePAY payment gateway.
65    """
[8255]66    grok.context(ICustomStudentOnlinePayment)
[7894]67    grok.name('goto_interswitch')
[8256]68    grok.template('student_goto_interswitch')
[7894]69    grok.require('waeup.payStudent')
70    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
71    submit_button = _('Submit')
72    action = POST_ACTION
73    site_name = SITE_NAME
74    currency = CURRENCY
75    product_id = PRODUCT_ID
[9487]76    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
[7894]77
[9464]78    def interswitch_img_url(self):
79        return interswitch_img_url(self)
80
[7894]81    def update(self):
[8256]82        #if self.context.p_state != 'unpaid':
83        if self.context.p_state == 'paid':
[7894]84            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
85            self.redirect(self.url(self.context, '@@index'))
86            return
[8256]87
[8745]88        student = self.student = self.context.student
89        certificate = getattr(student['studycourse'],'certificate',None)
[8276]90        self.amount_auth = 100 * self.context.amount_auth
[7894]91        xmldict = {}
92        if certificate is not None:
93            xmldict['department'] = certificate.__parent__.__parent__.code
94            xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code
95        else:
96            xmldict['department'] = None
97            xmldict['faculty'] = None
[9408]98        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
[8281]99        tz = getUtility(IKofaUtils).tzinfo
100        self.local_date_time = to_timezone(
101            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
[8256]102        self.site_redirect_url = self.url(self.context, 'request_webservice')
[8263]103        # Provider data
104        xmldict['detail_ref'] = self.context.p_id
105        xmldict['provider_acct'] = PROVIDER_ACCT
106        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
107        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
108        # Institution data
[9616]109        xmldict['institution_acct'] = "0000000000000"
110        xmldict['institution_bank_id'] = '0'
111        xmldict['institution_item_name'] = self.category
[8263]112        xmldict['institution_name'] = INSTITUTION_NAME
[9616]113        self.pay_item_id = '000'
[9737]114        if self.context.p_category == 'schoolfee':
[9789]115            provider_amt = 1200.0
116            xmldict['provider_amt'] = 100 * provider_amt
[9616]117            self.pay_item_id = '101'
[9789]118            dalash_amt = 1800.0
119            xmldict['dalash_amt'] = 100 * dalash_amt
120            xmldict['institution_amt'] = 100 * (
121                self.context.amount_auth - provider_amt -
122                GATEWAY_AMT - dalash_amt)
[9616]123            if xmldict['faculty'] in ('CPGS',):
124                xmldict['institution_acct'] = "1771180233"
125                xmldict['institution_bank_id'] = '120'
126            elif xmldict['faculty'] in ('IBAS',):
127                xmldict['institution_acct'] = "0006772436"
128                xmldict['institution_bank_id'] = '121'
129            elif xmldict['faculty'] in ('IETS',):
130                xmldict['institution_acct'] = "0106259811"
131                xmldict['institution_bank_id'] = '10'
132            elif xmldict['faculty'] in ('IFMS',):
133                xmldict['institution_acct'] = "2013910271"
134                xmldict['institution_bank_id'] = '8'
135            elif xmldict['faculty'] in ('ITCH',):
136                #acct. number changed from Zenith to FBN by gbenga Nov. 11, 2012
137                xmldict['institution_acct'] = "2013910271"
138                xmldict['institution_bank_id'] = '8'
[9392]139
[9617]140        elif 'maintenance' in self.context.p_category:
[9626]141            self.pay_item_id = '102'
[9617]142            xmldict['institution_acct'] = "0039050937"
143            xmldict['institution_bank_id'] = '31'
[9789]144            xmldict['institution_amt'] = 100 * (
145                self.context.amount_auth - GATEWAY_AMT)
146            dalash_amt = 0.0
147            provider_amt = 0.0
[9617]148
[9392]149        hashargs = (
150            self.context.p_id +
151            PRODUCT_ID +
152            self.pay_item_id +
153            str(int(self.amount_auth)) +
154            self.site_redirect_url +
155            self.mac)
156        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
157
[8263]158        # Interswitch amount is not part of the xml data
[9617]159
[9789]160        if self.context.p_category == 'schoolfee':
[9617]161            xmltext = """<payment_item_detail>
[8263]162<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
163<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" />
[9789]164<item_detail item_id="2" item_name="Dalash" item_amt="%(dalash_amt)d" bank_id="117" acct_num="1013196791" />
[9129]165<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
[8263]166</item_details>
167</payment_item_detail>""" % xmldict
[9617]168
169        elif 'maintenance' in self.context.p_category:
170            xmltext = """<payment_item_detail>
171<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
172<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" />
173</item_details>
174</payment_item_detail>""" % xmldict
175
[8263]176        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9789]177        self.context.provider_amt = provider_amt
178        self.context.gateway_amt = GATEWAY_AMT
179        self.context.thirdparty_amt = dalash_amt
[7894]180        return
181
[9789]182class InterswitchPaymentRequestWebservicePageStudent(
183    InterswitchPaymentRequestWebservicePageStudent):
[7919]184    """ Request webservice view for the CollegePAY gateway
185    """
[8255]186    grok.context(ICustomStudentOnlinePayment)
[9789]187    product_id = PRODUCT_ID
188    gateway_host = HOST
189    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.