source: main/waeup.aaua/trunk/src/waeup/aaua/interswitch/browser.py @ 10151

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

Fill trunk.

  • Property svn:keywords set to Id
File size: 6.4 KB
Line 
1## $Id: browser.py 10120 2013-04-30 06:33:55Z 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 hashlib
20import grok
21from zope.interface import Interface
22from zope.component import getUtility, queryAdapter
23from kofacustom.nigeria.interswitch.browser import (
24    InterswitchPaymentRequestWebservicePageStudent
25    )
26from waeup.kofa.browser.layout import KofaPage, UtilityView
27from waeup.kofa.interfaces import IKofaUtils
28from waeup.kofa.utils.helpers import to_timezone
29from waeup.aaua.students.interfaces import ICustomStudentOnlinePayment
30from waeup.aaua.applicants.interfaces import ICustomApplicantOnlinePayment
31from waeup.aaua.interfaces import MessageFactory as _
32
33PRODUCT_ID = '105'
34SITE_NAME = 'aaua.waeup.org'
35PROVIDER_ACCT = '6012015294'
36PROVIDER_BANK_ID = '117'
37PROVIDER_ITEM_NAME = 'BT Education'
38INSTITUTION_NAME = 'AAUA'
39CURRENCY = '566'
40GATEWAY_AMT = 150.0
41#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
42#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
43
44POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
45#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
46
47HOST = 'webpay.interswitchng.com'
48#HOST = 'testwebpay.interswitchng.com'
49
50URL = '/paydirect/services/TransactionQueryWs.asmx'
51#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
52httplib.HTTPConnection.debuglevel = 0
53
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(
59            view.request, Interface, name='waeup.aaua.interswitch')
60    return static['interswitch_verve_mastercard.gif']()
61
62class InterswitchPageStudent(KofaPage):
63    """ View which sends a POST request to the Interswitch
64    CollegePAY payment gateway.
65    """
66    grok.context(ICustomStudentOnlinePayment)
67    grok.name('goto_interswitch')
68    grok.template('student_goto_interswitch')
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
76    mac = 'E6BA6CBBA9AF2871EE25C32C8D57C98895B9B001DC5B9CB2C463E2A9BDA44A3F1260C8A364F33789CDF74CB3EE7E6EF5D94F48D3AF7B727E75D97F07618DFA6D'
77
78    def interswitch_img_url(self):
79        return interswitch_img_url(self)
80
81    def update(self):
82        #if self.context.p_state != 'unpaid':
83        if self.context.p_state == 'paid':
84            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
85            self.redirect(self.url(self.context, '@@index'))
86            return
87
88        student = self.student = self.context.student
89        certificate = getattr(student['studycourse'],'certificate',None)
90        self.amount_auth = 100 * self.context.amount_auth
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
98        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
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")
102        self.site_redirect_url = self.url(self.context, 'request_webservice')
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
109        xmldict['institution_acct'] = "0000000000000"
110        xmldict['institution_bank_id'] = '0'
111        xmldict['institution_item_name'] = self.category
112        xmldict['institution_name'] = INSTITUTION_NAME
113        self.pay_item_id = '000'
114        if self.context.p_category == 'schoolfee':
115            provider_amt = 3000.0
116            xmldict['provider_amt'] = 100 * provider_amt
117            self.pay_item_id = '10500'
118            xmldict['institution_amt'] = 100 * (
119                self.context.amount_auth - provider_amt -
120                GATEWAY_AMT)
121
122        hashargs = (
123            self.context.p_id +
124            PRODUCT_ID +
125            self.pay_item_id +
126            str(int(self.amount_auth)) +
127            self.site_redirect_url +
128            self.mac)
129        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
130
131        # Interswitch amount is not part of the xml data
132
133        if self.context.p_category == 'schoolfee':
134            xmltext = """<payment_item_detail>
135<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
136<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" />
137<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" />
138</item_details>
139</payment_item_detail>""" % xmldict
140
141        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
142        self.context.provider_amt = provider_amt
143        self.context.gateway_amt = GATEWAY_AMT
144        return
145
146class InterswitchPaymentRequestWebservicePageStudent(
147    InterswitchPaymentRequestWebservicePageStudent):
148    """ Request webservice view for the CollegePAY gateway
149    """
150    grok.context(ICustomStudentOnlinePayment)
151    product_id = PRODUCT_ID
152    gateway_host = HOST
153    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.