source: main/kofacustom.skeleton/trunk/src/kofacustom/skeleton/interswitch/browser.py @ 12716

Last change on this file since 12716 was 12511, checked in by Henrik Bettermann, 10 years ago

Adjust to base package.

  • Property svn:keywords set to Id
File size: 7.3 KB
Line 
1## $Id: browser.py 12511 2015-01-23 16:05:37Z 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 kofacustom.nigeria.interswitch.browser import (
22    InterswitchPaymentRequestWebservicePageApplicant,
23    InterswitchPaymentRequestWebservicePageStudent,
24    InterswitchPageStudent, InterswitchPageApplicant,
25    )
26from kofacustom.skeleton.students.interfaces import ICustomStudentOnlinePayment
27from kofacustom.skeleton.applicants.interfaces import ICustomApplicantOnlinePayment
28from kofacustom.skeleton.interfaces import MessageFactory as _
29
30PRODUCT_ID = '57'
31SITE_NAME = 'skeleton-kofa.waeup.org'
32PROVIDER_ACCT = '00000000'
33PROVIDER_BANK_ID = '00'
34PROVIDER_ITEM_NAME = 'BT Education'
35INSTITUTION_NAME = 'Skeleton'
36CURRENCY = '566'
37GATEWAY_AMT = 150.0
38#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
39#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
40POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
41#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
42
43HOST = 'webpay.interswitchng.com'
44#HOST = 'testwebpay.interswitchng.com'
45URL = '/paydirect/services/TransactionQueryWs.asmx'
46#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
47httplib.HTTPSConnection.debuglevel = 0
48HTTPS = True
49
50class CustomInterswitchPageStudent(InterswitchPageStudent):
51    """ View which sends a POST request to the Interswitch
52    CollegePAY payment gateway.
53    """
54    grok.context(ICustomStudentOnlinePayment)
55    action = POST_ACTION
56    site_name = SITE_NAME
57    currency = CURRENCY
58    product_id = PRODUCT_ID
59    mac = ''
60
61    def update(self):
62        super(CustomInterswitchPageStudent, self).update()
63        student = self.student
64        xmldict = self.xmldict
65        # Provider data
66        xmldict['detail_ref'] = self.context.p_id
67        xmldict['provider_acct'] = PROVIDER_ACCT
68        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
69        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
70        # Institution data
71        xmldict['institution_acct'] = '00000000'
72        xmldict['institution_bank_id'] = '00'
73        xmldict['institution_amt'] = '0.0'
74        provider_amt = 0.0
75        self.pay_item_id = '0000'
76        xmldict['provider_amt'] = 100 * provider_amt
77        xmldict['institution_item_name'] = self.context.category
78        xmldict['institution_name'] = INSTITUTION_NAME
79        xmldict['institution_amt'] = 100 * (
80            self.context.amount_auth - provider_amt - GATEWAY_AMT)
81        # Interswitch amount is not part of the xml data
82        if provider_amt == 0:
83            xmltext = """<payment_item_detail>
84<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
85<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" />
86</item_details>
87</payment_item_detail>""" % xmldict
88        else:
89            xmltext = """<payment_item_detail>
90<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
91<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" />
92<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" />
93</item_details>
94</payment_item_detail>""" % xmldict
95        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
96        self.context.provider_amt = provider_amt
97        self.context.gateway_amt = GATEWAY_AMT
98
99        hashargs = (
100            self.context.p_id +
101            PRODUCT_ID +
102            self.pay_item_id +
103            str(int(self.amount_auth)) +
104            self.site_redirect_url +
105            self.mac)
106        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
107        return
108
109class CustomInterswitchPageApplicant(InterswitchPageApplicant):
110    """ View which sends a POST request to the Interswitch
111    CollegePAY payment gateway.
112    """
113    grok.context(ICustomApplicantOnlinePayment)
114    action = POST_ACTION
115    site_name = SITE_NAME
116    currency = CURRENCY
117    pay_item_id = '0000'
118    product_id = PRODUCT_ID
119    mac = ''
120
121    def update(self):
122        super(CustomInterswitchPageApplicant, self).update()
123        xmldict = {}
124        provider_amt = 400.0
125        xmldict['institution_acct'] = '00000000000'
126        xmldict['institution_bank_id'] = '00'
127        xmldict['detail_ref'] = self.context.p_id
128        xmldict['provider_amt'] = 100 * provider_amt
129        xmldict['provider_acct'] = PROVIDER_ACCT
130        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
131        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
132        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
133        xmldict['institution_item_name'] = self.context.category
134        xmldict['institution_name'] = INSTITUTION_NAME
135        # Interswitch amount is not part of the xml data
136        xmltext = """<payment_item_detail>
137<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
138<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" />
139<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" />
140</item_details>
141</payment_item_detail>""" % xmldict
142        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
143        self.context.provider_amt = provider_amt
144        self.context.gateway_amt = GATEWAY_AMT
145
146        hashargs = (
147            self.context.p_id +
148            PRODUCT_ID +
149            self.pay_item_id +
150            str(int(self.amount_auth)) +
151            self.site_redirect_url +
152            self.mac)
153        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
154        return
155
156class CustomInterswitchPaymentRequestWebservicePageStudent(
157    InterswitchPaymentRequestWebservicePageStudent):
158    """ Request webservice view for the CollegePAY gateway
159    """
160    grok.context(ICustomStudentOnlinePayment)
161    product_id = PRODUCT_ID
162    gateway_host = HOST
163    gateway_url = URL
164    https = HTTPS
165
166class CustomInterswitchPaymentRequestWebservicePageApplicant(
167    InterswitchPaymentRequestWebservicePageApplicant):
168    """ Request webservice view for the CollegePAY gateway
169    """
170    grok.context(ICustomApplicantOnlinePayment)
171    product_id = PRODUCT_ID
172    gateway_host = HOST
173    gateway_url = URL
174    https = HTTPS
Note: See TracBrowser for help on using the repository browser.