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

Last change on this file since 13461 was 12976, checked in by Henrik Bettermann, 9 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
RevLine 
[7894]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##
[7898]18import httplib
[7894]19import grok
[9784]20from kofacustom.nigeria.interswitch.browser import (
21    InterswitchPaymentRequestWebservicePageApplicant,
[11635]22    InterswitchPaymentRequestWebservicePageStudent,
23    InterswitchPageStudent, InterswitchPageApplicant,
[9784]24    )
[8460]25from waeup.fceokene.students.interfaces import ICustomStudentOnlinePayment
26from waeup.fceokene.applicants.interfaces import ICustomApplicantOnlinePayment
27from waeup.fceokene.interfaces import MessageFactory as _
[7894]28
[8644]29PRODUCT_ID = '83'
[8460]30SITE_NAME = 'fceokene-kofa.waeup.org'
[8641]31PROVIDER_ACCT = '0026781725'
32PROVIDER_BANK_ID = '31'
[8263]33PROVIDER_ITEM_NAME = 'BT Education'
[8460]34INSTITUTION_NAME = 'FCEOkene'
[7894]35CURRENCY = '566'
[9780]36GATEWAY_AMT = 150.0
[8401]37#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
[8293]38#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
[8385]39POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
[8293]40#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[7894]41
[8293]42HOST = 'webpay.interswitchng.com'
43#HOST = 'testwebpay.interswitchng.com'
44URL = '/paydirect/services/TransactionQueryWs.asmx'
45#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
[7898]46httplib.HTTPConnection.debuglevel = 0
47
[11635]48class CustomInterswitchPageStudent(InterswitchPageStudent):
[7894]49    """ View which sends a POST request to the Interswitch
50    CollegePAY payment gateway.
51    """
[8255]52    grok.context(ICustomStudentOnlinePayment)
[7894]53    action = POST_ACTION
54    site_name = SITE_NAME
55    currency = CURRENCY
[9613]56    pay_item_id = ''
[7894]57    product_id = PRODUCT_ID
58
59    def update(self):
[11649]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
[8263]67        # Provider data
[9780]68        provider_amt = 1600.0
[8263]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
[9780]73        xmldict['provider_amt'] = 100 * provider_amt
[8263]74        # Institution data
[9780]75        fceokene_split_amt = 1400.0
[9613]76        xmldict['fceokene_acct'] = "0000000000000"
77        xmldict['institution_bank_id'] = '0'
78        xmldict['institution_item_name'] = self.category
79        xmldict['institution_name'] = INSTITUTION_NAME
[11919]80        if self.context.p_category in ('schoolfee', 'third_semester'):
[9613]81            self.pay_item_id = '8302'
[12799]82            if student.current_mode in ('ct_ft',):
83                xmldict['institution_acct'] = "1012044039"
84                xmldict['institution_bank_id'] = '117'
[9943]85            if student.current_mode in ('nce_sw','prence',):
[12661]86                xmldict['institution_acct'] = "1013780934"
[9613]87                xmldict['institution_bank_id'] = '117'
[9943]88            elif student.current_mode in ('nce_ft',) and \
[9613]89                student['studycourse'].current_verdict == 'O':
[12661]90                xmldict['institution_acct'] = "1013780934"
[9613]91                xmldict['institution_bank_id'] = '117'
[9943]92            elif student.current_mode in ('nce_ft',):
[12661]93                xmldict['institution_acct'] = "1013780934"
[9613]94                xmldict['institution_bank_id'] = '117'
95            elif student.current_mode in ('pd_ft',):
[12661]96                xmldict['institution_acct'] = "1013780934"
[9613]97                xmldict['institution_bank_id'] = '117'
[10011]98            #undergraduate schoolfee added
99            elif student.current_mode in ('ug_ft',):
[12662]100                xmldict['institution_acct'] = "2010952698"
[10011]101                xmldict['institution_bank_id'] = '8'
[9780]102            xmldict['fceokene_split'] = 100 * fceokene_split_amt
[9613]103            xmldict['institution_amt'] = 100 * (
[9780]104                self.context.amount_auth - provider_amt -
105                GATEWAY_AMT - fceokene_split_amt)
[9613]106        elif 'maintenance' in self.context.p_category:
[9780]107            fceokene_split_amt = 0.0
108            provider_amt = 0.0
[9613]109            self.pay_item_id = '8300'
110            xmldict['institution_amt'] = 100 * (
[9780]111                self.context.amount_auth - GATEWAY_AMT)
[12661]112            xmldict['institution_acct'] = "1013780934"
[9129]113            xmldict['institution_bank_id'] = '117'
[9956]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)
[12662]120            xmldict['institution_acct'] = "2010952698"
[9956]121            xmldict['institution_bank_id'] = '8'
122
[8263]123        # Interswitch amount is not part of the xml data
[11919]124        if self.context.p_category in ('schoolfee', 'third_semester'):
[9613]125            xmltext = """<payment_item_detail>
[8263]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" />
[12661]128<item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1013780934" />
[9129]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" />
[8263]130</item_details>
131</payment_item_detail>""" % xmldict
[9613]132
[9956]133        else:
[9613]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
[8263]140        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9780]141        self.context.provider_amt = provider_amt
142        self.context.gateway_amt = GATEWAY_AMT
143        self.context.thirdparty_amt = fceokene_split_amt
[7894]144        return
145
[11635]146class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[8256]147    """ View which sends a POST request to the Interswitch
148    CollegePAY payment gateway.
149    """
150    grok.context(ICustomApplicantOnlinePayment)
[8263]151    action = POST_ACTION
152    site_name = SITE_NAME
153    currency = CURRENCY
[8644]154    pay_item_id = '8303'
[8263]155    product_id = PRODUCT_ID
[8256]156
157    def update(self):
[12976]158        error = self.init_update()
159        if error:
160            self.flash(error, type='danger')
161            self.redirect(self.url(self.context, '@@index'))
162            return
[8256]163        xmldict = {}
[8263]164        # Provider data
[9780]165        provider_amt = 500.0
[11635]166        xmldict['detail_ref'] = self.context.p_id
[9780]167        xmldict['provider_amt'] = 100 * provider_amt
[8263]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
[10528]172        if getattr(
173            self.applicant.__parent__, 'prefix', None) in ('pude', 'putme'):
[12662]174            xmldict['institution_acct'] = '2010952698'
[10528]175            xmldict['institution_bank_id'] = '8'
176        else:
[12661]177            xmldict['institution_acct'] = '1013780934'
[10528]178            xmldict['institution_bank_id'] = '117'
[9780]179        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
180            provider_amt - GATEWAY_AMT)
[8263]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
[9780]191        self.context.provider_amt = provider_amt
192        self.context.gateway_amt = GATEWAY_AMT
[8256]193        return
194
[7894]195
[11635]196class CustomInterswitchPaymentRequestWebservicePageStudent(
[9784]197    InterswitchPaymentRequestWebservicePageStudent):
[7919]198    """ Request webservice view for the CollegePAY gateway
199    """
[8255]200    grok.context(ICustomStudentOnlinePayment)
[9784]201    product_id = PRODUCT_ID
202    gateway_host = HOST
203    gateway_url = URL
[7919]204
[11635]205class CustomInterswitchPaymentRequestWebservicePageApplicant(
[9784]206    InterswitchPaymentRequestWebservicePageApplicant):
[8256]207    """ Request webservice view for the CollegePAY gateway
208    """
209    grok.context(ICustomApplicantOnlinePayment)
[9784]210    product_id = PRODUCT_ID
211    gateway_host = HOST
212    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.