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

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

Forward hash value to Interswitch payment gateway.

  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1## $Id: browser.py 12479 2015-01-16 05:52:04Z 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        error = self.init_update()
63        if error:
64            self.flash(error, type='danger')
65            self.redirect(self.url(self.context, '@@index'))
66            return
67        student = self.student
68        xmldict = self.xmldict
69        # Provider data
70        xmldict['detail_ref'] = self.context.p_id
71        xmldict['provider_acct'] = PROVIDER_ACCT
72        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
73        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
74        # Institution data
75        xmldict['institution_acct'] = '00000000'
76        xmldict['institution_bank_id'] = '00'
77        xmldict['institution_amt'] = '0.0'
78        provider_amt = 0.0
79        self.pay_item_id = '0000'
80        xmldict['provider_amt'] = 100 * provider_amt
81        xmldict['institution_item_name'] = self.category
82        xmldict['institution_name'] = INSTITUTION_NAME
83        xmldict['institution_amt'] = 100 * (
84            self.context.amount_auth - provider_amt - GATEWAY_AMT)
85        # Interswitch amount is not part of the xml data
86        if provider_amt == 0:
87            xmltext = """<payment_item_detail>
88<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
89<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" />
90</item_details>
91</payment_item_detail>""" % xmldict
92        else:
93            xmltext = """<payment_item_detail>
94<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
95<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" />
96<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" />
97</item_details>
98</payment_item_detail>""" % xmldict
99        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
100        self.context.provider_amt = provider_amt
101        self.context.gateway_amt = GATEWAY_AMT
102
103        hashargs = (
104            self.context.p_id +
105            PRODUCT_ID +
106            self.pay_item_id +
107            str(int(self.amount_auth)) +
108            self.site_redirect_url +
109            self.mac)
110        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
111        return
112
113class CustomInterswitchPageApplicant(InterswitchPageApplicant):
114    """ View which sends a POST request to the Interswitch
115    CollegePAY payment gateway.
116    """
117    grok.context(ICustomApplicantOnlinePayment)
118    action = POST_ACTION
119    site_name = SITE_NAME
120    currency = CURRENCY
121    pay_item_id = '0000'
122    product_id = PRODUCT_ID
123    mac = ''
124
125    def update(self):
126        super(CustomInterswitchPageApplicant, self).update()
127        xmldict = {}
128        provider_amt = 400.0
129        xmldict['institution_acct'] = '00000000000'
130        xmldict['institution_bank_id'] = '00'
131        xmldict['detail_ref'] = self.context.p_id
132        xmldict['provider_amt'] = 100 * provider_amt
133        xmldict['provider_acct'] = PROVIDER_ACCT
134        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
135        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
136        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
137        xmldict['institution_item_name'] = self.context.p_category
138        xmldict['institution_name'] = INSTITUTION_NAME
139        # Interswitch amount is not part of the xml data
140        xmltext = """<payment_item_detail>
141<item_details detail_ref="%(detail_ref)s" college="%(institution_name)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        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
147        self.context.provider_amt = provider_amt
148        self.context.gateway_amt = GATEWAY_AMT
149
150        hashargs = (
151            self.context.p_id +
152            PRODUCT_ID +
153            self.pay_item_id +
154            str(int(self.amount_auth)) +
155            self.site_redirect_url +
156            self.mac)
157        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
158        return
159
160class CustomInterswitchPaymentRequestWebservicePageStudent(
161    InterswitchPaymentRequestWebservicePageStudent):
162    """ Request webservice view for the CollegePAY gateway
163    """
164    grok.context(ICustomStudentOnlinePayment)
165    product_id = PRODUCT_ID
166    gateway_host = HOST
167    gateway_url = URL
168    https = HTTPS
169
170class CustomInterswitchPaymentRequestWebservicePageApplicant(
171    InterswitchPaymentRequestWebservicePageApplicant):
172    """ Request webservice view for the CollegePAY gateway
173    """
174    grok.context(ICustomApplicantOnlinePayment)
175    product_id = PRODUCT_ID
176    gateway_host = HOST
177    gateway_url = URL
178    https = HTTPS
Note: See TracBrowser for help on using the repository browser.