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

Last change on this file since 11110 was 10765, checked in by Henrik Bettermann, 11 years ago

Fill trunk.

  • Property svn:keywords set to Id
File size: 9.2 KB
RevLine 
[10765]1## $Id: browser.py 10765 2013-11-19 12:57:15Z 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 grok
20from zope.component import getUtility
21from kofacustom.nigeria.interswitch.browser import (
22    InterswitchPaymentRequestWebservicePageApplicant,
23    InterswitchPaymentRequestWebservicePageStudent
24    )
25from waeup.kofa.browser.layout import KofaPage
26from waeup.kofa.interfaces import IKofaUtils
27from waeup.kofa.utils.helpers import to_timezone
28from kofacustom.skeleton.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.skeleton.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.skeleton.interfaces import MessageFactory as _
31
32PRODUCT_ID = '57'
33SITE_NAME = 'skeleton-kofa.waeup.org'
34PROVIDER_ACCT = '00000000'
35PROVIDER_BANK_ID = '00'
36PROVIDER_ITEM_NAME = 'BT Education'
37INSTITUTION_NAME = 'Skeleton'
38CURRENCY = '566'
39GATEWAY_AMT = 150.0
40#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
41#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
42POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx'
43#POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
44
45HOST = 'webpay.interswitchng.com'
46#HOST = 'testwebpay.interswitchng.com'
47URL = '/paydirect/services/TransactionQueryWs.asmx'
48#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
49httplib.HTTPConnection.debuglevel = 0
50
51class InterswitchPageStudent(KofaPage):
52    """ View which sends a POST request to the Interswitch
53    CollegePAY payment gateway.
54    """
55    grok.context(ICustomStudentOnlinePayment)
56    grok.name('goto_interswitch')
57    grok.template('student_goto_interswitch')
58    grok.require('waeup.payStudent')
59    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
60    submit_button = _('Submit')
61    action = POST_ACTION
62    site_name = SITE_NAME
63    currency = CURRENCY
64    product_id = PRODUCT_ID
65
66    def update(self):
67        #if self.context.p_state != 'unpaid':
68        if self.context.p_state == 'paid':
69            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
70            self.redirect(self.url(self.context, '@@index'))
71            return
72
73        student = self.student = self.context.student
74        certificate = getattr(student['studycourse'],'certificate',None)
75        if certificate is None:
76            self.flash(_("Study course data are incomplete."))
77            self.redirect(self.url(self.context, '@@index'))
78            return
79        self.amount_auth = 100 * self.context.amount_auth
80        xmldict = {}
81        if certificate is not None:
82            xmldict['department'] = certificate.__parent__.__parent__.code
83            xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code
84        else:
85            xmldict['department'] = None
86            xmldict['faculty'] = None
87        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
88        tz = getUtility(IKofaUtils).tzinfo
89        self.local_date_time = to_timezone(
90            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
91        self.site_redirect_url = self.url(self.context, 'request_webservice')
92        # Provider data
93        xmldict['detail_ref'] = self.context.p_id
94        xmldict['provider_acct'] = PROVIDER_ACCT
95        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
96        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
97        # Institution data
98        xmldict['institution_acct'] = '00000000'
99        xmldict['institution_bank_id'] = '00'
100        xmldict['institution_amt'] = '0.0'
101        provider_amt = 0.0
102        self.pay_item_id = '0000'
103        xmldict['provider_amt'] = 100 * provider_amt
104        xmldict['institution_item_name'] = self.category
105        xmldict['institution_name'] = INSTITUTION_NAME
106        xmldict['institution_amt'] = 100 * (
107            self.context.amount_auth - provider_amt - GATEWAY_AMT)
108        # Interswitch amount is not part of the xml data
109        if provider_amt == 0:
110            xmltext = """<payment_item_detail>
111<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
112<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" />
113</item_details>
114</payment_item_detail>""" % xmldict
115        else:
116            xmltext = """<payment_item_detail>
117<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
118<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" />
119<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" />
120</item_details>
121</payment_item_detail>""" % xmldict
122        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
123        self.context.provider_amt = provider_amt
124        self.context.gateway_amt = GATEWAY_AMT
125        return
126
127class InterswitchPageApplicant(KofaPage):
128    """ View which sends a POST request to the Interswitch
129    CollegePAY payment gateway.
130    """
131    grok.context(ICustomApplicantOnlinePayment)
132    grok.require('waeup.payApplicant')
133    grok.template('applicant_goto_interswitch')
134    grok.name('goto_interswitch')
135    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
136    submit_button = _('Submit')
137    action = POST_ACTION
138    site_name = SITE_NAME
139    currency = CURRENCY
140    pay_item_id = '0000'
141    product_id = PRODUCT_ID
142
143    def update(self):
144        if self.context.p_state != 'unpaid':
145            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
146            self.redirect(self.url(self.context, '@@index'))
147            return
148        if self.context.__parent__.__parent__.expired \
149            and self.context.__parent__.__parent__.strict_deadline:
150            self.flash(_("Payment ticket can't be send to CollegePAY. "
151                         "Application period has expired."))
152            self.redirect(self.url(self.context, '@@index'))
153            return
154        self.applicant = self.context.__parent__
155        self.amount_auth = 100 * self.context.amount_auth
156        xmldict = {}
157        self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
158        tz = getUtility(IKofaUtils).tzinfo
159        self.local_date_time = to_timezone(
160            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
161        self.site_redirect_url = self.url(self.context, 'request_webservice')
162        provider_amt = 400.0
163        xmldict['institution_acct'] = '00000000000'
164        xmldict['institution_bank_id'] = '00'
165        xmldict['detail_ref'] = self.context.p_id
166        xmldict['provider_amt'] = 100 * provider_amt
167        xmldict['provider_acct'] = PROVIDER_ACCT
168        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
169        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
170        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
171        xmldict['institution_item_name'] = self.context.p_category
172        xmldict['institution_name'] = INSTITUTION_NAME
173        # Interswitch amount is not part of the xml data
174        xmltext = """<payment_item_detail>
175<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
176<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" />
177<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" />
178</item_details>
179</payment_item_detail>""" % xmldict
180        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
181        self.context.provider_amt = provider_amt
182        self.context.gateway_amt = GATEWAY_AMT
183        return
184
185class InterswitchPaymentRequestWebservicePageStudent(
186    InterswitchPaymentRequestWebservicePageStudent):
187    """ Request webservice view for the CollegePAY gateway
188    """
189    grok.context(ICustomStudentOnlinePayment)
190    product_id = PRODUCT_ID
191    gateway_host = HOST
192    gateway_url = URL
193
194class InterswitchPaymentRequestWebservicePageApplicant(
195    InterswitchPaymentRequestWebservicePageApplicant):
196    """ Request webservice view for the CollegePAY gateway
197    """
198    grok.context(ICustomApplicantOnlinePayment)
199    product_id = PRODUCT_ID
200    gateway_host = HOST
201    gateway_url = URL
Note: See TracBrowser for help on using the repository browser.