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

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

Test if the ticket-expire mechanism works, for both applicant and student payments.

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