source: main/kofacustom.wdu/trunk/src/kofacustom/wdu/interswitch/browser.py @ 14023

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

Add Interswitch verification components.

  • Property svn:keywords set to Id
File size: 8.4 KB
RevLine 
[10765]1## $Id: browser.py 13592 2016-01-11 09:17:35Z 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
[12478]19import hashlib
[10765]20import grok
[12478]21from waeup.kofa.interfaces import CLEARED
[10765]22from kofacustom.nigeria.interswitch.browser import (
23    InterswitchPaymentRequestWebservicePageApplicant,
[11638]24    InterswitchPaymentRequestWebservicePageStudent,
[13592]25    InterswitchPaymentVerifyWebservicePageApplicant,
26    InterswitchPaymentVerifyWebservicePageStudent,
[11638]27    InterswitchPageStudent, InterswitchPageApplicant,
[10765]28    )
[11940]29from kofacustom.wdu.students.interfaces import ICustomStudentOnlinePayment
30from kofacustom.wdu.applicants.interfaces import ICustomApplicantOnlinePayment
31from kofacustom.wdu.interfaces import MessageFactory as _
[10765]32
[12510]33PRODUCT_ID = '5214'
[12478]34SITE_NAME = 'wdu.waeup.org'
35PROVIDER_ACCT = '0137712635'
36PROVIDER_BANK_ID = '10'
[10765]37PROVIDER_ITEM_NAME = 'BT Education'
[12478]38INSTITUTION_NAME = 'WDU'
[10765]39CURRENCY = '566'
[12478]40GATEWAY_AMT = 300.0
[10765]41
[12510]42#POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
[10765]44
[12510]45HOST = 'webpay.interswitchng.com'
46#HOST = 'stageserv.interswitchng.com'
[12478]47HTTPS = True
48
[12510]49URL = '/paydirect/services/TransactionQueryWs.asmx'
50#URL = '/test_paydirect/services/TransactionQueryWS.asmx'
[12478]51
52httplib.HTTPSConnection.debuglevel = 0
53
[11638]54class CustomInterswitchPageStudent(InterswitchPageStudent):
[10765]55    """ View which sends a POST request to the Interswitch
56    CollegePAY payment gateway.
57    """
58    grok.context(ICustomStudentOnlinePayment)
59    action = POST_ACTION
60    site_name = SITE_NAME
61    currency = CURRENCY
62    product_id = PRODUCT_ID
[12510]63    mac = '2EC91A15F6A0821A06DEC31CC4EF509FDB548A1ABF76BD6FCF620A4D3F1F80D06C362D26CA56D86DC91ADA85CD99B97A6E845B44C730D5749E2B9B339FDC7AF8'
[10765]64
65    def update(self):
[12982]66        error = self.init_update()
67        if error:
68            self.flash(error, type='danger')
69            self.redirect(self.url(self.context, '@@index'))
70            return
[11647]71        student = self.student
72        xmldict = self.xmldict
[10765]73        # Provider data
74        xmldict['detail_ref'] = self.context.p_id
75        xmldict['provider_acct'] = PROVIDER_ACCT
76        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
77        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
[12478]78        xmldict['institution_acct_1'] = '4742014159'
79        xmldict['institution_bank_id_1'] = '47'
80        xmldict['institution_amt_1'] = '0.0'
81        xmldict['institution_acct_2'] = '0029688237'
82        xmldict['institution_bank_id_2'] = '11'
83        xmldict['institution_amt_2'] = '0.0'
84        provider_amt = 4000.0
85        self.pay_item_id = '101'
86        # other charges + tech fee
87        if self.context.student.state == CLEARED:
88            institution_amt_2 = 207500.0 + 1000.0
89        else :
90            institution_amt_2 = 150500.0 + 1000.0
[10765]91        xmldict['provider_amt'] = 100 * provider_amt
[12510]92        xmldict['institution_item_name'] = self.context.category
[10765]93        xmldict['institution_name'] = INSTITUTION_NAME
[12478]94        xmldict['institution_amt_1'] = 100 * (
95            self.context.amount_auth - provider_amt - GATEWAY_AMT - institution_amt_2)
96        xmldict['institution_amt_2'] = 100 * institution_amt_2
97
98        xmltext = """<payment_item_detail>
[10765]99<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
[12478]100<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id_1)s" acct_num="%(institution_acct_1)s" />
101<item_detail item_id="2" item_name="other charges and tech fee" item_amt="%(institution_amt_2)d" bank_id="%(institution_bank_id_2)s" acct_num="%(institution_acct_2)s" />
102<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" />
[10765]103</item_details>
104</payment_item_detail>""" % xmldict
105        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
106        self.context.provider_amt = provider_amt
107        self.context.gateway_amt = GATEWAY_AMT
[12478]108
109        hashargs = (
110            self.context.p_id +
111            PRODUCT_ID +
112            self.pay_item_id +
113            str(int(self.amount_auth)) +
114            self.site_redirect_url +
115            self.mac)
116        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
[10765]117        return
118
119
[12510]120class CustomInterswitchPageApplicant(InterswitchPageApplicant):
121    """ View which sends a POST request to the Interswitch
122    CollegePAY payment gateway.
123    """
124    grok.context(ICustomApplicantOnlinePayment)
125    action = POST_ACTION
126    site_name = SITE_NAME
127    currency = CURRENCY
128    pay_item_id = '103'
129    product_id = PRODUCT_ID
130    mac = '2EC91A15F6A0821A06DEC31CC4EF509FDB548A1ABF76BD6FCF620A4D3F1F80D06C362D26CA56D86DC91ADA85CD99B97A6E845B44C730D5749E2B9B339FDC7AF8'
131
132    def update(self):
[12982]133        error = self.init_update()
134        if error:
135            self.flash(error, type='danger')
136            self.redirect(self.url(self.context, '@@index'))
137            return
[12510]138        xmldict = {}
139        provider_amt = 500.0
140        xmldict['institution_acct'] = '0029688237'
141        xmldict['institution_bank_id'] = '11'
142        xmldict['detail_ref'] = self.context.p_id
143        xmldict['provider_amt'] = 100 * provider_amt
144        xmldict['provider_acct'] = PROVIDER_ACCT
145        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
146        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
147        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
148        xmldict['institution_item_name'] = self.context.category
149        xmldict['institution_name'] = INSTITUTION_NAME
150        # Interswitch amount is not part of the xml data
151        xmltext = """<payment_item_detail>
152<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
153<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" />
154<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" />
155</item_details>
156</payment_item_detail>""" % xmldict
157        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
158        self.context.provider_amt = provider_amt
159        self.context.gateway_amt = GATEWAY_AMT
160
161        hashargs = (
162            self.context.p_id +
163            PRODUCT_ID +
164            self.pay_item_id +
165            str(int(self.amount_auth)) +
166            self.site_redirect_url +
167            self.mac)
168        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
169        return
170
171
[11638]172class CustomInterswitchPaymentRequestWebservicePageStudent(
[10765]173    InterswitchPaymentRequestWebservicePageStudent):
[13592]174    """Request webservice view for the CollegePAY gateway
[10765]175    """
176    grok.context(ICustomStudentOnlinePayment)
177    product_id = PRODUCT_ID
178    gateway_host = HOST
179    gateway_url = URL
180
[13592]181class CustomInterswitchPaymentVerifyWebservicePageStudent(
182    InterswitchPaymentVerifyWebservicePageStudent):
183    """Payment verify view for the CollegePAY gateway
184    """
185    grok.context(ICustomStudentOnlinePayment)
186    product_id = PRODUCT_ID
187    gateway_host = HOST
188    gateway_url = URL
189
[11638]190class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10765]191    InterswitchPaymentRequestWebservicePageApplicant):
[13592]192    """Request webservice view for the CollegePAY gateway
[10765]193    """
194    grok.context(ICustomApplicantOnlinePayment)
195    product_id = PRODUCT_ID
196    gateway_host = HOST
[12478]197    gateway_url = URL
[13592]198
199class CustomInterswitchPaymentVerifyWebservicePageApplicant(
200    InterswitchPaymentVerifyWebservicePageApplicant):
201    """Payment verify view for the CollegePAY gateway
202    """
203    grok.context(ICustomApplicantOnlinePayment)
204    product_id = PRODUCT_ID
205    gateway_host = HOST
206    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.