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

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

Add Interswitch verification components.

  • Property svn:keywords set to Id
File size: 10.1 KB
Line 
1## $Id: browser.py 13589 2016-01-11 09:15:08Z 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'
37CURRENCY = '566'
38GATEWAY_AMT = 150.0
39#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
40#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
41POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
42#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
43
44HOST = 'webpay.interswitchng.com'
45#HOST = 'testwebpay.interswitchng.com'
46URL = '/paydirect/services/TransactionQueryWs.asmx'
47#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
48httplib.HTTPConnection.debuglevel = 0
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    pay_item_id = ''
59    product_id = PRODUCT_ID
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        provider_amt = 1600.0
71        xmldict['detail_ref'] = self.context.p_id
72        xmldict['provider_acct'] = PROVIDER_ACCT
73        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
74        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
75        xmldict['provider_amt'] = 100 * provider_amt
76        # Institution data
77        fceokene_split_amt = 1400.0
78        xmldict['fceokene_acct'] = "0000000000000"
79        xmldict['institution_bank_id'] = '0'
80        xmldict['institution_item_name'] = self.category
81        xmldict['institution_name'] = INSTITUTION_NAME
82        if self.context.p_category in ('schoolfee', 'third_semester'):
83            self.pay_item_id = '8302'
84            if student.current_mode in ('ct_ft',):
85                xmldict['institution_acct'] = "1012044039"
86                xmldict['institution_bank_id'] = '117'
87            if student.current_mode in ('nce_sw','prence',):
88                xmldict['institution_acct'] = "1013780934"
89                xmldict['institution_bank_id'] = '117'
90            elif student.current_mode in ('nce_ft',) and \
91                student['studycourse'].current_verdict == 'O':
92                xmldict['institution_acct'] = "1013780934"
93                xmldict['institution_bank_id'] = '117'
94            elif student.current_mode in ('nce_ft',):
95                xmldict['institution_acct'] = "1013780934"
96                xmldict['institution_bank_id'] = '117'
97            elif student.current_mode in ('pd_ft',):
98                xmldict['institution_acct'] = "1013780934"
99                xmldict['institution_bank_id'] = '117'
100            #undergraduate schoolfee added
101            elif student.current_mode in ('ug_ft',):
102                xmldict['institution_acct'] = "2010952698"
103                xmldict['institution_bank_id'] = '8'
104            xmldict['fceokene_split'] = 100 * fceokene_split_amt
105            xmldict['institution_amt'] = 100 * (
106                self.context.amount_auth - provider_amt -
107                GATEWAY_AMT - fceokene_split_amt)
108        elif 'maintenance' in self.context.p_category:
109            fceokene_split_amt = 0.0
110            provider_amt = 0.0
111            self.pay_item_id = '8300'
112            xmldict['institution_amt'] = 100 * (
113                self.context.amount_auth - GATEWAY_AMT)
114            xmldict['institution_acct'] = "1013780934"
115            xmldict['institution_bank_id'] = '117'
116        elif self.context.p_category == 'clearance':
117            fceokene_split_amt = 0.0
118            provider_amt = 0.0
119            self.pay_item_id = '8304'
120            xmldict['institution_amt'] = 100 * (
121                self.context.amount_auth - GATEWAY_AMT)
122            xmldict['institution_acct'] = "2010952698"
123            xmldict['institution_bank_id'] = '8'
124
125        # Interswitch amount is not part of the xml data
126        if self.context.p_category in ('schoolfee', 'third_semester'):
127            xmltext = """<payment_item_detail>
128<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
129<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" />
130<item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1013780934" />
131<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" />
132</item_details>
133</payment_item_detail>""" % xmldict
134
135        else:
136            xmltext = """<payment_item_detail>
137<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)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_details>
140</payment_item_detail>""" % xmldict
141
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        self.context.thirdparty_amt = fceokene_split_amt
146        return
147
148class CustomInterswitchPageApplicant(InterswitchPageApplicant):
149    """ View which sends a POST request to the Interswitch
150    CollegePAY payment gateway.
151    """
152    grok.context(ICustomApplicantOnlinePayment)
153    action = POST_ACTION
154    site_name = SITE_NAME
155    currency = CURRENCY
156    pay_item_id = '8303'
157    product_id = PRODUCT_ID
158
159    def update(self):
160        error = self.init_update()
161        if error:
162            self.flash(error, type='danger')
163            self.redirect(self.url(self.context, '@@index'))
164            return
165        xmldict = {}
166        # Provider data
167        provider_amt = 500.0
168        xmldict['detail_ref'] = self.context.p_id
169        xmldict['provider_amt'] = 100 * provider_amt
170        xmldict['provider_acct'] = PROVIDER_ACCT
171        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
172        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
173        # Institution data
174        if getattr(
175            self.applicant.__parent__, 'prefix', None) in ('pude', 'putme'):
176            xmldict['institution_acct'] = '2010952698'
177            xmldict['institution_bank_id'] = '8'
178        else:
179            xmldict['institution_acct'] = '1013780934'
180            xmldict['institution_bank_id'] = '117'
181        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
182            provider_amt - GATEWAY_AMT)
183        xmldict['institution_item_name'] = self.context.p_category
184        xmldict['institution_name'] = INSTITUTION_NAME
185        # Interswitch amount is not part of the xml data
186        xmltext = """<payment_item_detail>
187<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
188<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" />
189<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" />
190</item_details>
191</payment_item_detail>""" % xmldict
192        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
193        self.context.provider_amt = provider_amt
194        self.context.gateway_amt = GATEWAY_AMT
195        return
196
197
198class CustomInterswitchPaymentRequestWebservicePageStudent(
199    InterswitchPaymentRequestWebservicePageStudent):
200    """Request webservice view for the CollegePAY gateway
201    """
202    grok.context(ICustomStudentOnlinePayment)
203    product_id = PRODUCT_ID
204    gateway_host = HOST
205    gateway_url = URL
206
207class CustomInterswitchPaymentVerifyWebservicePageStudent(
208    InterswitchPaymentVerifyWebservicePageStudent):
209    """Payment verify view for the CollegePAY gateway
210    """
211    grok.context(ICustomStudentOnlinePayment)
212    product_id = PRODUCT_ID
213    gateway_host = HOST
214    gateway_url = URL
215
216class CustomInterswitchPaymentRequestWebservicePageApplicant(
217    InterswitchPaymentRequestWebservicePageApplicant):
218    """Request webservice view for the CollegePAY gateway
219    """
220    grok.context(ICustomApplicantOnlinePayment)
221    product_id = PRODUCT_ID
222    gateway_host = HOST
223    gateway_url = URL
224
225class CustomInterswitchPaymentVerifyWebservicePageApplicant(
226    InterswitchPaymentVerifyWebservicePageApplicant):
227    """Payment verify view for the CollegePAY gateway
228    """
229    grok.context(ICustomApplicantOnlinePayment)
230    product_id = PRODUCT_ID
231    gateway_host = HOST
232    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.