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

Last change on this file was 13588, checked in by Henrik Bettermann, 9 years ago

Add Interswitch verification components.

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