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

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

Adjust to Nigeria package.

  • Property svn:keywords set to Id
File size: 10.0 KB
RevLine 
[10765]1## $Id: browser.py 15773 2019-11-07 17:45:43Z 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 
[15773]63    gateway_amt = GATEWAY_AMT
[10765]64
65    def update(self):
[12979]66        error = self.init_update()
67        if error:
68            self.flash(error, type='danger')
69            self.redirect(self.url(self.context, '@@index'))
70            return
[15773]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'
[11647]78        student = self.student
79        xmldict = self.xmldict
[10765]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
[15728]85        xmldict['institution_acct'] = ''
86        xmldict['institution_bank_id'] = ''
[15773]87        provider_amt = 0.0
[15728]88        self.pay_item_id = ''
[10765]89        # Institution data
[15728]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
[10765]109        xmldict['provider_amt'] = 100 * provider_amt
[12511]110        xmldict['institution_item_name'] = self.context.category
[10765]111        xmldict['institution_name'] = INSTITUTION_NAME
[15773]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
[10765]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
[15773]130        self.amount_auth = int(100 * self.context.amount_auth)
[12479]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()
[10765]139        return
140
[11638]141class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[10765]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
[14276]149    pay_item_id = '0000' # must be provided by Interswitch
[10765]150    product_id = PRODUCT_ID
[15269]151    mac = MAC
[15773]152    gateway_amt = GATEWAY_AMT
[10765]153
154    def update(self):
[12979]155        error = self.init_update()
156        if error:
157            self.flash(error, type='danger')
158            self.redirect(self.url(self.context, '@@index'))
159            return
[15773]160        # Already now it becomes an Interswitch payment. We set the net amount
161        # and add the gateway amount.
162        if not self.context.r_company:
163            self.context.net_amt = self.context.amount_auth
164            self.context.amount_auth += self.gateway_amt
165            self.context.gateway_amt = self.gateway_amt
166            self.context.r_company = u'interswitch'
167        self.amount_auth = int(100 * self.context.amount_auth)
[10765]168        xmldict = {}
[15773]169        provider_amt = 0.0
[15696]170        xmldict['institution_acct'] = '0040484781'
171        xmldict['institution_bank_id'] = '31'
[10765]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
[12511]177        xmldict['institution_item_name'] = self.context.category
[10765]178        xmldict['institution_name'] = INSTITUTION_NAME
[15773]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
[10765]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
[15773]190        self.amount_auth = int(100 * self.context.amount_auth)
[12479]191        hashargs = (
192            self.context.p_id +
193            PRODUCT_ID +
194            self.pay_item_id +
195            str(int(self.amount_auth)) +
196            self.site_redirect_url +
197            self.mac)
198        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
[10765]199        return
200
[11638]201class CustomInterswitchPaymentRequestWebservicePageStudent(
[10765]202    InterswitchPaymentRequestWebservicePageStudent):
[13587]203    """Request webservice view for the CollegePAY gateway
[10765]204    """
205    grok.context(ICustomStudentOnlinePayment)
206    product_id = PRODUCT_ID
207    gateway_host = HOST
208    gateway_url = URL
[15269]209    mac = MAC
[10765]210
[13587]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
[15269]219    mac = MAC
[13587]220
[11638]221class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10765]222    InterswitchPaymentRequestWebservicePageApplicant):
[13587]223    """Request webservice view for the CollegePAY gateway
[10765]224    """
225    grok.context(ICustomApplicantOnlinePayment)
226    product_id = PRODUCT_ID
227    gateway_host = HOST
[12479]228    gateway_url = URL
[15269]229    mac = MAC
[13587]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
[15269]238    gateway_url = URL
239    mac = MAC
Note: See TracBrowser for help on using the repository browser.