[7894] | 1 | ## $Id: browser.py 9934 2013-02-06 14:18:21Z 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 | ## |
---|
[7898] | 18 | import httplib |
---|
[7894] | 19 | import grok |
---|
[8281] | 20 | from zope.component import getUtility |
---|
[9785] | 21 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 22 | InterswitchPaymentRequestWebservicePageStudent |
---|
| 23 | ) |
---|
| 24 | from waeup.kofa.browser.layout import KofaPage |
---|
[9285] | 25 | from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils |
---|
[8281] | 26 | from waeup.kofa.utils.helpers import to_timezone |
---|
[8619] | 27 | from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment |
---|
| 28 | from waeup.futminna.interfaces import MessageFactory as _ |
---|
[7894] | 29 | |
---|
[9285] | 30 | PRODUCT_ID = '117' |
---|
[8619] | 31 | SITE_NAME = 'futminna-kofa.waeup.org' |
---|
[9630] | 32 | PROVIDER_ACCT = '0026781725' |
---|
| 33 | PROVIDER_BANK_ID = '31' |
---|
[8263] | 34 | PROVIDER_ITEM_NAME = 'BT Education' |
---|
[8619] | 35 | INSTITUTION_NAME = 'FUTMinna' |
---|
[7894] | 36 | CURRENCY = '566' |
---|
[9785] | 37 | GATEWAY_AMT = 300.0 |
---|
[8401] | 38 | #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' |
---|
[8293] | 39 | #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' |
---|
[8385] | 40 | POST_ACTION = 'https://webpay.interswitchng.com/paydirect/webpay/pay.aspx' |
---|
[8293] | 41 | #POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx' |
---|
[7894] | 42 | |
---|
[8293] | 43 | HOST = 'webpay.interswitchng.com' |
---|
| 44 | #HOST = 'testwebpay.interswitchng.com' |
---|
| 45 | URL = '/paydirect/services/TransactionQueryWs.asmx' |
---|
| 46 | #URL = '/test_paydirect/services/TransactionQueryWs.asmx' |
---|
[7898] | 47 | httplib.HTTPConnection.debuglevel = 0 |
---|
| 48 | |
---|
[8256] | 49 | class InterswitchPageStudent(KofaPage): |
---|
[7894] | 50 | """ View which sends a POST request to the Interswitch |
---|
| 51 | CollegePAY payment gateway. |
---|
| 52 | """ |
---|
[8255] | 53 | grok.context(ICustomStudentOnlinePayment) |
---|
[7894] | 54 | grok.name('goto_interswitch') |
---|
[8256] | 55 | grok.template('student_goto_interswitch') |
---|
[7894] | 56 | grok.require('waeup.payStudent') |
---|
| 57 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 58 | submit_button = _('Submit') |
---|
| 59 | action = POST_ACTION |
---|
| 60 | site_name = SITE_NAME |
---|
| 61 | currency = CURRENCY |
---|
[9288] | 62 | pay_item_id = '' |
---|
[7894] | 63 | product_id = PRODUCT_ID |
---|
| 64 | |
---|
| 65 | def update(self): |
---|
[8256] | 66 | #if self.context.p_state != 'unpaid': |
---|
| 67 | if self.context.p_state == 'paid': |
---|
[7894] | 68 | self.flash(_("Payment ticket can't be re-send to CollegePAY.")) |
---|
| 69 | self.redirect(self.url(self.context, '@@index')) |
---|
| 70 | return |
---|
[8256] | 71 | |
---|
[8744] | 72 | student = self.student = self.context.student |
---|
| 73 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
[8276] | 74 | self.amount_auth = 100 * self.context.amount_auth |
---|
[7894] | 75 | xmldict = {} |
---|
| 76 | if certificate is not None: |
---|
| 77 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
| 78 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
| 79 | else: |
---|
| 80 | xmldict['department'] = None |
---|
| 81 | xmldict['faculty'] = None |
---|
[9630] | 82 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[ |
---|
| 83 | self.context.p_category] |
---|
[8281] | 84 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 85 | self.local_date_time = to_timezone( |
---|
| 86 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
[8256] | 87 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[8263] | 88 | # Provider data |
---|
| 89 | xmldict['detail_ref'] = self.context.p_id |
---|
| 90 | xmldict['provider_acct'] = PROVIDER_ACCT |
---|
| 91 | xmldict['provider_bank_id'] = PROVIDER_BANK_ID |
---|
| 92 | xmldict['provider_item_name'] = PROVIDER_ITEM_NAME |
---|
[9785] | 93 | provider_amt = 1500.0 |
---|
[8263] | 94 | xmldict['provider_amt'] = 100 * provider_amt |
---|
[9285] | 95 | |
---|
[9630] | 96 | # Institution data. Account numbers were changed to the new |
---|
| 97 | # NUBAN 10 digit number system |
---|
[8263] | 98 | xmldict['institution_acct'] = '' |
---|
| 99 | xmldict['institution_bank_id'] = '' |
---|
[8957] | 100 | xmldict['institution_acct'] = '000000000000' |
---|
| 101 | xmldict['institution_bank_id'] = '00' |
---|
[9624] | 102 | xmldict['institution_name'] = INSTITUTION_NAME |
---|
[9292] | 103 | |
---|
| 104 | if self.context.p_category == 'schoolfee': |
---|
| 105 | xmldict['institution_amt'] = 100 * ( |
---|
[9785] | 106 | self.context.amount_auth - provider_amt - GATEWAY_AMT) |
---|
[9934] | 107 | if self.context.student.current_mode in ('pg_ft','pgd_ft'): |
---|
[9292] | 108 | self.pay_item_id = "11703" |
---|
| 109 | elif self.context.student.state == CLEARED and \ |
---|
| 110 | self.context.student.current_level == 100: |
---|
| 111 | self.pay_item_id = "11700" |
---|
| 112 | elif self.context.student.state == CLEARED and \ |
---|
| 113 | self.context.student.current_level == 200: |
---|
| 114 | self.pay_item_id = "11701" |
---|
| 115 | elif self.context.student.state == CLEARED and \ |
---|
| 116 | self.context.student.current_level == 300: |
---|
| 117 | self.pay_item_id = "11702" |
---|
| 118 | elif self.context.student.state == RETURNING and \ |
---|
| 119 | self.context.student.current_level in (100,110): |
---|
| 120 | self.pay_item_id = "11701" |
---|
| 121 | elif self.context.student.state == RETURNING and \ |
---|
| 122 | self.context.student.current_level in (200,210): |
---|
| 123 | self.pay_item_id = "11702" |
---|
| 124 | elif self.context.student.state == RETURNING and \ |
---|
| 125 | self.context.student.current_level in (300,310): |
---|
| 126 | self.pay_item_id = "11703" |
---|
| 127 | elif self.context.student.state == RETURNING and \ |
---|
| 128 | self.context.student.current_level in (400,410,500,510,600): |
---|
| 129 | self.pay_item_id = "11704" |
---|
[7894] | 130 | |
---|
[9292] | 131 | if self.context.student.current_mode == 'jm_ft': |
---|
| 132 | xmldict['institution_acct'] = "000000000000" |
---|
[9386] | 133 | xmldict['institution_bank_id'] = '00' |
---|
[9292] | 134 | elif self.context.student.current_mode == 'pg_ft': |
---|
[9630] | 135 | xmldict['institution_acct'] = "2005910931" |
---|
[9292] | 136 | xmldict['institution_bank_id'] = '8' |
---|
| 137 | elif self.context.student.state == CLEARED and \ |
---|
| 138 | self.context.student.current_level == 100: |
---|
[9630] | 139 | xmldict['institution_acct'] = "0021030851" |
---|
| 140 | xmldict['institution_bank_id'] = '31' |
---|
[9292] | 141 | elif self.context.student.state == CLEARED and \ |
---|
| 142 | self.context.student.current_level == 200: |
---|
[9630] | 143 | xmldict['institution_acct'] = "0005646299" |
---|
| 144 | xmldict['institution_bank_id'] = '47' |
---|
[9292] | 145 | elif self.context.student.state == CLEARED and \ |
---|
| 146 | self.context.student.current_level == 300: |
---|
[9630] | 147 | xmldict['institution_acct'] = "1010500151" |
---|
[9292] | 148 | xmldict['institution_bank_id'] = '117' |
---|
| 149 | elif self.context.student.state == RETURNING and \ |
---|
| 150 | self.context.student.current_level in (100,110): |
---|
[9630] | 151 | xmldict['institution_acct'] = "0005646299" |
---|
| 152 | xmldict['institution_bank_id'] = '47' |
---|
[9292] | 153 | elif self.context.student.current_level in (200,210): |
---|
[9630] | 154 | xmldict['institution_acct'] = "1010500151" |
---|
[9292] | 155 | xmldict['institution_bank_id'] = '117' |
---|
| 156 | elif self.context.student.current_level in (300,310): |
---|
[9630] | 157 | xmldict['institution_acct'] = "2005910931" |
---|
[9292] | 158 | xmldict['institution_bank_id'] = '8' |
---|
| 159 | elif self.context.student.current_level in (400,410,500,510,600): |
---|
[9630] | 160 | xmldict['institution_acct'] = "0027490487" |
---|
[9292] | 161 | xmldict['institution_bank_id'] = '10' |
---|
[8256] | 162 | |
---|
[9292] | 163 | elif self.context.p_category == 'clearance': |
---|
| 164 | xmldict['institution_amt'] = 100 * ( |
---|
[9785] | 165 | self.context.amount_auth - GATEWAY_AMT) |
---|
[9292] | 166 | xmldict['institution_acct'] = "1750005063" |
---|
| 167 | xmldict['institution_bank_id'] = '120' |
---|
| 168 | self.pay_item_id = "11706" |
---|
[9785] | 169 | provider_amt = 0.0 |
---|
[9288] | 170 | |
---|
[9410] | 171 | elif 'maintenance' in self.context.p_category: |
---|
[9409] | 172 | xmldict['institution_amt'] = 100 * ( |
---|
[9785] | 173 | self.context.amount_auth - GATEWAY_AMT) |
---|
[9410] | 174 | xmldict['institution_acct'] = "2018856637" |
---|
| 175 | xmldict['institution_bank_id'] = '8' |
---|
| 176 | self.pay_item_id = "11705" |
---|
[9785] | 177 | provider_amt = 0.0 |
---|
[9409] | 178 | |
---|
[8263] | 179 | # Interswitch amount is not part of the xml data |
---|
[9292] | 180 | if self.context.p_category == 'schoolfee': |
---|
| 181 | xmltext = """<payment_item_detail> |
---|
[9285] | 182 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
[9386] | 183 | <item_detail item_id="1" item_name="School Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
[8263] | 184 | <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" /> |
---|
| 185 | </item_details> |
---|
| 186 | </payment_item_detail>""" % xmldict |
---|
[9409] | 187 | |
---|
[9292] | 188 | elif self.context.p_category == 'clearance': |
---|
| 189 | xmltext = """<payment_item_detail> |
---|
| 190 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
[9386] | 191 | <item_detail item_id="1" item_name="Acceptance Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
[9292] | 192 | </item_details> |
---|
| 193 | </payment_item_detail>""" % xmldict |
---|
[9409] | 194 | |
---|
| 195 | elif 'maintenance' in self.context.p_category: |
---|
| 196 | xmltext = """<payment_item_detail> |
---|
| 197 | <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> |
---|
[9410] | 198 | <item_detail item_id="1" item_name="Hostel Maintenance Fee" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" /> |
---|
[9409] | 199 | </item_details> |
---|
| 200 | </payment_item_detail>""" % xmldict |
---|
| 201 | |
---|
| 202 | |
---|
[8263] | 203 | self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext |
---|
[9785] | 204 | self.context.provider_amt = provider_amt |
---|
| 205 | self.context.gateway_amt = GATEWAY_AMT |
---|
[8256] | 206 | return |
---|
| 207 | |
---|
[9785] | 208 | class InterswitchPaymentRequestWebservicePageStudent( |
---|
| 209 | InterswitchPaymentRequestWebservicePageStudent): |
---|
[7919] | 210 | """ Request webservice view for the CollegePAY gateway |
---|
| 211 | """ |
---|
[8255] | 212 | grok.context(ICustomStudentOnlinePayment) |
---|
[9785] | 213 | product_id = PRODUCT_ID |
---|
| 214 | gateway_host = HOST |
---|
| 215 | gateway_url = URL |
---|