source: main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py @ 12774

Last change on this file since 12774 was 12730, checked in by Henrik Bettermann, 10 years ago

svn propset svn:keywords "Id"

  • Property svn:keywords set to Id
File size: 10.2 KB
RevLine 
[12730]1## $Id: browser.py 12730 2015-03-11 12:01:32Z henrik $
[11846]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
19import hashlib
20import grok
21from zope.interface import Interface
22from zope.component import queryAdapter
23from kofacustom.nigeria.interswitch.browser import (
24    InterswitchPaymentRequestWebservicePageStudent,
25    InterswitchPaymentRequestWebservicePageApplicant,
26    InterswitchPageStudent, InterswitchPageApplicant,
27    )
28from waeup.aaue.students.interfaces import ICustomStudentOnlinePayment
29from waeup.aaue.applicants.interfaces import ICustomApplicantOnlinePayment
30from waeup.aaue.interfaces import MessageFactory as _
31
[11933]32PRODUCT_ID = '5040'
[11846]33SITE_NAME = 'aaue.waeup.org'
34PROVIDER_ACCT = '1010764827'
35PROVIDER_BANK_ID = '117'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'AAU Ekpoma'
38CURRENCY = '566'
[11934]39GATEWAY_AMT = 250.0
[11846]40#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
41#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
42
[11876]43#POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
[11846]44#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
[11933]45#POST_ACTION = 'https://stageserv.interswitchng.com/test_paydirect/pay'
46POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
[11846]47
[11933]48HOST = 'webpay.interswitchng.com'
49#HOST = 'stageserv.interswitchng.com'
[11916]50HTTPS = True
[11846]51
[11933]52URL = '/paydirect/services/TransactionQueryWs.asmx'
53#URL = '/test_paydirect/services/TransactionQueryWS.asmx'
[11917]54httplib.HTTPSConnection.debuglevel = 0
[11846]55
56class CustomInterswitchPageApplicant(InterswitchPageApplicant):
57    """ View which sends a POST request to the Interswitch
58    CollegePAY payment gateway.
59    """
60    grok.context(ICustomApplicantOnlinePayment)
61    action = POST_ACTION
62    site_name = SITE_NAME
63    currency = CURRENCY
[11866]64    pay_item_id = '101'
[11846]65    product_id = PRODUCT_ID
[11933]66    mac = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
[11846]67
68    def update(self):
69
70        super(CustomInterswitchPageApplicant, self).update()
71        xmldict = {}
72        provider_amt = 1000.0
73        xmldict['institution_acct'] = '1010835352'
74        xmldict['institution_bank_id'] = '117'
75        xmldict['detail_ref'] = self.context.p_id
76        xmldict['provider_amt'] = 100 * provider_amt
77        xmldict['provider_acct'] = PROVIDER_ACCT
78        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
79        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
80        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
81        xmldict['institution_item_name'] = self.context.p_category
82        xmldict['institution_name'] = INSTITUTION_NAME
83        # Interswitch amount is not part of the xml data
84        xmltext = """<payment_item_detail>
85<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
86<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" />
87<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" />
88</item_details>
89</payment_item_detail>""" % xmldict
90        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
91        self.context.provider_amt = provider_amt
92        self.context.gateway_amt = GATEWAY_AMT
93
94        hashargs = (
95            self.context.p_id +
96            PRODUCT_ID +
97            self.pay_item_id +
98            str(int(self.amount_auth)) +
99            self.site_redirect_url +
100            self.mac)
101        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
102
103        return
104
[11868]105class CustomInterswitchPageStudent(InterswitchPageStudent):
106    """ View which sends a POST request to the Interswitch
107    CollegePAY payment gateway.
108    """
109    grok.context(ICustomStudentOnlinePayment)
110    action = POST_ACTION
111    site_name = SITE_NAME
112    currency = CURRENCY
113    product_id = PRODUCT_ID
114    pay_item_id = '101'
[12480]115    mac = '74424F1DFECD6058F153148255CDD55E16724B4F380ADB2C63C5D1D7A5675759010C8153DCB930AAF2D38903CBF7CE32B8A6BA2C16BBC46721DF2E3F3E4548E3'
[11846]116
[11868]117    def update(self):
[12729]118        #self.flash('Payment method not yet configured.', type='danger')
119        #self.redirect(self.url(self.context, '@@index'))
120        #return
121        super(CustomInterswitchPageStudent, self).update()
[11868]122        student = self.student
123        xmldict = self.xmldict
[12729]124        xmltext = ""
[11868]125        # Provider data
126        xmldict['detail_ref'] = self.context.p_id
127        xmldict['provider_acct'] = PROVIDER_ACCT
128        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
129        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
130        xmldict['institution_item_name'] = self.category
131        xmldict['institution_name'] = INSTITUTION_NAME
[12729]132
133        if self.context.p_category == 'schoolfee':
134            if student.faccode == 'FCETA':
135                xmldict['institution_acct'] = '1190118227'
136                xmldict['institution_bank_id'] = '123'
137            else:
138                xmldict['institution_bank_id'] = '7'
139                xmldict['institution_acct'] = '1014847058'
140            if student.current_mode == 'found':
141                self.pay_item_id = '103'
142            else:
143                self.pay_item_id = '105'
144            provider_amt = 1900.0
145            joint_venture_amt = 1100.0
146            aaue_share_amt = 1000.0
147            student_union_due_amt = 1000.0
148            student_welfare_assurance_amt = 500.0
149            xmldict['provider_amt'] = 100 * provider_amt
150            xmldict['joint_venture_amt'] = 100 * joint_venture_amt
151            xmldict['aaue_share_amt'] = 100 * aaue_share_amt
152            xmldict['student_union_due_amt'] = 100 * student_union_due_amt
153            xmldict['student_welfare_assurance_amt'] = 100 * student_welfare_assurance_amt
154            xmldict['institution_amt'] = 100 * (
155                self.context.amount_auth
156                - provider_amt
157                - joint_venture_amt
158                - aaue_share_amt
159                - student_union_due_amt
160                - student_welfare_assurance_amt
161                - GATEWAY_AMT)
[11868]162            xmltext = """<payment_item_detail>
163<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
164<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" />
[12729]165<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" />
166<item_detail item_id="3" item_name="Joint Venture" item_amt="%(joint_venture_amt)d" bank_id="51" acct_num="5060023759" />
167<item_detail item_id="4" item_name="AAUE Share" item_amt="%(aaue_share_amt)d" bank_id="51" acct_num="5060020947" />
168<item_detail item_id="5" item_name="Student Union" item_amt="%(student_union_due_amt)d" bank_id="123" acct_num="1006360118" />
169<item_detail item_id="6" item_name="Student Welfare Assurance" item_amt="%(student_welfare_assurance_amt)d" bank_id="31" acct_num="1006407792" />
[11868]170</item_details>
171</payment_item_detail>""" % xmldict
[12729]172        elif self.context.p_category == 'clearance':
173            if student.current_mode == 'found':
174                self.pay_item_id = '102'
175            else:
176                self.pay_item_id = '104'
177            xmldict['institution_acct'] = '1014066976'
178            xmldict['institution_bank_id'] = '117'
179            provider_amt = 0.0
180            gown_fee_amt = 2000.0
181            aaue_fl_fee_amt = 800.0
182            xmldict['gown_fee_amt'] = 100 * gown_fee_amt
183            xmldict['aaue_fl_fee_amt'] = 100 * aaue_fl_fee_amt
184            xmldict['institution_amt'] = 100 * (
185                self.context.amount_auth
186                - gown_fee_amt
187                - aaue_fl_fee_amt
188                - GATEWAY_AMT)
[11868]189            xmltext = """<payment_item_detail>
190<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
191<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" />
[12729]192<item_detail item_id="2" item_name="Matriculation Gown Fee" item_amt="%(gown_fee_amt)d" bank_id="51" acct_num="5060020947" />
193<item_detail item_id="3" item_name="AAU File-Lapel Fee" item_amt="%(aaue_fl_fee_amt)d" bank_id="51" acct_num="4010660109" />
[11868]194</item_details>
195</payment_item_detail>""" % xmldict
[12729]196
197
[11868]198        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
199        self.context.provider_amt = provider_amt
200        self.context.gateway_amt = GATEWAY_AMT
201        hashargs = (
202            self.context.p_id +
203            PRODUCT_ID +
204            self.pay_item_id +
205            str(int(self.amount_auth)) +
206            self.site_redirect_url +
207            self.mac)
208        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
209        return
210
211
[11846]212class CustomInterswitchPaymentRequestWebservicePageApplicant(
213    InterswitchPaymentRequestWebservicePageApplicant):
214    """ Request webservice view for the CollegePAY gateway
215    """
216    grok.context(ICustomApplicantOnlinePayment)
217    product_id = PRODUCT_ID
218    gateway_host = HOST
219    gateway_url = URL
[11916]220    https = HTTPS
[11868]221
222class CustomInterswitchPaymentRequestWebservicePageStudent(
223    InterswitchPaymentRequestWebservicePageStudent):
224    """ Request webservice view for the CollegePAY gateway
225    """
226    grok.context(ICustomStudentOnlinePayment)
227    product_id = PRODUCT_ID
228    gateway_host = HOST
229    gateway_url = URL
[11916]230    https = HTTPS
Note: See TracBrowser for help on using the repository browser.