source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/interswitch/browser.py @ 15783

Last change on this file since 15783 was 15783, checked in by Henrik Bettermann, 5 years ago

Configure application payments.

  • Property svn:keywords set to Id
File size: 10.0 KB
Line 
1## $Id: browser.py 15783 2019-11-08 12:19:54Z 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 kofacustom.nigeria.interswitch.browser import (
22    InterswitchPaymentRequestWebservicePageApplicant,
23    InterswitchPaymentRequestWebservicePageStudent,
24    InterswitchPaymentVerifyWebservicePageApplicant,
25    InterswitchPaymentVerifyWebservicePageStudent,
26    InterswitchPageStudent, InterswitchPageApplicant,
27    )
28from kofacustom.iuokada.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.iuokada.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.iuokada.interfaces import MessageFactory as _
31
32PRODUCT_ID = '7922'
33SITE_NAME = 'iuokada-kofa.waeup.org'
34PROVIDER_ACCT = '0773411069'
35PROVIDER_BANK_ID = '31'
36PROVIDER_ITEM_NAME = 'WAeAC'
37INSTITUTION_NAME = 'IUOkada'
38CURRENCY = '566'
39GATEWAY_AMT = 250.0
40#MAC = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3' # must be provided by Interswitch
41MAC = '4D8723F33D728BE3F4A77B2DFB3F57B0BCF2DD818759D54A87B2A60874067F28D94F2B91E29BFB884F920F48E0973D826835A8F2D6F74220C64EDE4DE00E45AA'
42
43POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
44#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
45HOST = 'webpay.interswitchng.com'
46#HOST = 'sandbox.interswitchng.com'
47URL = '/paydirect/api/v1/gettransaction.json'
48#URL = '/webpay/api/v1/gettransaction.json'
49
50httplib.HTTPSConnection.debuglevel = 0
51HTTPS = True
52
53class CustomInterswitchPageStudent(InterswitchPageStudent):
54    """ View which sends a POST request to the Interswitch
55    CollegePAY payment gateway.
56    """
57    grok.context(ICustomStudentOnlinePayment)
58    action = POST_ACTION
59    site_name = SITE_NAME
60    currency = CURRENCY
61    product_id = PRODUCT_ID
62    mac = MAC 
63    gateway_amt = GATEWAY_AMT
64
65    def update(self):
66        error = self.init_update()
67        if error:
68            self.flash(error, type='danger')
69            self.redirect(self.url(self.context, '@@index'))
70            return
71        # Already now it becomes an Interswitch payment. We set the net amount
72        # and add the gateway amount.
73        if not self.context.r_company:
74            self.context.net_amt = self.context.amount_auth
75            self.context.amount_auth += self.gateway_amt
76            self.context.gateway_amt = self.gateway_amt
77            self.context.r_company = u'interswitch'
78        student = self.student
79        xmldict = self.xmldict
80        # Provider data
81        xmldict['detail_ref'] = self.context.p_id
82        xmldict['provider_acct'] = PROVIDER_ACCT
83        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
84        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
85        xmldict['institution_acct'] = ''
86        xmldict['institution_bank_id'] = ''
87        provider_amt = 0.0
88        self.pay_item_id = ''
89        # Institution data
90        if self.context.p_category in (
91            'schoolfee', 'schoolfee40', 'secondinstal'):
92            xmldict['institution_acct'] = '1011005811'
93            xmldict['institution_bank_id'] = '117'
94            self.pay_item_id = '101'
95        elif self.context.p_category == 'book':
96            xmldict['institution_acct'] = '1013249587'
97            xmldict['institution_bank_id'] = '117'
98            self.pay_item_id = '103'
99        elif self.context.p_category == 'parentsconsult':
100            xmldict['institution_acct'] = '1012355544'
101            xmldict['institution_bank_id'] = '117'
102            self.pay_item_id = '104'
103        else:
104            xmldict['institution_acct'] = '1011050158'
105            xmldict['institution_bank_id'] = '117'
106            self.pay_item_id = '102'
107        if self.context.p_category == 'registration':
108            provider_amt = 5000.0
109        xmldict['provider_amt'] = 100 * provider_amt
110        xmldict['institution_item_name'] = self.context.category
111        xmldict['institution_name'] = INSTITUTION_NAME
112        xmldict['institution_amt'] = 100 * self.context.net_amt
113        if not self.context.provider_amt:
114            self.context.provider_amt = provider_amt
115            self.context.amount_auth += provider_amt
116        if provider_amt == 0:
117            xmltext = """<payment_item_detail>
118<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
119<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" />
120</item_details>
121</payment_item_detail>""" % xmldict
122        else:
123            xmltext = """<payment_item_detail>
124<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
125<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" />
126<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" />
127</item_details>
128</payment_item_detail>""" % xmldict
129        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
130        self.amount_auth = int(100 * self.context.amount_auth)
131        hashargs = (
132            self.context.p_id +
133            PRODUCT_ID +
134            self.pay_item_id +
135            str(int(self.amount_auth)) +
136            self.site_redirect_url +
137            self.mac)
138        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
139        return
140
141class CustomInterswitchPageApplicant(InterswitchPageApplicant):
142    """ View which sends a POST request to the Interswitch
143    CollegePAY payment gateway.
144    """
145    grok.context(ICustomApplicantOnlinePayment)
146    action = POST_ACTION
147    site_name = SITE_NAME
148    currency = CURRENCY
149    product_id = PRODUCT_ID
150    mac = MAC
151    gateway_amt = GATEWAY_AMT
152
153    def update(self):
154        error = self.init_update()
155        if error:
156            self.flash(error, type='danger')
157            self.redirect(self.url(self.context, '@@index'))
158            return
159        # Already now it becomes an Interswitch payment. We set the net amount
160        # and add the gateway amount.
161        if not self.context.r_company:
162            self.context.net_amt = self.context.amount_auth
163            self.context.amount_auth += self.gateway_amt
164            self.context.gateway_amt = self.gateway_amt
165            self.context.r_company = u'interswitch'
166        self.amount_auth = int(100 * self.context.amount_auth)
167        xmldict = {}
168        provider_amt = 0.0
169        pay_item_id = '101'
170        xmldict['institution_acct'] = '1011005811'
171        xmldict['institution_bank_id'] = '117'
172        xmldict['detail_ref'] = self.context.p_id
173        xmldict['provider_amt'] = 100 * provider_amt
174        xmldict['provider_acct'] = PROVIDER_ACCT
175        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
176        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
177        xmldict['institution_item_name'] = self.context.category
178        xmldict['institution_name'] = INSTITUTION_NAME
179        xmldict['institution_amt'] = 100 * self.context.net_amt
180        if not self.context.provider_amt:
181            self.context.provider_amt = provider_amt
182            self.context.amount_auth += provider_amt
183        xmltext = """<payment_item_detail>
184<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
185<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" />
186<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" />
187</item_details>
188</payment_item_detail>""" % xmldict
189        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
190        self.amount_auth = int(100 * self.context.amount_auth)
191        hashargs = (
192            self.context.p_id +
193            PRODUCT_ID +
194            pay_item_id +
195            str(int(self.amount_auth)) +
196            self.site_redirect_url +
197            self.mac)
198        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
199        return
200
201class CustomInterswitchPaymentRequestWebservicePageStudent(
202    InterswitchPaymentRequestWebservicePageStudent):
203    """Request webservice view for the CollegePAY gateway
204    """
205    grok.context(ICustomStudentOnlinePayment)
206    product_id = PRODUCT_ID
207    gateway_host = HOST
208    gateway_url = URL
209    mac = MAC
210
211class CustomInterswitchPaymentVerifyWebservicePageStudent(
212    InterswitchPaymentVerifyWebservicePageStudent):
213    """Payment verify view for the CollegePAY gateway
214    """
215    grok.context(ICustomStudentOnlinePayment)
216    product_id = PRODUCT_ID
217    gateway_host = HOST
218    gateway_url = URL
219    mac = MAC
220
221class CustomInterswitchPaymentRequestWebservicePageApplicant(
222    InterswitchPaymentRequestWebservicePageApplicant):
223    """Request webservice view for the CollegePAY gateway
224    """
225    grok.context(ICustomApplicantOnlinePayment)
226    product_id = PRODUCT_ID
227    gateway_host = HOST
228    gateway_url = URL
229    mac = MAC
230
231class CustomInterswitchPaymentVerifyWebservicePageApplicant(
232    InterswitchPaymentVerifyWebservicePageApplicant):
233    """Payment verify view for the CollegePAY gateway
234    """
235    grok.context(ICustomApplicantOnlinePayment)
236    product_id = PRODUCT_ID
237    gateway_host = HOST
238    gateway_url = URL
239    mac = MAC
Note: See TracBrowser for help on using the repository browser.