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

Last change on this file since 15523 was 15271, checked in by Henrik Bettermann, 6 years ago

Enable Remita payment gateway.

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