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

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

Configure Interswitch payment.

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1## $Id: browser.py 10174 2013-05-12 07:47:09Z 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 = ''
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 in ('schoolfee', 'schoolfee_1', 'schoolfee_2'):
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            if student.current_mode.endswith('_pt'):
122                xmldict['institution_acct'] = "0321100000000046"
123                xmldict['institution_bank_id'] = "89"
124            elif student.current_mode.endswith('_sw'):
125                xmldict['institution_acct'] = "2461770000021"
126                xmldict['institution_bank_id'] = "120"
127
128        #hashargs = (
129        #    self.context.p_id +
130        #    PRODUCT_ID +
131        #    self.pay_item_id +
132        #    str(int(self.amount_auth)) +
133        #    self.site_redirect_url +
134        #    self.mac)
135        #self.hashvalue = hashlib.sha512(hashargs).hexdigest()
136
137        # Interswitch amount is not part of the xml data
138
139        if self.context.p_category in ('schoolfee', 'schoolfee_1', 'schoolfee_2'):
140            xmltext = """<payment_item_detail>
141<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
142<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" />
143<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" />
144</item_details>
145</payment_item_detail>""" % xmldict
146
147        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
148        self.context.provider_amt = provider_amt
149        self.context.gateway_amt = GATEWAY_AMT
150        return
151
152class InterswitchPaymentRequestWebservicePageStudent(
153    InterswitchPaymentRequestWebservicePageStudent):
154    """ Request webservice view for the CollegePAY gateway
155    """
156    grok.context(ICustomStudentOnlinePayment)
157    product_id = PRODUCT_ID
158    gateway_host = HOST
159    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.