source: main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py @ 11831

Last change on this file since 11831 was 10434, checked in by Henrik Bettermann, 11 years ago

Change pay_item_id.

  • Property svn:keywords set to Id
File size: 14.3 KB
RevLine 
[7894]1## $Id: browser.py 10434 2013-07-22 11:31:14Z 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
[10165]20from zope.interface import Interface
21from zope.component import getUtility, queryAdapter
[9785]22from kofacustom.nigeria.interswitch.browser import (
[10165]23    InterswitchPaymentRequestWebservicePageStudent,
24    InterswitchPaymentRequestWebservicePageApplicant
[9785]25    )
26from waeup.kofa.browser.layout import KofaPage
[9285]27from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils
[8281]28from waeup.kofa.utils.helpers import to_timezone
[8619]29from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment
[10165]30from waeup.futminna.applicants.interfaces import ICustomApplicantOnlinePayment
[8619]31from waeup.futminna.interfaces import MessageFactory as _
[7894]32
[9285]33PRODUCT_ID = '117'
[8619]34SITE_NAME = 'futminna-kofa.waeup.org'
[10336]35PROVIDER_ACCT = '1010764827'
36PROVIDER_BANK_ID = '117'
[8263]37PROVIDER_ITEM_NAME = 'BT Education'
[8619]38INSTITUTION_NAME = 'FUTMinna'
[7894]39CURRENCY = '566'
[9785]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'
[8385]43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
[8293]44#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[7894]45
[8293]46HOST = 'webpay.interswitchng.com'
47#HOST = 'testwebpay.interswitchng.com'
48URL = '/paydirect/services/TransactionQueryWs.asmx'
49#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
[7898]50httplib.HTTPConnection.debuglevel = 0
51
[10165]52def interswitch_img_url(view):
53    static = view.static
54    if static is None or static.get(
55        'interswitch_verve_mastercard.gif', None) is None:
56        static = queryAdapter(
57            view.request, Interface, name='waeup.futminna.interswitch')
58    return static['interswitch_verve_mastercard.gif']()
59
[8256]60class InterswitchPageStudent(KofaPage):
[7894]61    """ View which sends a POST request to the Interswitch
62    CollegePAY payment gateway.
63    """
[8255]64    grok.context(ICustomStudentOnlinePayment)
[7894]65    grok.name('goto_interswitch')
[8256]66    grok.template('student_goto_interswitch')
[7894]67    grok.require('waeup.payStudent')
68    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
69    submit_button = _('Submit')
70    action = POST_ACTION
71    site_name = SITE_NAME
72    currency = CURRENCY
[9288]73    pay_item_id = ''
[7894]74    product_id = PRODUCT_ID
75
76    def update(self):
[8256]77        #if self.context.p_state != 'unpaid':
78        if self.context.p_state == 'paid':
[7894]79            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
80            self.redirect(self.url(self.context, '@@index'))
81            return
[8256]82
[8744]83        student = self.student = self.context.student
84        certificate = getattr(student['studycourse'],'certificate',None)
[8276]85        self.amount_auth = 100 * self.context.amount_auth
[7894]86        xmldict = {}
87        if certificate is not None:
88            xmldict['department'] = certificate.__parent__.__parent__.code
89            xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code
90        else:
91            xmldict['department'] = None
92            xmldict['faculty'] = None
[9630]93        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[
94            self.context.p_category]
[8281]95        tz = getUtility(IKofaUtils).tzinfo
96        self.local_date_time = to_timezone(
97            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
[8256]98        self.site_redirect_url = self.url(self.context, 'request_webservice')
[8263]99        # Provider data
100        xmldict['detail_ref'] = self.context.p_id
101        xmldict['provider_acct'] = PROVIDER_ACCT
102        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
103        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[9785]104        provider_amt = 1500.0
[8263]105        xmldict['provider_amt'] = 100 * provider_amt
[9285]106
[9630]107        # Institution data. Account numbers were changed to the new
108        # NUBAN 10 digit number system
[8263]109        xmldict['institution_acct'] = ''
110        xmldict['institution_bank_id'] = ''
[8957]111        xmldict['institution_acct'] = '000000000000'
112        xmldict['institution_bank_id'] = '00'
[9624]113        xmldict['institution_name'] = INSTITUTION_NAME
[9292]114       
115        if self.context.p_category == 'schoolfee':
116            xmldict['institution_amt'] = 100 * (
[9785]117                self.context.amount_auth - provider_amt - GATEWAY_AMT)
[9934]118            if self.context.student.current_mode in ('pg_ft','pgd_ft'):
[9292]119                self.pay_item_id = "11703"
120            elif self.context.student.state == CLEARED and \
121                self.context.student.current_level == 100:
122                self.pay_item_id = "11700"
123            elif self.context.student.state == CLEARED and \
124                self.context.student.current_level == 200:
125                self.pay_item_id = "11701"
126            elif self.context.student.state == CLEARED and \
127                self.context.student.current_level == 300:
128                self.pay_item_id = "11702"
129            elif self.context.student.state == RETURNING and \
130                self.context.student.current_level in (100,110):
131                self.pay_item_id = "11701"
132            elif self.context.student.state == RETURNING and \
133                self.context.student.current_level in (200,210):
134                self.pay_item_id = "11702"
135            elif self.context.student.state == RETURNING and \
136                self.context.student.current_level in (300,310):
137                self.pay_item_id = "11703"
138            elif self.context.student.state == RETURNING and \
139                self.context.student.current_level in (400,410,500,510,600):
140                self.pay_item_id = "11704"
[7894]141
[9292]142            if self.context.student.current_mode == 'jm_ft':
143                xmldict['institution_acct'] = "000000000000"
[9386]144                xmldict['institution_bank_id'] = '00'
[9292]145            elif self.context.student.current_mode == 'pg_ft':
[9630]146                xmldict['institution_acct'] = "2005910931"
[9292]147                xmldict['institution_bank_id'] = '8'
148            elif self.context.student.state == CLEARED and \
149                self.context.student.current_level == 100:
[9630]150                xmldict['institution_acct'] = "0021030851"
151                xmldict['institution_bank_id'] = '31'
[9292]152            elif self.context.student.state == CLEARED and \
153                self.context.student.current_level == 200:
[9630]154                xmldict['institution_acct'] = "0005646299"
155                xmldict['institution_bank_id'] = '47'
[9292]156            elif self.context.student.state == CLEARED and \
157                self.context.student.current_level == 300:
[9630]158                xmldict['institution_acct'] = "1010500151"
[9292]159                xmldict['institution_bank_id'] = '117'
160            elif self.context.student.state == RETURNING and \
161                self.context.student.current_level in (100,110):
[9630]162                xmldict['institution_acct'] = "0005646299"
163                xmldict['institution_bank_id'] = '47'
[9292]164            elif self.context.student.current_level in (200,210):
[9630]165                xmldict['institution_acct'] = "1010500151"
[9292]166                xmldict['institution_bank_id'] = '117'
167            elif self.context.student.current_level in (300,310):
[9630]168                xmldict['institution_acct'] = "2005910931"
[9292]169                xmldict['institution_bank_id'] = '8'
170            elif self.context.student.current_level in (400,410,500,510,600):
[9630]171                xmldict['institution_acct'] = "0027490487"
[9292]172                xmldict['institution_bank_id'] = '10'
[8256]173
[9292]174        elif self.context.p_category == 'clearance':
175            xmldict['institution_amt'] = 100 * (
[9785]176                self.context.amount_auth - GATEWAY_AMT)
[9292]177            xmldict['institution_acct'] = "1750005063"
178            xmldict['institution_bank_id'] = '120'
179            self.pay_item_id = "11706"
[9785]180            provider_amt = 0.0
[9288]181
[9410]182        elif 'maintenance' in self.context.p_category:
[9409]183            xmldict['institution_amt'] = 100 * (
[9785]184                self.context.amount_auth - GATEWAY_AMT)
[9410]185            xmldict['institution_acct'] = "2018856637"
186            xmldict['institution_bank_id'] = '8'
187            self.pay_item_id = "11705"
[9785]188            provider_amt = 0.0
[9409]189
[8263]190        # Interswitch amount is not part of the xml data
[9292]191        if self.context.p_category == 'schoolfee':
192            xmltext = """<payment_item_detail>
[9285]193<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
[9386]194<item_detail item_id="1" item_name="School Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
[8263]195<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" />
196</item_details>
197</payment_item_detail>""" % xmldict
[9409]198
[9292]199        elif self.context.p_category == 'clearance':
200            xmltext = """<payment_item_detail>
201<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
[9386]202<item_detail item_id="1" item_name="Acceptance Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
[9292]203</item_details>
204</payment_item_detail>""" % xmldict
[9409]205
206        elif 'maintenance' in self.context.p_category:
207            xmltext = """<payment_item_detail>
208<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
[9410]209<item_detail item_id="1" item_name="Hostel Maintenance Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
[9409]210</item_details>
211</payment_item_detail>""" % xmldict
212
213
[8263]214        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9785]215        self.context.provider_amt = provider_amt
216        self.context.gateway_amt = GATEWAY_AMT
[8256]217        return
218
[10165]219class InterswitchPageApplicant(KofaPage):
220    """ View which sends a POST request to the Interswitch
221    CollegePAY payment gateway.
222    """
223    grok.context(ICustomApplicantOnlinePayment)
224    grok.require('waeup.payApplicant')
225    grok.template('applicant_goto_interswitch')
226    grok.name('goto_interswitch')
227    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
228    submit_button = _('Submit')
229    action = POST_ACTION
230    site_name = SITE_NAME
231    currency = CURRENCY
[10434]232    pay_item_id = '11707'
[10165]233    product_id = PRODUCT_ID
234    #mac = ''
235
236    def interswitch_img_url(self):
237        return interswitch_img_url(self)
238
239    def update(self):
240        if self.context.p_state != 'unpaid':
241            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
242            self.redirect(self.url(self.context, '@@index'))
243            return
244        if self.context.__parent__.__parent__.expired \
245            and self.context.__parent__.__parent__.strict_deadline:
246            self.flash(_("Payment ticket can't be send to CollegePAY. "
247                         "Application period has expired."))
248            self.redirect(self.url(self.context, '@@index'))
249            return
250        self.applicant = self.context.__parent__
251        self.amount_auth = 100 * self.context.amount_auth
252        xmldict = {}
253        self.category = getUtility(
254            IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
255        tz = getUtility(IKofaUtils).tzinfo
256        self.local_date_time = to_timezone(
257            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
258        self.site_redirect_url = self.url(self.context, 'request_webservice')
259        provider_amt = 500.0
260        if self.applicant.applicant_id.startswith('pg'):
261            xmldict['institution_acct'] = '2005910931'
262            xmldict['institution_bank_id'] = '8'
263        else:
264            xmldict['institution_acct'] = '00000000000'
265            xmldict['institution_bank_id'] = '00'
266        xmldict['detail_ref'] = self.context.p_id
267        xmldict['provider_amt'] = 100 * provider_amt
268        xmldict['provider_acct'] = PROVIDER_ACCT
269        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
270        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
271        xmldict['institution_amt'] = 100 * (
272            self.context.amount_auth - provider_amt - GATEWAY_AMT)
273        xmldict['institution_item_name'] = self.context.p_category
274        xmldict['institution_name'] = INSTITUTION_NAME
275
276        #hashargs = (
277        #    self.context.p_id +
278        #    PRODUCT_ID +
279        #    self.pay_item_id +
280        #    str(int(self.amount_auth)) +
281        #    self.site_redirect_url +
282        #    self.mac)
283        #self.hashvalue = hashlib.sha512(hashargs).hexdigest()
284
285        # Interswitch amount is not part of the xml data
286        xmltext = """<payment_item_detail>
287<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
288<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" />
289<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" />
290</item_details>
291</payment_item_detail>""" % xmldict
292        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
293        self.context.provider_amt = provider_amt
294        self.context.gateway_amt = GATEWAY_AMT
295        return
296
[9785]297class InterswitchPaymentRequestWebservicePageStudent(
298    InterswitchPaymentRequestWebservicePageStudent):
[7919]299    """ Request webservice view for the CollegePAY gateway
300    """
[8255]301    grok.context(ICustomStudentOnlinePayment)
[9785]302    product_id = PRODUCT_ID
303    gateway_host = HOST
304    gateway_url = URL
[10165]305
306class InterswitchPaymentRequestWebservicePageApplicant(
307    InterswitchPaymentRequestWebservicePageApplicant):
308    """ Request webservice view for the CollegePAY gateway
309    """
310    grok.context(ICustomApplicantOnlinePayment)
311    product_id = PRODUCT_ID
312    gateway_host = HOST
313    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.