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

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

Fix exporter and test if the ticket-expire mechanism works, for both applicant and student payments.

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