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

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

Go live.

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