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

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

Configure CustomInterswitchPageApplicant?.

Go live.

  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1## $Id: browser.py 12510 2015-01-23 14:32:45Z 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        super(CustomInterswitchPageStudent, self).update()
65        student = self.student
66        xmldict = self.xmldict
67        # Provider data
68        xmldict['detail_ref'] = self.context.p_id
69        xmldict['provider_acct'] = PROVIDER_ACCT
70        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
71        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
72        xmldict['institution_acct_1'] = '4742014159'
73        xmldict['institution_bank_id_1'] = '47'
74        xmldict['institution_amt_1'] = '0.0'
75        xmldict['institution_acct_2'] = '0029688237'
76        xmldict['institution_bank_id_2'] = '11'
77        xmldict['institution_amt_2'] = '0.0'
78        provider_amt = 4000.0
79        self.pay_item_id = '101'
80        # other charges + tech fee
81        if self.context.student.state == CLEARED:
82            institution_amt_2 = 207500.0 + 1000.0
83        else :
84            institution_amt_2 = 150500.0 + 1000.0
85        xmldict['provider_amt'] = 100 * provider_amt
86        xmldict['institution_item_name'] = self.context.category
87        xmldict['institution_name'] = INSTITUTION_NAME
88        xmldict['institution_amt_1'] = 100 * (
89            self.context.amount_auth - provider_amt - GATEWAY_AMT - institution_amt_2)
90        xmldict['institution_amt_2'] = 100 * institution_amt_2
91
92        xmltext = """<payment_item_detail>
93<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
94<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" />
95<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" />
96<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" />
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
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()
111        return
112
113
114class CustomInterswitchPageApplicant(InterswitchPageApplicant):
115    """ View which sends a POST request to the Interswitch
116    CollegePAY payment gateway.
117    """
118    grok.context(ICustomApplicantOnlinePayment)
119    action = POST_ACTION
120    site_name = SITE_NAME
121    currency = CURRENCY
122    pay_item_id = '103'
123    product_id = PRODUCT_ID
124    mac = '2EC91A15F6A0821A06DEC31CC4EF509FDB548A1ABF76BD6FCF620A4D3F1F80D06C362D26CA56D86DC91ADA85CD99B97A6E845B44C730D5749E2B9B339FDC7AF8'
125
126    def update(self):
127        super(CustomInterswitchPageApplicant, self).update()
128        xmldict = {}
129        provider_amt = 500.0
130        xmldict['institution_acct'] = '0029688237'
131        xmldict['institution_bank_id'] = '11'
132        xmldict['detail_ref'] = self.context.p_id
133        xmldict['provider_amt'] = 100 * provider_amt
134        xmldict['provider_acct'] = PROVIDER_ACCT
135        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
136        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
137        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
138        xmldict['institution_item_name'] = self.context.category
139        xmldict['institution_name'] = INSTITUTION_NAME
140        # Interswitch amount is not part of the xml data
141        xmltext = """<payment_item_detail>
142<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
143<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" />
144<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" />
145</item_details>
146</payment_item_detail>""" % xmldict
147        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
148        self.context.provider_amt = provider_amt
149        self.context.gateway_amt = GATEWAY_AMT
150
151        hashargs = (
152            self.context.p_id +
153            PRODUCT_ID +
154            self.pay_item_id +
155            str(int(self.amount_auth)) +
156            self.site_redirect_url +
157            self.mac)
158        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
159        return
160
161
162class CustomInterswitchPaymentRequestWebservicePageStudent(
163    InterswitchPaymentRequestWebservicePageStudent):
164    """ Request webservice view for the CollegePAY gateway
165    """
166    grok.context(ICustomStudentOnlinePayment)
167    product_id = PRODUCT_ID
168    gateway_host = HOST
169    gateway_url = URL
170    https = HTTPS
171
172class CustomInterswitchPaymentRequestWebservicePageApplicant(
173    InterswitchPaymentRequestWebservicePageApplicant):
174    """ Request webservice view for the CollegePAY gateway
175    """
176    grok.context(ICustomApplicantOnlinePayment)
177    product_id = PRODUCT_ID
178    gateway_host = HOST
179    gateway_url = URL
180    https = HTTPS
Note: See TracBrowser for help on using the repository browser.