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