source: main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py @ 13018

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

To guarantee that cleared students pay both acceptance fees and
school fees, a school fee payment POST request to the Interswitch
CollegePAY payment gateway can only be sent if
acceptance/clearance fee has been successfully queried/paid
beforehand. This requirement applies to students in state 'cleared'
and entry_session greater than 2013 only, see ticket #119.

  • Property svn:keywords set to Id
File size: 11.3 KB
Line 
1## $Id: browser.py 12975 2015-05-21 17:05:42Z 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 hashlib
20import grok
21from zope.interface import Interface
22from zope.component import queryAdapter
23from waeup.kofa.interfaces import CLEARED
24from kofacustom.nigeria.interswitch.browser import (
25    InterswitchPaymentRequestWebservicePageStudent,
26    InterswitchPaymentRequestWebservicePageApplicant,
27    InterswitchPageStudent, InterswitchPageApplicant,
28    )
29from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment
30from waeup.aaue.applicants.interfaces import ICustomApplicantOnlinePayment
31from waeup.aaue.interfaces import MessageFactory as _
32
33PRODUCT_ID = '5040'
34SITE_NAME = 'aaue.waeup.org'
35PROVIDER_ACCT = '1010764827'
36PROVIDER_BANK_ID = '117'
37PROVIDER_ITEM_NAME = 'BT Education'
38INSTITUTION_NAME = 'AAU Ekpoma'
39CURRENCY = '566'
40GATEWAY_AMT = 250.0
41#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
42#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
43
44#POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
45#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
46#POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
47POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
48
49HOST = 'webpay.interswitchng.com'
50#HOST = 'stageserv.interswitchng.com'
51HTTPS = True
52
53URL = '/paydirect/services/TransactionQueryWs.asmx'
54#URL = '/test_paydirect/services/TransactionQueryWS.asmx'
55httplib.HTTPSConnection.debuglevel = 0
56
57class CustomInterswitchPageApplicant(InterswitchPageApplicant):
58    """ View which sends a POST request to the Interswitch
59    CollegePAY payment gateway.
60    """
61    grok.context(ICustomApplicantOnlinePayment)
62    action = POST_ACTION
63    site_name = SITE_NAME
64    currency = CURRENCY
65    pay_item_id = '101'
66    product_id = PRODUCT_ID
67    mac = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
68
69    def update(self):
70
71        error = self.init_update()
72        if error:
73            self.flash(error, type='danger')
74            self.redirect(self.url(self.context, '@@index'))
75            return
76        xmldict = {}
77        provider_amt = 1000.0
78        xmldict['institution_acct'] = '1010835352'
79        xmldict['institution_bank_id'] = '117'
80        xmldict['detail_ref'] = self.context.p_id
81        xmldict['provider_amt'] = 100 * provider_amt
82        xmldict['provider_acct'] = PROVIDER_ACCT
83        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
84        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
85        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
86        xmldict['institution_item_name'] = self.context.p_category
87        xmldict['institution_name'] = INSTITUTION_NAME
88        # Interswitch amount is not part of the xml data
89        xmltext = """<payment_item_detail>
90<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
91<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" />
92<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" />
93</item_details>
94</payment_item_detail>""" % xmldict
95        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
96        self.context.provider_amt = provider_amt
97        self.context.gateway_amt = GATEWAY_AMT
98
99        hashargs = (
100            self.context.p_id +
101            PRODUCT_ID +
102            self.pay_item_id +
103            str(int(self.amount_auth)) +
104            self.site_redirect_url +
105            self.mac)
106        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
107
108        return
109
110class CustomInterswitchPageStudent(InterswitchPageStudent):
111    """ View which sends a POST request to the Interswitch
112    CollegePAY payment gateway.
113    """
114    grok.context(ICustomStudentOnlinePayment)
115    action = POST_ACTION
116    site_name = SITE_NAME
117    currency = CURRENCY
118    product_id = PRODUCT_ID
119    pay_item_id = '101'
120    mac = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
121
122    def update(self):
123        error = self.init_update()
124        if error:
125            self.flash(error, type='danger')
126            self.redirect(self.url(self.context, '@@index'))
127            return
128        student = self.student
129
130        # To guarantee that cleared students pay both acceptance fee
131        # and school fees, the page can only be accessed
132        # for school fee payments if acceptance/clearance fee has
133        # been successfully queried/paid beforehand. This
134        # requirement applies to students in state 'cleared' and
135        # entry_session greater than 2013 only.
136        if self.context.p_category == 'schoolfee' and \
137            student.state == CLEARED and \
138            student.entry_session > 2012:
139            acceptance_fee_paid = False
140            for ticket in student['payments'].values():
141                if ticket.p_state == 'paid' and \
142                    ticket.p_category == 'clearance':
143                    acceptance_fee_paid = True
144                    break
145            if not acceptance_fee_paid:
146                self.flash(
147                    _('Please pay acceptance fee first.'), type="danger")
148                self.redirect(self.url(self.context, '@@index'))
149                return
150
151        xmldict = self.xmldict
152        xmltext = ""
153        # Provider data
154        xmldict['detail_ref'] = self.context.p_id
155        xmldict['provider_acct'] = PROVIDER_ACCT
156        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
157        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
158        xmldict['institution_item_name'] = self.category
159        xmldict['institution_name'] = INSTITUTION_NAME
160
161        if self.context.p_category == 'schoolfee':
162            if student.faccode == 'FCETA':
163                xmldict['institution_acct'] = '1190118227'
164                xmldict['institution_bank_id'] = '123'
165            else:
166                xmldict['institution_bank_id'] = '7'
167                xmldict['institution_acct'] = '1014847058'
168            if student.current_mode == 'found':
169                self.pay_item_id = '103'
170            else:
171                self.pay_item_id = '105'
172            provider_amt = 1900.0
173            joint_venture_amt = 1100.0
174            aaue_share_amt = 1000.0
175            student_union_due_amt = 1000.0
176            student_welfare_assurance_amt = 500.0
177            xmldict['provider_amt'] = 100 * provider_amt
178            xmldict['joint_venture_amt'] = 100 * joint_venture_amt
179            xmldict['aaue_share_amt'] = 100 * aaue_share_amt
180            xmldict['student_union_due_amt'] = 100 * student_union_due_amt
181            xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
182            xmldict['institution_amt'] = 100 * (
183                self.context.amount_auth
184                - provider_amt
185                - joint_venture_amt
186                - aaue_share_amt
187                - student_union_due_amt
188                - student_welfare_assurance_amt
189                - GATEWAY_AMT)
190            xmltext = """<payment_item_detail>
191<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
192<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" />
193<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" />
194<item_detail item_id="3" item_name="Joint Venture" item_amt="%(joint_venture_amt)d" bank_id="51" acct_num="5060023759" />
195<item_detail item_id="4" item_name="AAUE Share" item_amt="%(aaue_share_amt)d" bank_id="51" acct_num="5060020947" />
196<item_detail item_id="5" item_name="Student Union" item_amt="%(student_union_due_amt)d" bank_id="123" acct_num="1006360118" />
197<item_detail item_id="6" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="31" acct_num="1006407792" />
198</item_details>
199</payment_item_detail>""" % xmldict
200        elif self.context.p_category == 'clearance':
201            if student.current_mode == 'found':
202                self.pay_item_id = '102'
203            else:
204                self.pay_item_id = '104'
205            xmldict['institution_acct'] = '1014066976'
206            xmldict['institution_bank_id'] = '117'
207            provider_amt = 0.0
208            gown_fee_amt = 2000.0
209            aaue_fl_fee_amt = 800.0
210            xmldict['gown_fee_amt'] = 100 * gown_fee_amt
211            xmldict['aaue_fl_fee_amt'] = 100 * aaue_fl_fee_amt
212            xmldict['institution_amt'] = 100 * (
213                self.context.amount_auth
214                - gown_fee_amt
215                - aaue_fl_fee_amt
216                - GATEWAY_AMT)
217            xmltext = """<payment_item_detail>
218<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
219<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" />
220<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="51" acct_num="5060020947" />
221<item_detail item_id="3" item_name="AAU File-Lapel Fee" item_amt="%(aaue_fl_fee_amt)d" bank_id="51" acct_num="4010660109" />
222</item_details>
223</payment_item_detail>""" % xmldict
224
225
226        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
227        self.context.provider_amt = provider_amt
228        self.context.gateway_amt = GATEWAY_AMT
229        hashargs = (
230            self.context.p_id +
231            PRODUCT_ID +
232            self.pay_item_id +
233            str(int(self.amount_auth)) +
234            self.site_redirect_url +
235            self.mac)
236        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
237        return
238
239
240class CustomInterswitchPaymentRequestWebservicePageApplicant(
241    InterswitchPaymentRequestWebservicePageApplicant):
242    """ Request webservice view for the CollegePAY gateway
243    """
244    grok.context(ICustomApplicantOnlinePayment)
245    product_id = PRODUCT_ID
246    gateway_host = HOST
247    gateway_url = URL
248    https = HTTPS
249
250class CustomInterswitchPaymentRequestWebservicePageStudent(
251    InterswitchPaymentRequestWebservicePageStudent):
252    """ Request webservice view for the CollegePAY gateway
253    """
254    grok.context(ICustomStudentOnlinePayment)
255    product_id = PRODUCT_ID
256    gateway_host = HOST
257    gateway_url = URL
258    https = HTTPS
Note: See TracBrowser for help on using the repository browser.