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

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

New single account configuration.

  • Property svn:keywords set to Id
File size: 8.0 KB
RevLine 
[7894]1## $Id: browser.py 13752 2016-02-29 12:33:05Z 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,
[13589]23    InterswitchPaymentVerifyWebservicePageApplicant,
24    InterswitchPaymentVerifyWebservicePageStudent,
[11635]25    InterswitchPageStudent, InterswitchPageApplicant,
[9784]26    )
[8460]27from waeup.fceokene.students.interfaces import ICustomStudentOnlinePayment
28from waeup.fceokene.applicants.interfaces import ICustomApplicantOnlinePayment
29from waeup.fceokene.interfaces import MessageFactory as _
[7894]30
[8644]31PRODUCT_ID = '83'
[8460]32SITE_NAME = 'fceokene-kofa.waeup.org'
[8641]33PROVIDER_ACCT = '0026781725'
34PROVIDER_BANK_ID = '31'
[8263]35PROVIDER_ITEM_NAME = 'BT Education'
[8460]36INSTITUTION_NAME = 'FCEOkene'
[13752]37INSTITUTION_ACCT = '2003670143'
38INSTITUTION_BANK_ID = '8'
[7894]39CURRENCY = '566'
[9780]40GATEWAY_AMT = 150.0
[8401]41#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
[8293]42#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
[8385]43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
[8293]44#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[7894]45
[8293]46HOST = 'webpay.interswitchng.com'
47#HOST = 'testwebpay.interswitchng.com'
48URL = '/paydirect/services/TransactionQueryWs.asmx'
49#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
[7898]50httplib.HTTPConnection.debuglevel = 0
51
[11635]52class CustomInterswitchPageStudent(InterswitchPageStudent):
[7894]53    """ View which sends a POST request to the Interswitch
54    CollegePAY payment gateway.
55    """
[8255]56    grok.context(ICustomStudentOnlinePayment)
[7894]57    action = POST_ACTION
58    site_name = SITE_NAME
59    currency = CURRENCY
[9613]60    pay_item_id = ''
[7894]61    product_id = PRODUCT_ID
62
63    def update(self):
[11649]64        error = self.init_update()
65        if error:
66            self.flash(error, type='danger')
67            self.redirect(self.url(self.context, '@@index'))
68            return
69        student = self.student
70        xmldict = self.xmldict
[8263]71        # Provider data
[9780]72        provider_amt = 1600.0
[8263]73        xmldict['detail_ref'] = self.context.p_id
74        xmldict['provider_acct'] = PROVIDER_ACCT
75        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
76        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[9780]77        xmldict['provider_amt'] = 100 * provider_amt
[8263]78        # Institution data
[13752]79        xmldict['institution_acct'] = INSTITUTION_ACCT
80        xmldict['institution_bank_id'] = INSTITUTION_BANK_ID
[9613]81        xmldict['institution_item_name'] = self.category
82        xmldict['institution_name'] = INSTITUTION_NAME
[11919]83        if self.context.p_category in ('schoolfee', 'third_semester'):
[9613]84            self.pay_item_id = '8302'
85        elif 'maintenance' in self.context.p_category:
[9780]86            provider_amt = 0.0
[9613]87            self.pay_item_id = '8300'
[9956]88        elif self.context.p_category == 'clearance':
89            provider_amt = 0.0
90            self.pay_item_id = '8304'
[13752]91        xmldict['institution_amt'] = 100 * (
92            self.context.amount_auth - GATEWAY_AMT - provider_amt)
93        if provider_amt:
[9613]94            xmltext = """<payment_item_detail>
[8263]95<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
96<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" />
[13752]97<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" />
[8263]98</item_details>
99</payment_item_detail>""" % xmldict
[9956]100        else:
[9613]101            xmltext = """<payment_item_detail>
102<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
103<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" />
104</item_details>
105</payment_item_detail>""" % xmldict
106
[8263]107        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9780]108        self.context.provider_amt = provider_amt
109        self.context.gateway_amt = GATEWAY_AMT
[7894]110        return
111
[11635]112class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[8256]113    """ View which sends a POST request to the Interswitch
114    CollegePAY payment gateway.
115    """
116    grok.context(ICustomApplicantOnlinePayment)
[8263]117    action = POST_ACTION
118    site_name = SITE_NAME
119    currency = CURRENCY
[8644]120    pay_item_id = '8303'
[8263]121    product_id = PRODUCT_ID
[8256]122
123    def update(self):
[12976]124        error = self.init_update()
125        if error:
126            self.flash(error, type='danger')
127            self.redirect(self.url(self.context, '@@index'))
128            return
[8256]129        xmldict = {}
[8263]130        # Provider data
[9780]131        provider_amt = 500.0
[11635]132        xmldict['detail_ref'] = self.context.p_id
[9780]133        xmldict['provider_amt'] = 100 * provider_amt
[8263]134        xmldict['provider_acct'] = PROVIDER_ACCT
135        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
136        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
137        # Institution data
[13752]138        xmldict['institution_acct'] = INSTITUTION_ACCT
139        xmldict['institution_bank_id'] = INSTITUTION_BANK_ID
[9780]140        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
141            provider_amt - GATEWAY_AMT)
[8263]142        xmldict['institution_item_name'] = self.context.p_category
143        xmldict['institution_name'] = INSTITUTION_NAME
144        # Interswitch amount is not part of the xml data
145        xmltext = """<payment_item_detail>
146<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
147<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" />
148<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" />
149</item_details>
150</payment_item_detail>""" % xmldict
151        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
[9780]152        self.context.provider_amt = provider_amt
153        self.context.gateway_amt = GATEWAY_AMT
[8256]154        return
155
[7894]156
[11635]157class CustomInterswitchPaymentRequestWebservicePageStudent(
[9784]158    InterswitchPaymentRequestWebservicePageStudent):
[13589]159    """Request webservice view for the CollegePAY gateway
[7919]160    """
[8255]161    grok.context(ICustomStudentOnlinePayment)
[9784]162    product_id = PRODUCT_ID
163    gateway_host = HOST
164    gateway_url = URL
[7919]165
[13589]166class CustomInterswitchPaymentVerifyWebservicePageStudent(
167    InterswitchPaymentVerifyWebservicePageStudent):
168    """Payment verify view for the CollegePAY gateway
169    """
170    grok.context(ICustomStudentOnlinePayment)
171    product_id = PRODUCT_ID
172    gateway_host = HOST
173    gateway_url = URL
174
[11635]175class CustomInterswitchPaymentRequestWebservicePageApplicant(
[9784]176    InterswitchPaymentRequestWebservicePageApplicant):
[13589]177    """Request webservice view for the CollegePAY gateway
[8256]178    """
179    grok.context(ICustomApplicantOnlinePayment)
[9784]180    product_id = PRODUCT_ID
181    gateway_host = HOST
182    gateway_url = URL
[13589]183
184class CustomInterswitchPaymentVerifyWebservicePageApplicant(
185    InterswitchPaymentVerifyWebservicePageApplicant):
186    """Payment verify view for the CollegePAY gateway
187    """
188    grok.context(ICustomApplicantOnlinePayment)
189    product_id = PRODUCT_ID
190    gateway_host = HOST
191    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.