source: main/kofacustom.wdu/trunk/src/kofacustom/wdu/interswitch/browser.py @ 15284

Last change on this file since 15284 was 13592, checked in by Henrik Bettermann, 9 years ago

Add Interswitch verification components.

  • Property svn:keywords set to Id
File size: 8.4 KB
Line 
1## $Id: browser.py 13592 2016-01-11 09:17:35Z 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 waeup.kofa.interfaces import CLEARED
22from kofacustom.nigeria.interswitch.browser import (
23    InterswitchPaymentRequestWebservicePageApplicant,
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
29from kofacustom.wdu.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.wdu.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.wdu.interfaces import MessageFactory as _
32
33PRODUCT_ID = '5214'
34SITE_NAME = 'wdu.waeup.org'
35PROVIDER_ACCT = '0137712635'
36PROVIDER_BANK_ID = '10'
37PROVIDER_ITEM_NAME = 'BT Education'
38INSTITUTION_NAME = 'WDU'
39CURRENCY = '566'
40GATEWAY_AMT = 300.0
41
42#POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
44
45HOST = 'webpay.interswitchng.com'
46#HOST = 'stageserv.interswitchng.com'
47HTTPS = True
48
49URL = '/paydirect/services/TransactionQueryWs.asmx'
50#URL = '/test_paydirect/services/TransactionQueryWS.asmx'
51
52httplib.HTTPSConnection.debuglevel = 0
53
54class CustomInterswitchPageStudent(InterswitchPageStudent):
55    """ View which sends a POST request to the Interswitch
56    CollegePAY payment gateway.
57    """
58    grok.context(ICustomStudentOnlinePayment)
59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
63    mac = '2EC91A15F6A0821A06DEC31CC4EF509FDB548A1ABF76BD6FCF620A4D3F1F80D06C362D26CA56D86DC91ADA85CD99B97A6E845B44C730D5749E2B9B339FDC7AF8'
64
65    def update(self):
66        error = self.init_update()
67        if error:
68            self.flash(error, type='danger')
69            self.redirect(self.url(self.context, '@@index'))
70            return
71        student = self.student
72        xmldict = self.xmldict
73        # Provider data
74        xmldict['detail_ref'] = self.context.p_id
75        xmldict['provider_acct'] = PROVIDER_ACCT
76        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
77        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
78        xmldict['institution_acct_1'] = '4742014159'
79        xmldict['institution_bank_id_1'] = '47'
80        xmldict['institution_amt_1'] = '0.0'
81        xmldict['institution_acct_2'] = '0029688237'
82        xmldict['institution_bank_id_2'] = '11'
83        xmldict['institution_amt_2'] = '0.0'
84        provider_amt = 4000.0
85        self.pay_item_id = '101'
86        # other charges + tech fee
87        if self.context.student.state == CLEARED:
88            institution_amt_2 = 207500.0 + 1000.0
89        else :
90            institution_amt_2 = 150500.0 + 1000.0
91        xmldict['provider_amt'] = 100 * provider_amt
92        xmldict['institution_item_name'] = self.context.category
93        xmldict['institution_name'] = INSTITUTION_NAME
94        xmldict['institution_amt_1'] = 100 * (
95            self.context.amount_auth - provider_amt - GATEWAY_AMT - institution_amt_2)
96        xmldict['institution_amt_2'] = 100 * institution_amt_2
97
98        xmltext = """<payment_item_detail>
99<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
100<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id_1)s" acct_num="%(institution_acct_1)s" />
101<item_detail item_id="2" item_name="other charges and tech fee" item_amt="%(institution_amt_2)d" bank_id="%(institution_bank_id_2)s" acct_num="%(institution_acct_2)s" />
102<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
103</item_details>
104</payment_item_detail>""" % xmldict
105        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
106        self.context.provider_amt = provider_amt
107        self.context.gateway_amt = GATEWAY_AMT
108
109        hashargs = (
110            self.context.p_id +
111            PRODUCT_ID +
112            self.pay_item_id +
113            str(int(self.amount_auth)) +
114            self.site_redirect_url +
115            self.mac)
116        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
117        return
118
119
120class CustomInterswitchPageApplicant(InterswitchPageApplicant):
121    """ View which sends a POST request to the Interswitch
122    CollegePAY payment gateway.
123    """
124    grok.context(ICustomApplicantOnlinePayment)
125    action = POST_ACTION
126    site_name = SITE_NAME
127    currency = CURRENCY
128    pay_item_id = '103'
129    product_id = PRODUCT_ID
130    mac = '2EC91A15F6A0821A06DEC31CC4EF509FDB548A1ABF76BD6FCF620A4D3F1F80D06C362D26CA56D86DC91ADA85CD99B97A6E845B44C730D5749E2B9B339FDC7AF8'
131
132    def update(self):
133        error = self.init_update()
134        if error:
135            self.flash(error, type='danger')
136            self.redirect(self.url(self.context, '@@index'))
137            return
138        xmldict = {}
139        provider_amt = 500.0
140        xmldict['institution_acct'] = '0029688237'
141        xmldict['institution_bank_id'] = '11'
142        xmldict['detail_ref'] = self.context.p_id
143        xmldict['provider_amt'] = 100 * provider_amt
144        xmldict['provider_acct'] = PROVIDER_ACCT
145        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
146        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
147        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
148        xmldict['institution_item_name'] = self.context.category
149        xmldict['institution_name'] = INSTITUTION_NAME
150        # Interswitch amount is not part of the xml data
151        xmltext = """<payment_item_detail>
152<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
153<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" />
154<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" />
155</item_details>
156</payment_item_detail>""" % xmldict
157        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
158        self.context.provider_amt = provider_amt
159        self.context.gateway_amt = GATEWAY_AMT
160
161        hashargs = (
162            self.context.p_id +
163            PRODUCT_ID +
164            self.pay_item_id +
165            str(int(self.amount_auth)) +
166            self.site_redirect_url +
167            self.mac)
168        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
169        return
170
171
172class CustomInterswitchPaymentRequestWebservicePageStudent(
173    InterswitchPaymentRequestWebservicePageStudent):
174    """Request webservice view for the CollegePAY gateway
175    """
176    grok.context(ICustomStudentOnlinePayment)
177    product_id = PRODUCT_ID
178    gateway_host = HOST
179    gateway_url = URL
180
181class CustomInterswitchPaymentVerifyWebservicePageStudent(
182    InterswitchPaymentVerifyWebservicePageStudent):
183    """Payment verify view for the CollegePAY gateway
184    """
185    grok.context(ICustomStudentOnlinePayment)
186    product_id = PRODUCT_ID
187    gateway_host = HOST
188    gateway_url = URL
189
190class CustomInterswitchPaymentRequestWebservicePageApplicant(
191    InterswitchPaymentRequestWebservicePageApplicant):
192    """Request webservice view for the CollegePAY gateway
193    """
194    grok.context(ICustomApplicantOnlinePayment)
195    product_id = PRODUCT_ID
196    gateway_host = HOST
197    gateway_url = URL
198
199class CustomInterswitchPaymentVerifyWebservicePageApplicant(
200    InterswitchPaymentVerifyWebservicePageApplicant):
201    """Payment verify view for the CollegePAY gateway
202    """
203    grok.context(ICustomApplicantOnlinePayment)
204    product_id = PRODUCT_ID
205    gateway_host = HOST
206    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.