source: main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/browser.py @ 14212

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

New single account configuration.

  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1## $Id: browser.py 13752 2016-02-29 12:33:05Z 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 grok
20from kofacustom.nigeria.interswitch.browser import (
21    InterswitchPaymentRequestWebservicePageApplicant,
22    InterswitchPaymentRequestWebservicePageStudent,
23    InterswitchPaymentVerifyWebservicePageApplicant,
24    InterswitchPaymentVerifyWebservicePageStudent,
25    InterswitchPageStudent, InterswitchPageApplicant,
26    )
27from waeup.fceokene.students.interfaces import ICustomStudentOnlinePayment
28from waeup.fceokene.applicants.interfaces import ICustomApplicantOnlinePayment
29from waeup.fceokene.interfaces import MessageFactory as _
30
31PRODUCT_ID = '83'
32SITE_NAME = 'fceokene-kofa.waeup.org'
33PROVIDER_ACCT = '0026781725'
34PROVIDER_BANK_ID = '31'
35PROVIDER_ITEM_NAME = 'BT Education'
36INSTITUTION_NAME = 'FCEOkene'
37INSTITUTION_ACCT = '2003670143'
38INSTITUTION_BANK_ID = '8'
39CURRENCY = '566'
40GATEWAY_AMT = 150.0
41#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
42#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
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'
48URL = '/paydirect/services/TransactionQueryWs.asmx'
49#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
50httplib.HTTPConnection.debuglevel = 0
51
52class CustomInterswitchPageStudent(InterswitchPageStudent):
53    """ View which sends a POST request to the Interswitch
54    CollegePAY payment gateway.
55    """
56    grok.context(ICustomStudentOnlinePayment)
57    action = POST_ACTION
58    site_name = SITE_NAME
59    currency = CURRENCY
60    pay_item_id = ''
61    product_id = PRODUCT_ID
62
63    def update(self):
64        error = self.init_update()
65        if error:
66            self.flash(error, type='danger')
67            self.redirect(self.url(self.context, '@@index'))
68            return
69        student = self.student
70        xmldict = self.xmldict
71        # Provider data
72        provider_amt = 1600.0
73        xmldict['detail_ref'] = self.context.p_id
74        xmldict['provider_acct'] = PROVIDER_ACCT
75        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
76        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
77        xmldict['provider_amt'] = 100 * provider_amt
78        # Institution data
79        xmldict['institution_acct'] = INSTITUTION_ACCT
80        xmldict['institution_bank_id'] = INSTITUTION_BANK_ID
81        xmldict['institution_item_name'] = self.category
82        xmldict['institution_name'] = INSTITUTION_NAME
83        if self.context.p_category in ('schoolfee', 'third_semester'):
84            self.pay_item_id = '8302'
85        elif 'maintenance' in self.context.p_category:
86            provider_amt = 0.0
87            self.pay_item_id = '8300'
88        elif self.context.p_category == 'clearance':
89            provider_amt = 0.0
90            self.pay_item_id = '8304'
91        xmldict['institution_amt'] = 100 * (
92            self.context.amount_auth - GATEWAY_AMT - provider_amt)
93        if provider_amt:
94            xmltext = """<payment_item_detail>
95<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
96<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" />
97<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" />
98</item_details>
99</payment_item_detail>""" % xmldict
100        else:
101            xmltext = """<payment_item_detail>
102<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
103<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" />
104</item_details>
105</payment_item_detail>""" % xmldict
106
107        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
108        self.context.provider_amt = provider_amt
109        self.context.gateway_amt = GATEWAY_AMT
110        return
111
112class CustomInterswitchPageApplicant(InterswitchPageApplicant):
113    """ View which sends a POST request to the Interswitch
114    CollegePAY payment gateway.
115    """
116    grok.context(ICustomApplicantOnlinePayment)
117    action = POST_ACTION
118    site_name = SITE_NAME
119    currency = CURRENCY
120    pay_item_id = '8303'
121    product_id = PRODUCT_ID
122
123    def update(self):
124        error = self.init_update()
125        if error:
126            self.flash(error, type='danger')
127            self.redirect(self.url(self.context, '@@index'))
128            return
129        xmldict = {}
130        # Provider data
131        provider_amt = 500.0
132        xmldict['detail_ref'] = self.context.p_id
133        xmldict['provider_amt'] = 100 * provider_amt
134        xmldict['provider_acct'] = PROVIDER_ACCT
135        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
136        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
137        # Institution data
138        xmldict['institution_acct'] = INSTITUTION_ACCT
139        xmldict['institution_bank_id'] = INSTITUTION_BANK_ID
140        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
141            provider_amt - GATEWAY_AMT)
142        xmldict['institution_item_name'] = self.context.p_category
143        xmldict['institution_name'] = INSTITUTION_NAME
144        # Interswitch amount is not part of the xml data
145        xmltext = """<payment_item_detail>
146<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
147<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" />
148<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" />
149</item_details>
150</payment_item_detail>""" % xmldict
151        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
152        self.context.provider_amt = provider_amt
153        self.context.gateway_amt = GATEWAY_AMT
154        return
155
156
157class CustomInterswitchPaymentRequestWebservicePageStudent(
158    InterswitchPaymentRequestWebservicePageStudent):
159    """Request webservice view for the CollegePAY gateway
160    """
161    grok.context(ICustomStudentOnlinePayment)
162    product_id = PRODUCT_ID
163    gateway_host = HOST
164    gateway_url = URL
165
166class CustomInterswitchPaymentVerifyWebservicePageStudent(
167    InterswitchPaymentVerifyWebservicePageStudent):
168    """Payment verify view for the CollegePAY gateway
169    """
170    grok.context(ICustomStudentOnlinePayment)
171    product_id = PRODUCT_ID
172    gateway_host = HOST
173    gateway_url = URL
174
175class CustomInterswitchPaymentRequestWebservicePageApplicant(
176    InterswitchPaymentRequestWebservicePageApplicant):
177    """Request webservice view for the CollegePAY gateway
178    """
179    grok.context(ICustomApplicantOnlinePayment)
180    product_id = PRODUCT_ID
181    gateway_host = HOST
182    gateway_url = URL
183
184class CustomInterswitchPaymentVerifyWebservicePageApplicant(
185    InterswitchPaymentVerifyWebservicePageApplicant):
186    """Payment verify view for the CollegePAY gateway
187    """
188    grok.context(ICustomApplicantOnlinePayment)
189    product_id = PRODUCT_ID
190    gateway_host = HOST
191    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.