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

Last change on this file since 12133 was 11919, checked in by Henrik Bettermann, 10 years ago

Configure third semester payment in setPaymentDetails. Session configuration field is is no longer needed.

  • Property svn:keywords set to Id
File size: 9.2 KB
Line 
1## $Id: browser.py 11919 2014-10-30 21:20:11Z 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        error = self.init_update()
61        if error:
62            self.flash(error, type='danger')
63            self.redirect(self.url(self.context, '@@index'))
64            return
65        student = self.student
66        xmldict = self.xmldict
67        # Provider data
68        provider_amt = 1600.0
69        xmldict['detail_ref'] = self.context.p_id
70        xmldict['provider_acct'] = PROVIDER_ACCT
71        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
72        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
73        xmldict['provider_amt'] = 100 * provider_amt
74        # Institution data
75        fceokene_split_amt = 1400.0
76        xmldict['fceokene_acct'] = "0000000000000"
77        xmldict['institution_bank_id'] = '0'
78        xmldict['institution_item_name'] = self.category
79        xmldict['institution_name'] = INSTITUTION_NAME
80        if self.context.p_category in ('schoolfee', 'third_semester'):
81            self.pay_item_id = '8302'
82            if student.current_mode in ('nce_sw','prence',):
83                xmldict['institution_acct'] = "1012044194"
84                xmldict['institution_bank_id'] = '117'
85            elif student.current_mode in ('nce_ft',) and \
86                student['studycourse'].current_verdict == 'O':
87                xmldict['institution_acct'] = "1012044015"
88                xmldict['institution_bank_id'] = '117'
89            elif student.current_mode in ('nce_ft',):
90                xmldict['institution_acct'] = "1012044015"
91                xmldict['institution_bank_id'] = '117'
92            elif student.current_mode in ('pd_ft',):
93                xmldict['institution_acct'] = "1012415659"
94                xmldict['institution_bank_id'] = '117'
95            #undergraduate schoolfee added
96            elif student.current_mode in ('ug_ft',):
97                xmldict['institution_acct'] = "2003670143"
98                xmldict['institution_bank_id'] = '8'
99            xmldict['fceokene_split'] = 100 * fceokene_split_amt
100            xmldict['institution_amt'] = 100 * (
101                self.context.amount_auth - provider_amt -
102                GATEWAY_AMT - fceokene_split_amt)
103        elif 'maintenance' in self.context.p_category:
104            fceokene_split_amt = 0.0
105            provider_amt = 0.0
106            self.pay_item_id = '8300'
107            xmldict['institution_amt'] = 100 * (
108                self.context.amount_auth - GATEWAY_AMT)
109            xmldict['institution_acct'] = "1012044132"
110            xmldict['institution_bank_id'] = '117'
111        elif self.context.p_category == 'clearance':
112            fceokene_split_amt = 0.0
113            provider_amt = 0.0
114            self.pay_item_id = '8304'
115            xmldict['institution_amt'] = 100 * (
116                self.context.amount_auth - GATEWAY_AMT)
117            xmldict['institution_acct'] = "2003670143"
118            xmldict['institution_bank_id'] = '8'
119
120        # Interswitch amount is not part of the xml data
121        if self.context.p_category in ('schoolfee', 'third_semester'):
122            xmltext = """<payment_item_detail>
123<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
124<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" />
125<item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1012044039" />
126<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" />
127</item_details>
128</payment_item_detail>""" % xmldict
129
130        else:
131            xmltext = """<payment_item_detail>
132<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
133<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" />
134</item_details>
135</payment_item_detail>""" % xmldict
136
137        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
138        self.context.provider_amt = provider_amt
139        self.context.gateway_amt = GATEWAY_AMT
140        self.context.thirdparty_amt = fceokene_split_amt
141        return
142
143class CustomInterswitchPageApplicant(InterswitchPageApplicant):
144    """ View which sends a POST request to the Interswitch
145    CollegePAY payment gateway.
146    """
147    grok.context(ICustomApplicantOnlinePayment)
148    action = POST_ACTION
149    site_name = SITE_NAME
150    currency = CURRENCY
151    pay_item_id = '8303'
152    product_id = PRODUCT_ID
153
154    def update(self):
155        super(CustomInterswitchPageApplicant, self).update()
156        xmldict = {}
157        # Provider data
158        provider_amt = 500.0
159        xmldict['detail_ref'] = self.context.p_id
160        xmldict['provider_amt'] = 100 * provider_amt
161        xmldict['provider_acct'] = PROVIDER_ACCT
162        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
163        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
164        # Institution data
165        if getattr(
166            self.applicant.__parent__, 'prefix', None) in ('pude', 'putme'):
167            xmldict['institution_acct'] = '2003670143'
168            xmldict['institution_bank_id'] = '8'
169        else:
170            xmldict['institution_acct'] = '1012445289'
171            xmldict['institution_bank_id'] = '117'
172        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
173            provider_amt - GATEWAY_AMT)
174        xmldict['institution_item_name'] = self.context.p_category
175        xmldict['institution_name'] = INSTITUTION_NAME
176        # Interswitch amount is not part of the xml data
177        xmltext = """<payment_item_detail>
178<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
179<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" />
180<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" />
181</item_details>
182</payment_item_detail>""" % xmldict
183        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
184        self.context.provider_amt = provider_amt
185        self.context.gateway_amt = GATEWAY_AMT
186        return
187
188
189class CustomInterswitchPaymentRequestWebservicePageStudent(
190    InterswitchPaymentRequestWebservicePageStudent):
191    """ Request webservice view for the CollegePAY gateway
192    """
193    grok.context(ICustomStudentOnlinePayment)
194    product_id = PRODUCT_ID
195    gateway_host = HOST
196    gateway_url = URL
197
198class CustomInterswitchPaymentRequestWebservicePageApplicant(
199    InterswitchPaymentRequestWebservicePageApplicant):
200    """ Request webservice view for the CollegePAY gateway
201    """
202    grok.context(ICustomApplicantOnlinePayment)
203    product_id = PRODUCT_ID
204    gateway_host = HOST
205    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.