source: main/kofacustom.skeleton/trunk/src/kofacustom/skeleton/interswitch/browser.py @ 13055

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

Test if the ticket-expire mechanism works, for both applicant and student payments.

Fix code.

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