source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/browser.py @ 14819

Last change on this file since 14819 was 14819, checked in by Henrik Bettermann, 8 years ago

Change provider bank account.

  • Property svn:keywords set to Id
File size: 8.9 KB
RevLine 
[10765]1## $Id: browser.py 14819 2017-08-28 11:23:25Z 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    )
[14716]28from kofacustom.dspg.students.interfaces import ICustomStudentOnlinePayment
29from kofacustom.dspg.applicants.interfaces import ICustomApplicantOnlinePayment
30from kofacustom.dspg.interfaces import MessageFactory as _
[10765]31
[14726]32PRODUCT_ID = '7269' # must be provided by Interswitch
[14749]33SITE_NAME = 'dspg.waeup.org'
[14819]34PROVIDER_ACCT = '1014261520'
35PROVIDER_BANK_ID = '117'
[10765]36PROVIDER_ITEM_NAME = 'BT Education'
[14722]37INSTITUTION_NAME = 'Delta State Polytechnic Ogwashi-Uku'
[10765]38CURRENCY = '566'
[14727]39GATEWAY_AMT = 250.0
[10765]40
[14726]41POST_ACTION = 'https://webpay.interswitchng.com/paydirect/pay'
42#POST_ACTION = 'https://sandbox.interswitchng.com/webpay/pay'
43HOST = 'webpay.interswitchng.com'
44#HOST = 'sandbox.interswitchng.com'
45URL = '/paydirect/api/v1/gettransaction.json'
46#URL = '/webpay/api/v1/gettransaction.json'
[14276]47
[12479]48httplib.HTTPSConnection.debuglevel = 0
49HTTPS = True
[10765]50
[11638]51class CustomInterswitchPageStudent(InterswitchPageStudent):
[10765]52    """ View which sends a POST request to the Interswitch
53    CollegePAY payment gateway.
54    """
55    grok.context(ICustomStudentOnlinePayment)
56    action = POST_ACTION
57    site_name = SITE_NAME
58    currency = CURRENCY
59    product_id = PRODUCT_ID
[14276]60    mac = ''  # must be provided by Interswitch
[10765]61
62    def update(self):
[12979]63        error = self.init_update()
64        if error:
65            self.flash(error, type='danger')
66            self.redirect(self.url(self.context, '@@index'))
67            return
[11647]68        student = self.student
69        xmldict = self.xmldict
[10765]70        # Provider data
71        xmldict['detail_ref'] = self.context.p_id
72        xmldict['provider_acct'] = PROVIDER_ACCT
73        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
74        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
75        # Institution data
76        xmldict['institution_acct'] = '00000000'
77        xmldict['institution_bank_id'] = '00'
78        xmldict['institution_amt'] = '0.0'
[14810]79        provider_amt = 500.0
[14276]80        self.pay_item_id = '0000' # must be provided by Interswitch
[10765]81        xmldict['provider_amt'] = 100 * provider_amt
[12511]82        xmldict['institution_item_name'] = self.context.category
[10765]83        xmldict['institution_name'] = INSTITUTION_NAME
84        xmldict['institution_amt'] = 100 * (
85            self.context.amount_auth - provider_amt - GATEWAY_AMT)
86        # Interswitch amount is not part of the xml data
87        if provider_amt == 0:
88            xmltext = """<payment_item_detail>
89<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
90<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" />
91</item_details>
92</payment_item_detail>""" % xmldict
93        else:
94            xmltext = """<payment_item_detail>
95<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
96<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" />
97<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" />
98</item_details>
99</payment_item_detail>""" % xmldict
100        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
101        self.context.provider_amt = provider_amt
102        self.context.gateway_amt = GATEWAY_AMT
[12479]103
104        hashargs = (
105            self.context.p_id +
106            PRODUCT_ID +
107            self.pay_item_id +
108            str(int(self.amount_auth)) +
109            self.site_redirect_url +
110            self.mac)
111        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
[10765]112        return
113
[11638]114class CustomInterswitchPageApplicant(InterswitchPageApplicant):
[10765]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
[14729]122    pay_item_id = '101' # must be provided by Interswitch
[10765]123    product_id = PRODUCT_ID
[14730]124    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
[10765]125
126    def update(self):
[12979]127        error = self.init_update()
128        if error:
129            self.flash(error, type='danger')
130            self.redirect(self.url(self.context, '@@index'))
131            return
[10765]132        xmldict = {}
[14731]133        provider_amt = 500.0
[14810]134        xmldict['institution_acct'] = '00000000'
135        xmldict['institution_bank_id'] = '00'
136        if self.applicant.__parent__.application_category in ('ndft', 'hndft'):
137            xmldict['institution_acct'] = '0010761873'
[14815]138            xmldict['institution_bank_id'] = '11'
[14810]139        elif self.applicant.__parent__.application_category in (
140            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
141            xmldict['institution_acct'] = '1015220292'
142            xmldict['institution_bank_id'] = '117'
[10765]143        xmldict['detail_ref'] = self.context.p_id
144        xmldict['provider_amt'] = 100 * provider_amt
145        xmldict['provider_acct'] = PROVIDER_ACCT
146        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
147        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
148        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
[12511]149        xmldict['institution_item_name'] = self.context.category
[10765]150        xmldict['institution_name'] = INSTITUTION_NAME
151        # Interswitch amount is not part of the xml data
152        xmltext = """<payment_item_detail>
153<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
154<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" />
155<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" />
156</item_details>
157</payment_item_detail>""" % xmldict
158        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
159        self.context.provider_amt = provider_amt
160        self.context.gateway_amt = GATEWAY_AMT
[12479]161
162        hashargs = (
163            self.context.p_id +
164            PRODUCT_ID +
165            self.pay_item_id +
166            str(int(self.amount_auth)) +
167            self.site_redirect_url +
168            self.mac)
169        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
[10765]170        return
171
[11638]172class CustomInterswitchPaymentRequestWebservicePageStudent(
[10765]173    InterswitchPaymentRequestWebservicePageStudent):
[13587]174    """Request webservice view for the CollegePAY gateway
[10765]175    """
176    grok.context(ICustomStudentOnlinePayment)
177    product_id = PRODUCT_ID
178    gateway_host = HOST
179    gateway_url = URL
180
[13587]181class CustomInterswitchPaymentVerifyWebservicePageStudent(
182    InterswitchPaymentVerifyWebservicePageStudent):
183    """Payment verify view for the CollegePAY gateway
184    """
185    grok.context(ICustomStudentOnlinePayment)
186    product_id = PRODUCT_ID
187    gateway_host = HOST
188    gateway_url = URL
189
[11638]190class CustomInterswitchPaymentRequestWebservicePageApplicant(
[10765]191    InterswitchPaymentRequestWebservicePageApplicant):
[13587]192    """Request webservice view for the CollegePAY gateway
[10765]193    """
194    grok.context(ICustomApplicantOnlinePayment)
195    product_id = PRODUCT_ID
196    gateway_host = HOST
[12479]197    gateway_url = URL
[14730]198    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
[13587]199
200class CustomInterswitchPaymentVerifyWebservicePageApplicant(
201    InterswitchPaymentVerifyWebservicePageApplicant):
202    """Payment verify view for the CollegePAY gateway
203    """
204    grok.context(ICustomApplicantOnlinePayment)
205    product_id = PRODUCT_ID
206    gateway_host = HOST
[14722]207    gateway_url = URL
[14730]208    mac = 'D43ED93B7A307B152C7111D04E1F384428057CD1E75428D3A4C5631C28ACB9C8C822A88CA76DEDC5F9A520CF4BFDB2824FF8B207AAFC667DF3CBB13685B66627'
Note: See TracBrowser for help on using the repository browser.