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

Last change on this file since 9998 was 9956, checked in by Henrik Bettermann, 12 years ago

Configure acceptance fee payment.

We must not use assertMatches in browser tests when comparing payment amounts and bank account numbers because we need exact comparisons.

  • Property svn:keywords set to Id
File size: 10.9 KB
Line 
1## $Id: browser.py 9956 2013-02-15 11:49:44Z 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 zope.component import getUtility
21from kofacustom.nigeria.interswitch.browser import (
22    InterswitchPaymentRequestWebservicePageApplicant,
23    InterswitchPaymentRequestWebservicePageStudent
24    )
25from waeup.kofa.browser.layout import KofaPage
26from waeup.kofa.interfaces import IKofaUtils
27from waeup.kofa.utils.helpers import to_timezone
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 = '0026781725'
35PROVIDER_BANK_ID = '31'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'FCEOkene'
38CURRENCY = '566'
39GATEWAY_AMT = 150.0
40#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
41#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
43#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
44
45HOST = 'webpay.interswitchng.com'
46#HOST = 'testwebpay.interswitchng.com'
47URL = '/paydirect/services/TransactionQueryWs.asmx'
48#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
49httplib.HTTPConnection.debuglevel = 0
50
51class InterswitchPageStudent(KofaPage):
52    """ View which sends a POST request to the Interswitch
53    CollegePAY payment gateway.
54    """
55    grok.context(ICustomStudentOnlinePayment)
56    grok.name('goto_interswitch')
57    grok.template('student_goto_interswitch')
58    grok.require('waeup.payStudent')
59    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
60    submit_button = _('Submit')
61    action = POST_ACTION
62    site_name = SITE_NAME
63    currency = CURRENCY
64    pay_item_id = ''
65    product_id = PRODUCT_ID
66
67    def update(self):
68        if self.context.p_state == 'paid':
69            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
70            self.redirect(self.url(self.context, '@@index'))
71            return
72
73        student = self.student = self.context.student
74        certificate = getattr(student['studycourse'],'certificate',None)
75        self.amount_auth = 100 * self.context.amount_auth
76        xmldict = {}
77        if certificate is not None:
78            xmldict['department'] = certificate.__parent__.__parent__.code
79            xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code
80        else:
81            xmldict['department'] = None
82            xmldict['faculty'] = None
83        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
84        tz = getUtility(IKofaUtils).tzinfo
85        self.local_date_time = to_timezone(
86            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
87        self.site_redirect_url = self.url(self.context, 'request_webservice')
88        # Provider data
89        provider_amt = 1600.0
90        xmldict['detail_ref'] = self.context.p_id
91        xmldict['provider_acct'] = PROVIDER_ACCT
92        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
93        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
94        xmldict['provider_amt'] = 100 * provider_amt
95        # Institution data
96        fceokene_split_amt = 1400.0
97        xmldict['fceokene_acct'] = "0000000000000"
98        xmldict['institution_bank_id'] = '0'
99        xmldict['institution_item_name'] = self.category
100        xmldict['institution_name'] = INSTITUTION_NAME
101        if self.context.p_category == 'schoolfee':
102            self.pay_item_id = '8302'
103            if student.current_mode in ('nce_sw','prence',):
104                xmldict['institution_acct'] = "1012044194"
105                xmldict['institution_bank_id'] = '117'
106            elif student.current_mode in ('nce_ft',) and \
107                student['studycourse'].current_verdict == 'O':
108                xmldict['institution_acct'] = "1012044015"
109                xmldict['institution_bank_id'] = '117'
110            elif student.current_mode in ('nce_ft',):
111                xmldict['institution_acct'] = "1012044015"
112                xmldict['institution_bank_id'] = '117'
113            elif student.current_mode in ('pd_ft',):
114                xmldict['institution_acct'] = "1012415659"
115                xmldict['institution_bank_id'] = '117'
116            xmldict['fceokene_split'] = 100 * fceokene_split_amt
117            xmldict['institution_amt'] = 100 * (
118                self.context.amount_auth - provider_amt -
119                GATEWAY_AMT - fceokene_split_amt)
120        elif 'maintenance' in self.context.p_category:
121            fceokene_split_amt = 0.0
122            provider_amt = 0.0
123            self.pay_item_id = '8300'
124            xmldict['institution_amt'] = 100 * (
125                self.context.amount_auth - GATEWAY_AMT)
126            xmldict['institution_acct'] = "1012044132"
127            xmldict['institution_bank_id'] = '117'
128        elif self.context.p_category == 'clearance':
129            fceokene_split_amt = 0.0
130            provider_amt = 0.0
131            self.pay_item_id = '8304'
132            xmldict['institution_amt'] = 100 * (
133                self.context.amount_auth - GATEWAY_AMT)
134            xmldict['institution_acct'] = "2003670143"
135            xmldict['institution_bank_id'] = '8'
136
137        # Interswitch amount is not part of the xml data
138        if self.context.p_category == 'schoolfee':
139            xmltext = """<payment_item_detail>
140<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
141<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" />
142<item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1012044039" />
143<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" />
144</item_details>
145</payment_item_detail>""" % xmldict
146
147        else:
148            xmltext = """<payment_item_detail>
149<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
150<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" />
151</item_details>
152</payment_item_detail>""" % xmldict
153
154        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
155        self.context.provider_amt = provider_amt
156        self.context.gateway_amt = GATEWAY_AMT
157        self.context.thirdparty_amt = fceokene_split_amt
158        return
159
160class InterswitchPageApplicant(KofaPage):
161    """ View which sends a POST request to the Interswitch
162    CollegePAY payment gateway.
163    """
164    grok.context(ICustomApplicantOnlinePayment)
165    grok.require('waeup.payApplicant')
166    grok.template('applicant_goto_interswitch')
167    grok.name('goto_interswitch')
168    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
169    submit_button = _('Submit')
170    action = POST_ACTION
171    site_name = SITE_NAME
172    currency = CURRENCY
173    pay_item_id = '8303'
174    product_id = PRODUCT_ID
175
176    def update(self):
177        if self.context.p_state != 'unpaid':
178            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
179            self.redirect(self.url(self.context, '@@index'))
180            return
181        if self.context.__parent__.__parent__.expired \
182            and self.context.__parent__.__parent__.strict_deadline:
183            self.flash(_("Payment ticket can't be send to CollegePAY. "
184                         "Application period has expired."))
185            self.redirect(self.url(self.context, '@@index'))
186            return
187        self.applicant = self.context.__parent__
188        self.amount_auth = 100 * self.context.amount_auth
189        xmldict = {}
190        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
191        tz = getUtility(IKofaUtils).tzinfo
192        self.local_date_time = to_timezone(
193            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
194        self.site_redirect_url = self.url(self.context, 'request_webservice')
195        xmldict['detail_ref'] = self.context.p_id
196        # Provider data
197        provider_amt = 500.0
198        xmldict['provider_amt'] = 100 * provider_amt
199        xmldict['provider_acct'] = PROVIDER_ACCT
200        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
201        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
202        # Institution data
203        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
204            provider_amt - GATEWAY_AMT)
205        xmldict['institution_acct'] = '10120445289'
206        xmldict['institution_bank_id'] = '117'
207        xmldict['institution_item_name'] = self.context.p_category
208        xmldict['institution_name'] = INSTITUTION_NAME
209        # Interswitch amount is not part of the xml data
210        xmltext = """<payment_item_detail>
211<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
212<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" />
213<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" />
214</item_details>
215</payment_item_detail>""" % xmldict
216        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
217        self.context.provider_amt = provider_amt
218        self.context.gateway_amt = GATEWAY_AMT
219        return
220
221
222class InterswitchPaymentRequestWebservicePageStudent(
223    InterswitchPaymentRequestWebservicePageStudent):
224    """ Request webservice view for the CollegePAY gateway
225    """
226    grok.context(ICustomStudentOnlinePayment)
227    product_id = PRODUCT_ID
228    gateway_host = HOST
229    gateway_url = URL
230
231class InterswitchPaymentRequestWebservicePageApplicant(
232    InterswitchPaymentRequestWebservicePageApplicant):
233    """ Request webservice view for the CollegePAY gateway
234    """
235    grok.context(ICustomApplicantOnlinePayment)
236    product_id = PRODUCT_ID
237    gateway_host = HOST
238    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.