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

Last change on this file since 13397 was 13397, checked in by Henrik Bettermann, 9 years ago

Change provider account.

  • Property svn:keywords set to Id
File size: 19.2 KB
Line 
1## $Id: browser.py 13397 2015-11-06 10:25:54Z 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_PT = '5040'
34PRODUCT_ID_REGULAR = '5845'
35SITE_NAME = 'aaue.waeup.org'
36PROVIDER_ACCT = '2022866811'
37PROVIDER_BANK_ID = '8'
38PROVIDER_ITEM_NAME = 'BT Education'
39INSTITUTION_NAME = 'AAU Ekpoma'
40CURRENCY = '566'
41GATEWAY_AMT = 250.0
42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
43
44HOST = 'webpay.interswitchng.com'
45HTTPS = True
46
47URL = '/paydirect/services/TransactionQueryWs.asmx'
48httplib.HTTPSConnection.debuglevel = 0
49
50
51def school(student):
52    if student.current_mode == 'found' or student.current_mode.endswith('_pt'):
53        return 'pt'
54    return 'regular'
55
56class CustomInterswitchPageApplicant(InterswitchPageApplicant):
57    """ View which sends a POST request to the Interswitch
58    CollegePAY payment gateway.
59
60    So far only PT application has been configured.
61    """
62    grok.context(ICustomApplicantOnlinePayment)
63    action = POST_ACTION
64    site_name = SITE_NAME
65    currency = CURRENCY
66    pay_item_id = '101'
67    product_id = PRODUCT_ID_PT
68    mac = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
69
70    def update(self):
71
72        error = self.init_update()
73        if error:
74            self.flash(error, type='danger')
75            self.redirect(self.url(self.context, '@@index'))
76            return
77        xmldict = {}
78        provider_amt = 1000.0
79        xmldict['institution_acct'] = '1010835352'
80        xmldict['institution_bank_id'] = '117'
81        xmldict['detail_ref'] = self.context.p_id
82        xmldict['provider_amt'] = 100 * provider_amt
83        xmldict['provider_acct'] = PROVIDER_ACCT
84        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
85        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
86        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
87        xmldict['institution_item_name'] = self.context.p_category
88        xmldict['institution_name'] = INSTITUTION_NAME
89        # Interswitch amount is not part of the xml data
90        xmltext = """<payment_item_detail>
91<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
92<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" />
93<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" />
94</item_details>
95</payment_item_detail>""" % xmldict
96        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
97        self.context.provider_amt = provider_amt
98        self.context.gateway_amt = GATEWAY_AMT
99
100        hashargs = (
101            self.context.p_id +
102            PRODUCT_ID_PT +
103            self.pay_item_id +
104            str(int(self.amount_auth)) +
105            self.site_redirect_url +
106            self.mac)
107        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
108
109        return
110
111class CustomInterswitchPageStudent(InterswitchPageStudent):
112    """ View which sends a POST request to the Interswitch
113    CollegePAY payment gateway.
114    """
115    grok.context(ICustomStudentOnlinePayment)
116    action = POST_ACTION
117    site_name = SITE_NAME
118    currency = CURRENCY
119    pay_item_id = '101'
120    #mac = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
121    mac = '9718FA00B0F5070B388A9896ADCED9B2FB02D30F71E12E68BDADC63F6852A3496FF97D8A0F9DA9F753B911A49BB09BB87B55FD02046BD325C74C46C0123CF023'
122
123    def update(self):
124        error = self.init_update()
125
126        ######################################
127        #error = 'Sorry, Interswitch payments are temporarily disabled.'
128        ######################################
129
130        if error:
131            self.flash(error, type='danger')
132            self.redirect(self.url(self.context, '@@index'))
133            return
134        student = self.student
135
136        if school(student) == 'PT':
137            self.product_id = PRODUCT_ID_PT
138        else:
139            self.product_id = PRODUCT_ID_REGULAR
140
141        # To guarantee that cleared students pay both acceptance fee
142        # and school fees, the page can only be accessed
143        # for school fee payments if acceptance/clearance fee has
144        # been successfully queried/paid beforehand. This
145        # requirement applies to students in state 'cleared' and
146        # entry_session greater than 2013 only.
147        if self.context.p_category == 'schoolfee' and \
148            student.state == CLEARED and \
149            student.entry_session > 2012:
150            acceptance_fee_paid = False
151            for ticket in student['payments'].values():
152                if ticket.p_state == 'paid' and \
153                    ticket.p_category == 'clearance':
154                    acceptance_fee_paid = True
155                    break
156            if not acceptance_fee_paid:
157                self.flash(
158                    _('Please pay acceptance fee first.'), type="danger")
159                self.redirect(self.url(self.context, '@@index'))
160                return
161
162        xmldict = self.xmldict
163        xmltext = ""
164        # Provider data
165        xmldict['detail_ref'] = self.context.p_id
166        xmldict['provider_acct'] = PROVIDER_ACCT
167        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
168        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
169        xmldict['institution_item_name'] = self.category
170        xmldict['institution_name'] = INSTITUTION_NAME
171        provider_amt = 0.0
172
173        # PT
174        if school(student) == 'pt':
175            if self.context.p_category == 'schoolfee':
176                xmldict['institution_bank_id'] = '7'
177                xmldict['institution_acct'] = '1014847058'
178                if student.current_mode == 'found':
179                    self.pay_item_id = '103'
180                else:
181                    self.pay_item_id = '105'
182                provider_amt = 1900.0
183                joint_venture_amt = 1100.0
184                aaue_share_amt = 1000.0
185                student_union_due_amt = 1000.0
186                student_welfare_assurance_amt = 500.0
187                xmldict['provider_amt'] = 100 * provider_amt
188                xmldict['joint_venture_amt'] = 100 * joint_venture_amt
189                xmldict['aaue_share_amt'] = 100 * aaue_share_amt
190                xmldict['student_union_due_amt'] = 100 * student_union_due_amt
191                xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
192                xmldict['institution_amt'] = 100 * (
193                    self.context.amount_auth
194                    - provider_amt
195                    - joint_venture_amt
196                    - aaue_share_amt
197                    - student_union_due_amt
198                    - student_welfare_assurance_amt
199                    - GATEWAY_AMT)
200                xmltext = """<payment_item_detail>
201<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
202<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" />
203<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" />
204<item_detail item_id="3" item_name="Joint Venture" item_amt="%(joint_venture_amt)d" bank_id="51" acct_num="5060023759" />
205<item_detail item_id="4" item_name="AAUE Share" item_amt="%(aaue_share_amt)d" bank_id="51" acct_num="5060020947" />
206<item_detail item_id="5" item_name="Student Union" item_amt="%(student_union_due_amt)d" bank_id="123" acct_num="1006360118" />
207<item_detail item_id="6" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="31" acct_num="1006407792" />
208</item_details>
209</payment_item_detail>""" % xmldict
210            elif self.context.p_category == 'clearance':
211                if student.current_mode == 'found':
212                    self.pay_item_id = '102'
213                else:
214                    self.pay_item_id = '104'
215                xmldict['institution_acct'] = '1014066976'
216                xmldict['institution_bank_id'] = '117'
217                gown_fee_amt = 2000.0
218                aaue_fl_fee_amt = 800.0
219                xmldict['gown_fee_amt'] = 100 * gown_fee_amt
220                xmldict['aaue_fl_fee_amt'] = 100 * aaue_fl_fee_amt
221                xmldict['institution_amt'] = 100 * (
222                    self.context.amount_auth
223                    - gown_fee_amt
224                    - aaue_fl_fee_amt
225                    - GATEWAY_AMT)
226                xmltext = """<payment_item_detail>
227<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
228<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" />
229<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="51" acct_num="5060020947" />
230<item_detail item_id="3" item_name="AAU File-Lapel Fee" item_amt="%(aaue_fl_fee_amt)d" bank_id="51" acct_num="4010660109" />
231</item_details>
232</payment_item_detail>""" % xmldict
233            else:
234                self.flash('Not applicable', type='danger')
235                self.redirect(self.url(self.context, '@@index'))
236                return
237
238        # REGULAR
239        else:
240            if self.context.p_category == 'schoolfee':
241                self.pay_item_id = '101'
242                xmldict['institution_bank_id'] = '117'
243                xmldict['institution_acct'] = '1010827641'
244                provider_amt = 1500.0
245                xmldict['provider_amt'] = 100 * provider_amt
246                aaue_share_amt = 1500.0
247                xmldict['aaue_share_amt'] = 100 * aaue_share_amt
248                joint_venture_amt = 1000.0
249                xmldict['joint_venture_amt'] = 100 * joint_venture_amt
250                xmldict['institution_amt'] = 100 * (
251                    self.context.amount_auth
252                    - provider_amt
253                    - joint_venture_amt
254                    - aaue_share_amt
255                    - GATEWAY_AMT)
256                xmltext = """<payment_item_detail>
257<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
258<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" />
259<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" />
260<item_detail item_id="3" item_name="Joint Venture" item_amt="%(joint_venture_amt)d" bank_id="117" acct_num="1014066969" />
261<item_detail item_id="4" item_name="AAUE Share" item_amt="%(aaue_share_amt)d" bank_id="11" acct_num="0030656377" />
262</item_details>
263</payment_item_detail>""" % xmldict
264
265            elif self.context.p_category == 'clearance':
266                self.pay_item_id = '102'
267                xmldict['institution_acct'] = '1010827641'
268                xmldict['institution_bank_id'] = '117'
269                xmldict['institution_amt'] = 100 * (
270                    self.context.amount_auth - GATEWAY_AMT)
271                xmltext = """<payment_item_detail>
272<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
273<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" />
274</item_details>
275</payment_item_detail>""" % xmldict
276
277            elif self.context.p_category == 'union':
278                self.pay_item_id = '103'
279                xmldict['institution_acct'] = '1006360118'
280                xmldict['institution_bank_id'] = '123'
281                xmldict['institution_amt'] = 100 * (
282                    self.context.amount_auth - GATEWAY_AMT)
283                xmltext = """<payment_item_detail>
284<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
285<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" />
286</item_details>
287</payment_item_detail>""" % xmldict
288
289            elif self.context.p_category == 'lapel':
290                self.pay_item_id = '104'
291                xmldict['institution_acct'] = '4010660109'
292                xmldict['institution_bank_id'] = '51'
293                xmldict['institution_amt'] = 100 * (
294                    self.context.amount_auth - GATEWAY_AMT)
295                xmltext = """<payment_item_detail>
296<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
297<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" />
298</item_details>
299</payment_item_detail>""" % xmldict
300
301            elif self.context.p_category == 'welfare':
302                self.pay_item_id = '105'
303                xmldict['institution_acct'] = '1006407792'
304                xmldict['institution_bank_id'] = '123'
305                xmldict['institution_amt'] = 100 * (
306                    self.context.amount_auth - GATEWAY_AMT)
307                xmltext = """<payment_item_detail>
308<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
309<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" />
310</item_details>
311</payment_item_detail>""" % xmldict
312
313            elif self.context.p_category == 'matric_gown':
314                self.pay_item_id = '106'
315                xmldict['institution_acct'] = '5060023429'
316                xmldict['institution_bank_id'] = '51'
317                xmldict['institution_amt'] = 100 * (
318                    self.context.amount_auth - GATEWAY_AMT)
319                xmltext = """<payment_item_detail>
320<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
321<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" />
322</item_details>
323</payment_item_detail>""" % xmldict
324
325            elif self.context.p_category == 'concessional':
326                self.pay_item_id = '107'
327                xmldict['institution_acct'] = '1010835352'
328                xmldict['institution_bank_id'] = '117'
329                xmldict['institution_amt'] = 100 * (
330                    self.context.amount_auth - GATEWAY_AMT)
331                xmltext = """<payment_item_detail>
332<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
333<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" />
334</item_details>
335</payment_item_detail>""" % xmldict
336
337            elif self.context.p_category == 'medical':
338                self.pay_item_id = '108'
339                xmldict['institution_acct'] = '1010827641'
340                xmldict['institution_bank_id'] = '117'
341                xmldict['institution_amt'] = 100 * (
342                    self.context.amount_auth - GATEWAY_AMT)
343                xmltext = """<payment_item_detail>
344<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
345<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" />
346</item_details>
347</payment_item_detail>""" % xmldict
348
349            elif self.context.p_category == 'hostel_maintenance':
350                self.pay_item_id = '109'
351                xmldict['institution_acct'] = '1006406795'
352                xmldict['institution_bank_id'] = '123'
353                xmldict['institution_amt'] = 100 * (
354                    self.context.amount_auth - GATEWAY_AMT)
355                xmltext = """<payment_item_detail>
356<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
357<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" />
358</item_details>
359</payment_item_detail>""" % xmldict
360
361        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
362        self.context.provider_amt = provider_amt
363        self.context.gateway_amt = GATEWAY_AMT
364        hashargs = (
365            self.context.p_id +
366            self.product_id +
367            self.pay_item_id +
368            str(int(self.amount_auth)) +
369            self.site_redirect_url +
370            self.mac)
371        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
372        return
373
374
375class CustomInterswitchPaymentRequestWebservicePageApplicant(
376    InterswitchPaymentRequestWebservicePageApplicant):
377    """ Request webservice view for the CollegePAY gateway
378
379    So far only PT application has been configured.
380    """
381    grok.context(ICustomApplicantOnlinePayment)
382    product_id = PRODUCT_ID_PT
383    gateway_host = HOST
384    gateway_url = URL
385    https = HTTPS
386
387class CustomInterswitchPaymentRequestWebservicePageStudent(
388    InterswitchPaymentRequestWebservicePageStudent):
389    """ Request webservice view for the CollegePAY gateway
390    """
391    grok.context(ICustomStudentOnlinePayment)
392    gateway_host = HOST
393    gateway_url = '/paydirect/api/v1/gettransaction.json'
394    https = HTTPS
395    mac = '9718FA00B0F5070B388A9896ADCED9B2FB02D30F71E12E68BDADC63F6852A3496FF97D8A0F9DA9F753B911A49BB09BB87B55FD02046BD325C74C46C0123CF023'
396
397    @property
398    def product_id(self):
399        if school(self.context.student) == 'pt':
400            return PRODUCT_ID_PT
401        return PRODUCT_ID_REGULAR
Note: See TracBrowser for help on using the repository browser.