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

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

Use base classes InterswitchPageApplicant? and InterswitchPageStudent? from kofacustom.nigeria.

  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1## $Id: browser.py 11637 2014-05-13 10:37:46Z 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 queryAdapter
23from kofacustom.nigeria.interswitch.browser import (
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPageStudent
26    )
27from waeup.aaua.students.interfaces import ICustomStudentOnlinePayment
28from waeup.aaua.applicants.interfaces import ICustomApplicantOnlinePayment
29from waeup.aaua.interfaces import MessageFactory as _
30
31PRODUCT_ID = '105'
32SITE_NAME = 'aaua.waeup.org'
33PROVIDER_ACCT = '6012015294'
34PROVIDER_BANK_ID = '117'
35PROVIDER_ITEM_NAME = 'BT Education'
36INSTITUTION_NAME = 'AAUA'
37CURRENCY = '566'
38GATEWAY_AMT = 150.0
39#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
40#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
41
42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
43#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
44
45HOST = 'webpay.interswitchng.com'
46#HOST = 'testwebpay.interswitchng.com'
47
48URL = '/paydirect/services/TransactionQueryWs.asmx'
49#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
50httplib.HTTPConnection.debuglevel = 0
51
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.aaua.interswitch')
58    return static['interswitch_verve_mastercard.gif']()
59
60class CustomInterswitchPageStudent(InterswitchPageStudent):
61    """ View which sends a POST request to the Interswitch
62    CollegePAY payment gateway.
63    """
64    grok.context(ICustomStudentOnlinePayment)
65    grok.template('student_goto_interswitch')
66    action = POST_ACTION
67    site_name = SITE_NAME
68    currency = CURRENCY
69    product_id = PRODUCT_ID
70    #mac = ''
71
72    def interswitch_img_url(self):
73        return interswitch_img_url(self)
74
75    def update(self):
76        student, certificate, xmldict = super(
77            CustomInterswitchPageStudent, self).update()
78        # Provider data
79        xmldict['detail_ref'] = self.context.p_id
80        xmldict['provider_acct'] = PROVIDER_ACCT
81        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
82        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
83        # Institution data
84        xmldict['institution_acct'] = "0000000000000"
85        xmldict['institution_bank_id'] = '0'
86        xmldict['institution_item_name'] = self.category
87        xmldict['institution_name'] = INSTITUTION_NAME
88        self.pay_item_id = '000'
89        if self.context.p_category in ('schoolfee', 'schoolfee_1', 'schoolfee_2'):
90            provider_amt = 3000.0
91            if self.context.p_category == 'schoolfee_2':
92                provider_amt = 0.0
93            xmldict['provider_amt'] = 100 * provider_amt
94            self.pay_item_id = '10500'
95            xmldict['institution_amt'] = 100 * (
96                self.context.amount_auth - provider_amt -
97                GATEWAY_AMT)
98            if student.current_mode.endswith('_pt'):
99                xmldict['institution_acct'] = "0321100000000046"
100                xmldict['institution_bank_id'] = "89"
101            elif student.current_mode.endswith('_sw'):
102                xmldict['institution_acct'] = "2461770000021"
103                xmldict['institution_bank_id'] = "120"
104
105        #hashargs = (
106        #    self.context.p_id +
107        #    PRODUCT_ID +
108        #    self.pay_item_id +
109        #    str(int(self.amount_auth)) +
110        #    self.site_redirect_url +
111        #    self.mac)
112        #self.hashvalue = hashlib.sha512(hashargs).hexdigest()
113
114        # Interswitch amount is not part of the xml data
115
116        if self.context.p_category in ('schoolfee', 'schoolfee_1'):
117            xmltext = """<payment_item_detail>
118<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
119<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" />
120<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" />
121</item_details>
122</payment_item_detail>""" % xmldict
123        elif self.context.p_category  == 'schoolfee_2':
124            xmltext = """<payment_item_detail>
125<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
126<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" />
127</item_details>
128</payment_item_detail>""" % xmldict
129        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
130        self.context.provider_amt = provider_amt
131        self.context.gateway_amt = GATEWAY_AMT
132        return
133
134class CustomInterswitchPaymentRequestWebservicePageStudent(
135    InterswitchPaymentRequestWebservicePageStudent):
136    """ Request webservice view for the CollegePAY gateway
137    """
138    grok.context(ICustomStudentOnlinePayment)
139    product_id = PRODUCT_ID
140    gateway_host = HOST
141    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.