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

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

Use init_update and samePaymentMade methods.

  • Property svn:keywords set to Id
File size: 6.1 KB
Line 
1## $Id: browser.py 11648 2014-05-14 05:26:13Z 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        error = self.init_update()
77        if error:
78            self.flash(error, type='danger')
79            self.redirect(self.url(self.context, '@@index'))
80            return
81        student = self.student
82        xmldict = self.xmldict
83        # Provider data
84        xmldict['detail_ref'] = self.context.p_id
85        xmldict['provider_acct'] = PROVIDER_ACCT
86        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
87        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
88        # Institution data
89        xmldict['institution_acct'] = "0000000000000"
90        xmldict['institution_bank_id'] = '0'
91        xmldict['institution_item_name'] = self.category
92        xmldict['institution_name'] = INSTITUTION_NAME
93        self.pay_item_id = '000'
94        if self.context.p_category in ('schoolfee', 'schoolfee_1', 'schoolfee_2'):
95            provider_amt = 3000.0
96            if self.context.p_category == 'schoolfee_2':
97                provider_amt = 0.0
98            xmldict['provider_amt'] = 100 * provider_amt
99            self.pay_item_id = '10500'
100            xmldict['institution_amt'] = 100 * (
101                self.context.amount_auth - provider_amt -
102                GATEWAY_AMT)
103            if student.current_mode.endswith('_pt'):
104                xmldict['institution_acct'] = "0321100000000046"
105                xmldict['institution_bank_id'] = "89"
106            elif student.current_mode.endswith('_sw'):
107                xmldict['institution_acct'] = "2461770000021"
108                xmldict['institution_bank_id'] = "120"
109
110        #hashargs = (
111        #    self.context.p_id +
112        #    PRODUCT_ID +
113        #    self.pay_item_id +
114        #    str(int(self.amount_auth)) +
115        #    self.site_redirect_url +
116        #    self.mac)
117        #self.hashvalue = hashlib.sha512(hashargs).hexdigest()
118
119        # Interswitch amount is not part of the xml data
120
121        if self.context.p_category in ('schoolfee', 'schoolfee_1'):
122            xmltext = """<payment_item_detail>
123<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
124<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" />
125<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" />
126</item_details>
127</payment_item_detail>""" % xmldict
128        elif self.context.p_category  == 'schoolfee_2':
129            xmltext = """<payment_item_detail>
130<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
131<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" />
132</item_details>
133</payment_item_detail>""" % xmldict
134        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
135        self.context.provider_amt = provider_amt
136        self.context.gateway_amt = GATEWAY_AMT
137        return
138
139class CustomInterswitchPaymentRequestWebservicePageStudent(
140    InterswitchPaymentRequestWebservicePageStudent):
141    """ Request webservice view for the CollegePAY gateway
142    """
143    grok.context(ICustomStudentOnlinePayment)
144    product_id = PRODUCT_ID
145    gateway_host = HOST
146    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.