source: main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py @ 16281

Last change on this file since 16281 was 15828, checked in by Henrik Bettermann, 5 years ago

Adjust to changes in base packages.

  • Property svn:keywords set to Id
File size: 9.7 KB
RevLine 
[7894]1## $Id: browser.py 15828 2019-11-19 20:31:30Z 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##
[7898]18import httplib
[7894]19import grok
[13301]20from zope.component import getUtility
21from waeup.kofa.students.interfaces import IStudentsUtils
[9782]22from kofacustom.nigeria.interswitch.browser import (
23    InterswitchPaymentRequestWebservicePageApplicant,
[11633]24    InterswitchPaymentRequestWebservicePageStudent,
[13582]25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
[11633]27    InterswitchPageStudent, InterswitchPageApplicant,
[9782]28    )
[8263]29from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
30from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment
[8020]31from waeup.uniben.interfaces import MessageFactory as _
[7894]32
33PRODUCT_ID = '57'
[8263]34SITE_NAME = 'uniben-kofa.waeup.org'
[14214]35PROVIDER_ACCT = '1014261520'
[8424]36PROVIDER_BANK_ID = '117'
[8263]37PROVIDER_ITEM_NAME = 'BT Education'
38INSTITUTION_NAME = 'Uniben'
[13771]39INSTITUTION_ACCT = '2017506430'
40INSTITUTION_BANK_ID = '8'
[7894]41CURRENCY = '566'
[9775]42GATEWAY_AMT = 150.0
[8401]43#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
[8293]44#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
[8385]45POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
[8293]46#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[7894]47
[8293]48HOST = 'webpay.interswitchng.com'
49#HOST = 'testwebpay.interswitchng.com'
50URL = '/paydirect/services/TransactionQueryWs.asmx'
51#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
[7898]52httplib.HTTPConnection.debuglevel = 0
53
[11633]54class CustomInterswitchPageStudent(InterswitchPageStudent):
[7894]55    """ View which sends a POST request to the Interswitch
56    CollegePAY payment gateway.
57    """
[8255]58    grok.context(ICustomStudentOnlinePayment)
[7894]59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
63
[14237]64    def dynamic_provider_amt(self, student):
65        if student.entry_session >= 2016:
66            return 2500.0
67        return 1500.0
68
[7894]69    def update(self):
[11644]70        error = self.init_update()
71        if error:
72            self.flash(error, type='danger')
73            self.redirect(self.url(self.context, '@@index'))
74            return
[15828]75        self.context.r_company = u'interswitch'
[11644]76        student = self.student
77        xmldict = self.xmldict
[8263]78        # Provider data
79        xmldict['detail_ref'] = self.context.p_id
80        xmldict['provider_acct'] = PROVIDER_ACCT
81        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
82        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
83        # Institution data
[13771]84        xmldict['institution_acct'] = INSTITUTION_ACCT
85        xmldict['institution_bank_id'] = INSTITUTION_BANK_ID
[9384]86        xmldict['institution_amt'] = '0.0'
[9869]87        provider_amt = 0.0
88        self.pay_item_id = '0000'
[9384]89        if self.context.p_category == 'schoolfee':
[9869]90            if not self.context.p_item == 'Balance':
[14237]91                provider_amt = self.dynamic_provider_amt(student)
[9384]92            if student.current_mode.endswith('_ft'):
[9389]93                self.pay_item_id = '5700'
[14026]94            elif student.current_mode[-3:] in ('_pt', '_sw'):
[9389]95                self.pay_item_id = '5701'
[14902]96            elif student.is_jupeb:
[13333]97                self.pay_item_id = '5718'
[14690]98                #xmldict['institution_acct'] =  '0025186411'
99                #xmldict['institution_bank_id'] = '129'
[9384]100        elif self.context.p_category == 'clearance':
[9389]101            self.pay_item_id = '5702'
[14902]102            if student.is_jupeb:
[14691]103                self.pay_item_id = '5722'
[14237]104            provider_amt = self.dynamic_provider_amt(student)
[9727]105        elif self.context.p_category == 'gown':
[9515]106            self.pay_item_id = '5704'
[13785]107        elif self.context.p_category.startswith('hostel_maintenance'):
108            self.pay_item_id = '5705'
[13301]109        elif self.context.p_category.startswith('bed_allocation'):
110            self.pay_item_id = '5716'
[13785]111        elif self.context.p_category == 'jupeb':
112            self.pay_item_id = '5717'
[14358]113        elif self.context.p_category == 'clinexam':
114            self.pay_item_id = '5720'
[9384]115
116        xmldict['provider_amt'] = 100 * provider_amt
117        xmldict['institution_item_name'] = self.category
[8263]118        xmldict['institution_name'] = INSTITUTION_NAME
[9384]119        xmldict['institution_amt'] = 100 * (
[9775]120            self.context.amount_auth - provider_amt - GATEWAY_AMT)
[13301]121
[13771]122        if provider_amt == 0:
[9515]123            xmltext = """<payment_item_detail>
[8263]124<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
125<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" />
[9515]126</item_details>
127</payment_item_detail>""" % xmldict
128        else:
129            xmltext = """<payment_item_detail>
130<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
131<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" />
[8263]132<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" />
133</item_details>
134</payment_item_detail>""" % xmldict
135        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9775]136        self.context.provider_amt = provider_amt
137        self.context.gateway_amt = GATEWAY_AMT
[15828]138        self.amount_auth = int(100 * self.context.amount_auth)
[7894]139        return
140
[11633]141class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[8256]142    """ View which sends a POST request to the Interswitch
143    CollegePAY payment gateway.
144    """
145    grok.context(ICustomApplicantOnlinePayment)
[8263]146    action = POST_ACTION
147    site_name = SITE_NAME
148    currency = CURRENCY
[8274]149    pay_item_id = '5703'
[8263]150    product_id = PRODUCT_ID
[8256]151
152    def update(self):
[11644]153        error = self.init_update()
154        if error:
155            self.flash(error, type='danger')
156            self.redirect(self.url(self.context, '@@index'))
157            return
[15828]158        self.context.r_company = u'interswitch'
[8256]159        xmldict = {}
[9775]160        provider_amt = 400.0
[13771]161        if self.applicant.applicant_id.startswith('cbt'):
[13143]162            provider_amt = 200.0
[13771]163        xmldict['institution_acct'] = INSTITUTION_ACCT
164        xmldict['institution_bank_id'] = INSTITUTION_BANK_ID
[14182]165        if self.applicant.applicant_id.startswith('ak'):
[14059]166            xmldict['institution_acct'] = 1014774176
167            xmldict['institution_bank_id'] = 117
[14691]168        if self.applicant.applicant_id.startswith('pre'):
169            self.pay_item_id = '5721'
[8263]170        xmldict['detail_ref'] = self.context.p_id
[8545]171        xmldict['provider_amt'] = 100 * provider_amt
[8263]172        xmldict['provider_acct'] = PROVIDER_ACCT
173        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
174        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[13771]175        xmldict['institution_amt'] = 100 * (
176            self.context.amount_auth - provider_amt - GATEWAY_AMT)
[13818]177        xmldict['institution_item_name'] = self.category
[8263]178        xmldict['institution_name'] = INSTITUTION_NAME
179        # Interswitch amount is not part of the xml data
180        xmltext = """<payment_item_detail>
181<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
182<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" />
183<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" />
184</item_details>
185</payment_item_detail>""" % xmldict
186        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9775]187        self.context.provider_amt = provider_amt
188        self.context.gateway_amt = GATEWAY_AMT
[15828]189        self.amount_auth = int(100 * self.context.amount_auth)
[8256]190        return
191
[11633]192class CustomInterswitchPaymentRequestWebservicePageStudent(
[9782]193    InterswitchPaymentRequestWebservicePageStudent):
[13582]194    """Request webservice view for the CollegePAY gateway
[7919]195    """
[8255]196    grok.context(ICustomStudentOnlinePayment)
[9782]197    product_id = PRODUCT_ID
198    gateway_host = HOST
199    gateway_url = URL
[7919]200
[13582]201class CustomInterswitchPaymentVerifyWebservicePageStudent(
202    InterswitchPaymentVerifyWebservicePageStudent):
[13590]203    """Payment verify view for the CollegePAY gateway
[13582]204    """
205    grok.context(ICustomStudentOnlinePayment)
206    product_id = PRODUCT_ID
207    gateway_host = HOST
208    gateway_url = URL
209
[11633]210class CustomInterswitchPaymentRequestWebservicePageApplicant(
[9782]211    InterswitchPaymentRequestWebservicePageApplicant):
[13582]212    """Request webservice view for the CollegePAY gateway
[8256]213    """
214    grok.context(ICustomApplicantOnlinePayment)
[9782]215    product_id = PRODUCT_ID
216    gateway_host = HOST
[11478]217    gateway_url = URL
[13582]218
219class CustomInterswitchPaymentVerifyWebservicePageApplicant(
220    InterswitchPaymentVerifyWebservicePageApplicant):
221    """Payment verify view for the CollegePAY gateway
222    """
223    grok.context(ICustomApplicantOnlinePayment)
224    product_id = PRODUCT_ID
225    gateway_host = HOST
226    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.