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

Last change on this file since 11645 was 11635, checked in by Henrik Bettermann, 11 years ago

Use base classes InterswitchPageApplicant? and InterswitchPageStudent? from kofacustom.nigeria.

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