[10120] | 1 | ## $Id: browser.py 10952 2014-01-21 12:42:23Z 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 | ## |
---|
| 18 | import httplib |
---|
| 19 | import hashlib |
---|
| 20 | import grok |
---|
| 21 | from zope.interface import Interface |
---|
| 22 | from zope.component import getUtility, queryAdapter |
---|
| 23 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 24 | InterswitchPaymentRequestWebservicePageStudent |
---|
| 25 | ) |
---|
| 26 | from waeup.kofa.browser.layout import KofaPage, UtilityView |
---|
| 27 | from waeup.kofa.interfaces import IKofaUtils |
---|
| 28 | from waeup.kofa.utils.helpers import to_timezone |
---|
| 29 | from waeup.aaua.students.interfaces import ICustomStudentOnlinePayment |
---|
| 30 | from waeup.aaua.applicants.interfaces import ICustomApplicantOnlinePayment |
---|
| 31 | from waeup.aaua.interfaces import MessageFactory as _ |
---|
| 32 | |
---|
| 33 | PRODUCT_ID = '105' |
---|
| 34 | SITE_NAME = 'aaua.waeup.org' |
---|
| 35 | PROVIDER_ACCT = '6012015294' |
---|
| 36 | PROVIDER_BANK_ID = '117' |
---|
| 37 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
| 38 | INSTITUTION_NAME = 'AAUA' |
---|
| 39 | CURRENCY = '566' |
---|
| 40 | GATEWAY_AMT = 150.0 |
---|
| 41 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
| 42 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
| 43 | |
---|
| 44 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
| 45 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
| 46 | |
---|
| 47 | HOST = 'webpay.interswitchng.com' |
---|
| 48 | #HOST = 'testwebpay.interswitchng.com' |
---|
| 49 | |
---|
| 50 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 51 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
| 52 | httplib.HTTPConnection.debuglevel = 0 |
---|
| 53 | |
---|
| 54 | def interswitch_img_url(view): |
---|
| 55 | static = view.static |
---|
| 56 | if static is None or static.get( |
---|
| 57 | 'interswitch_verve_mastercard.gif', None) is None: |
---|
| 58 | static = queryAdapter( |
---|
| 59 | view.request, Interface, name='waeup.aaua.interswitch') |
---|
| 60 | return static['interswitch_verve_mastercard.gif']() |
---|
| 61 | |
---|
| 62 | class InterswitchPageStudent(KofaPage): |
---|
| 63 | """ View which sends a POST request to the Interswitch |
---|
| 64 | CollegePAY payment gateway. |
---|
| 65 | """ |
---|
| 66 | grok.context(ICustomStudentOnlinePayment) |
---|
| 67 | grok.name('goto_interswitch') |
---|
| 68 | grok.template('student_goto_interswitch') |
---|
| 69 | grok.require('waeup.payStudent') |
---|
| 70 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 71 | submit_button = _('Submit') |
---|
| 72 | action = POST_ACTION |
---|
| 73 | site_name = SITE_NAME |
---|
| 74 | currency = CURRENCY |
---|
| 75 | product_id = PRODUCT_ID |
---|
[10174] | 76 | #mac = '' |
---|
[10120] | 77 | |
---|
| 78 | def interswitch_img_url(self): |
---|
| 79 | return interswitch_img_url(self) |
---|
| 80 | |
---|
| 81 | def update(self): |
---|
| 82 | #if self.context.p_state != 'unpaid': |
---|
| 83 | if self.context.p_state == 'paid': |
---|
| 84 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
| 85 | self.redirect(self.url(self.context, '@@index')) |
---|
| 86 | return |
---|
| 87 | |
---|
| 88 | student = self.student = self.context.student |
---|
| 89 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
| 90 | self.amount_auth = 100 * self.context.amount_auth |
---|
| 91 | xmldict = {} |
---|
| 92 | if certificate is not None: |
---|
| 93 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
| 94 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
| 95 | else: |
---|
| 96 | xmldict['department'] = None |
---|
| 97 | xmldict['faculty'] = None |
---|
| 98 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
| 99 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 100 | self.local_date_time = to_timezone( |
---|
| 101 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
| 102 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
| 103 | # Provider data |
---|
| 104 | xmldict['detail_ref'] = self.context.p_id |
---|
| 105 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 106 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 107 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
| 108 | # Institution data |
---|
| 109 | xmldict['institution_acct'] = "0000000000000" |
---|
| 110 | xmldict['institution_bank_id'] = '0' |
---|
| 111 | xmldict['institution_item_name'] = self.category |
---|
| 112 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
| 113 | self.pay_item_id = '000' |
---|
[10174] | 114 | if self.context.p_category in ('schoolfee', 'schoolfee_1', 'schoolfee_2'): |
---|
[10120] | 115 | provider_amt = 3000.0 |
---|
[10952] | 116 | if self.context.p_category == 'schoolfee_2': |
---|
| 117 | provider_amt = 0.0 |
---|
[10120] | 118 | xmldict['provider_amt'] = 100 * provider_amt |
---|
| 119 | self.pay_item_id = '10500' |
---|
| 120 | xmldict['institution_amt'] = 100 * ( |
---|
| 121 | self.context.amount_auth - provider_amt - |
---|
| 122 | GATEWAY_AMT) |
---|
[10174] | 123 | if student.current_mode.endswith('_pt'): |
---|
| 124 | xmldict['institution_acct'] = "0321100000000046" |
---|
| 125 | xmldict['institution_bank_id'] = "89" |
---|
| 126 | elif student.current_mode.endswith('_sw'): |
---|
| 127 | xmldict['institution_acct'] = "2461770000021" |
---|
| 128 | xmldict['institution_bank_id'] = "120" |
---|
[10120] | 129 | |
---|
[10174] | 130 | #hashargs = ( |
---|
| 131 | # self.context.p_id + |
---|
| 132 | # PRODUCT_ID + |
---|
| 133 | # self.pay_item_id + |
---|
| 134 | # str(int(self.amount_auth)) + |
---|
| 135 | # self.site_redirect_url + |
---|
| 136 | # self.mac) |
---|
| 137 | #self.hashvalue = hashlib.sha512(hashargs).hexdigest() |
---|
[10120] | 138 | |
---|
| 139 | # Interswitch amount is not part of the xml data |
---|
| 140 | |
---|
[10952] | 141 | if self.context.p_category in ('schoolfee', 'schoolfee_1'): |
---|
[10120] | 142 | xmltext = """<payment_item_detail> |
---|
| 143 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 144 | <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" /> |
---|
| 145 | <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" /> |
---|
| 146 | </item_details> |
---|
| 147 | </payment_item_detail>""" % xmldict |
---|
[10952] | 148 | elif self.context.p_category == 'schoolfee_2': |
---|
| 149 | xmltext = """<payment_item_detail> |
---|
| 150 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
| 151 | <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" /> |
---|
| 152 | </item_details> |
---|
| 153 | </payment_item_detail>""" % xmldict |
---|
[10120] | 154 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
| 155 | self.context.provider_amt = provider_amt |
---|
| 156 | self.context.gateway_amt = GATEWAY_AMT |
---|
| 157 | return |
---|
| 158 | |
---|
| 159 | class InterswitchPaymentRequestWebservicePageStudent( |
---|
| 160 | InterswitchPaymentRequestWebservicePageStudent): |
---|
| 161 | """ Request webservice view for the CollegePAY gateway |
---|
| 162 | """ |
---|
| 163 | grok.context(ICustomStudentOnlinePayment) |
---|
| 164 | product_id = PRODUCT_ID |
---|
| 165 | gateway_host = HOST |
---|
| 166 | gateway_url = URL |
---|