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

Last change on this file since 11645 was 11635, checked in by Henrik Bettermann, 11 years ago

Use base classes InterswitchPageApplicant? and InterswitchPageStudent? from kofacustom.nigeria.

  • Property svn:keywords set to Id
File size: 9.0 KB
RevLine 
[7894]1## $Id: browser.py 11635 2014-05-13 10:20: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
[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):
[11635]60        student, certificate, xmldict = super(
61            CustomInterswitchPageStudent, self).update()
[8263]62        # Provider data
[9780]63        provider_amt = 1600.0
[8263]64        xmldict['detail_ref'] = self.context.p_id
65        xmldict['provider_acct'] = PROVIDER_ACCT
66        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
67        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[9780]68        xmldict['provider_amt'] = 100 * provider_amt
[8263]69        # Institution data
[9780]70        fceokene_split_amt = 1400.0
[9613]71        xmldict['fceokene_acct'] = "0000000000000"
72        xmldict['institution_bank_id'] = '0'
73        xmldict['institution_item_name'] = self.category
74        xmldict['institution_name'] = INSTITUTION_NAME
75        if self.context.p_category == 'schoolfee':
76            self.pay_item_id = '8302'
[9943]77            if student.current_mode in ('nce_sw','prence',):
[9951]78                xmldict['institution_acct'] = "1012044194"
[9613]79                xmldict['institution_bank_id'] = '117'
[9943]80            elif student.current_mode in ('nce_ft',) and \
[9613]81                student['studycourse'].current_verdict == 'O':
[9951]82                xmldict['institution_acct'] = "1012044015"
[9613]83                xmldict['institution_bank_id'] = '117'
[9943]84            elif student.current_mode in ('nce_ft',):
[9951]85                xmldict['institution_acct'] = "1012044015"
[9613]86                xmldict['institution_bank_id'] = '117'
87            elif student.current_mode in ('pd_ft',):
[9951]88                xmldict['institution_acct'] = "1012415659"
[9613]89                xmldict['institution_bank_id'] = '117'
[10011]90            #undergraduate schoolfee added
91            elif student.current_mode in ('ug_ft',):
92                xmldict['institution_acct'] = "2003670143"
93                xmldict['institution_bank_id'] = '8'
[9780]94            xmldict['fceokene_split'] = 100 * fceokene_split_amt
[9613]95            xmldict['institution_amt'] = 100 * (
[9780]96                self.context.amount_auth - provider_amt -
97                GATEWAY_AMT - fceokene_split_amt)
[9613]98        elif 'maintenance' in self.context.p_category:
[9780]99            fceokene_split_amt = 0.0
100            provider_amt = 0.0
[9613]101            self.pay_item_id = '8300'
102            xmldict['institution_amt'] = 100 * (
[9780]103                self.context.amount_auth - GATEWAY_AMT)
[9613]104            xmldict['institution_acct'] = "1012044132"
[9129]105            xmldict['institution_bank_id'] = '117'
[9956]106        elif self.context.p_category == 'clearance':
107            fceokene_split_amt = 0.0
108            provider_amt = 0.0
109            self.pay_item_id = '8304'
110            xmldict['institution_amt'] = 100 * (
111                self.context.amount_auth - GATEWAY_AMT)
112            xmldict['institution_acct'] = "2003670143"
113            xmldict['institution_bank_id'] = '8'
114
[8263]115        # Interswitch amount is not part of the xml data
[9613]116        if self.context.p_category == 'schoolfee':
117            xmltext = """<payment_item_detail>
[8263]118<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
119<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" />
[9951]120<item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="1012044039" />
[9129]121<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]122</item_details>
123</payment_item_detail>""" % xmldict
[9613]124
[9956]125        else:
[9613]126            xmltext = """<payment_item_detail>
127<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
128<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" />
129</item_details>
130</payment_item_detail>""" % xmldict
131
[8263]132        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9780]133        self.context.provider_amt = provider_amt
134        self.context.gateway_amt = GATEWAY_AMT
135        self.context.thirdparty_amt = fceokene_split_amt
[7894]136        return
137
[11635]138class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[8256]139    """ View which sends a POST request to the Interswitch
140    CollegePAY payment gateway.
141    """
142    grok.context(ICustomApplicantOnlinePayment)
[8263]143    action = POST_ACTION
144    site_name = SITE_NAME
145    currency = CURRENCY
[8644]146    pay_item_id = '8303'
[8263]147    product_id = PRODUCT_ID
[8256]148
149    def update(self):
[11635]150        super(CustomInterswitchPageApplicant, self).update()
[8256]151        xmldict = {}
[8263]152        # Provider data
[9780]153        provider_amt = 500.0
[11635]154        xmldict['detail_ref'] = self.context.p_id
[9780]155        xmldict['provider_amt'] = 100 * provider_amt
[8263]156        xmldict['provider_acct'] = PROVIDER_ACCT
157        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
158        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
159        # Institution data
[10528]160        if getattr(
161            self.applicant.__parent__, 'prefix', None) in ('pude', 'putme'):
162            xmldict['institution_acct'] = '2003670143'
163            xmldict['institution_bank_id'] = '8'
164        else:
165            xmldict['institution_acct'] = '1012445289'
166            xmldict['institution_bank_id'] = '117'
[9780]167        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
168            provider_amt - GATEWAY_AMT)
[8263]169        xmldict['institution_item_name'] = self.context.p_category
170        xmldict['institution_name'] = INSTITUTION_NAME
171        # Interswitch amount is not part of the xml data
172        xmltext = """<payment_item_detail>
173<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
174<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" />
175<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" />
176</item_details>
177</payment_item_detail>""" % xmldict
178        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9780]179        self.context.provider_amt = provider_amt
180        self.context.gateway_amt = GATEWAY_AMT
[8256]181        return
182
[7894]183
[11635]184class CustomInterswitchPaymentRequestWebservicePageStudent(
[9784]185    InterswitchPaymentRequestWebservicePageStudent):
[7919]186    """ Request webservice view for the CollegePAY gateway
187    """
[8255]188    grok.context(ICustomStudentOnlinePayment)
[9784]189    product_id = PRODUCT_ID
190    gateway_host = HOST
191    gateway_url = URL
[7919]192
[11635]193class CustomInterswitchPaymentRequestWebservicePageApplicant(
[9784]194    InterswitchPaymentRequestWebservicePageApplicant):
[8256]195    """ Request webservice view for the CollegePAY gateway
196    """
197    grok.context(ICustomApplicantOnlinePayment)
[9784]198    product_id = PRODUCT_ID
199    gateway_host = HOST
200    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.