[15702] | 1 | ## $Id: browser.py 15346 2019-03-06 22:19:56Z 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 | from datetime import datetime |
---|
| 19 | import httplib |
---|
| 20 | import urllib |
---|
| 21 | import urllib2 |
---|
| 22 | import re |
---|
| 23 | from xml.dom.minidom import parseString |
---|
| 24 | import grok |
---|
| 25 | from zope.component import getUtility |
---|
| 26 | from zope.catalog.interfaces import ICatalog |
---|
| 27 | from waeup.kofa.interfaces import IUniversity, CLEARED |
---|
| 28 | from waeup.kofa.payments.interfaces import IPayer |
---|
| 29 | from waeup.kofa.webservices import PaymentDataWebservice |
---|
| 30 | from waeup.kofa.browser.layout import KofaPage, UtilityView |
---|
| 31 | from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent |
---|
| 32 | from waeup.kofa.applicants.viewlets import ApprovePaymentActionButton as APABApplicant |
---|
[15796] | 33 | from waeup.kofa.students.viewlets import PaymentReceiptActionButton as PRABStudent |
---|
| 34 | from waeup.kofa.applicants.viewlets import PaymentReceiptActionButton as PRABApplicant |
---|
[15702] | 35 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 36 | InterswitchActionButtonStudent, |
---|
| 37 | InterswitchRequestWebserviceActionButtonStudent, |
---|
| 38 | InterswitchActionButtonApplicant, |
---|
| 39 | InterswitchRequestWebserviceActionButtonApplicant) |
---|
| 40 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
| 41 | from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment |
---|
| 42 | from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment |
---|
[15755] | 43 | from kofacustom.nigeria.etranzact.tests import HOST, TERMINAL_ID, HTTPS, GATEWAY_AMT |
---|
[15730] | 44 | from kofacustom.nigeria.etranzact.helpers import query_payoutlet |
---|
[15702] | 45 | |
---|
| 46 | grok.templatedir('browser_templates') |
---|
| 47 | |
---|
[15772] | 48 | def payoutlet_module_activated(session, payment): |
---|
[17248] | 49 | if payment.p_currency != 'NGN': |
---|
| 50 | return False |
---|
[15770] | 51 | if payment.r_company and payment.r_company != 'etranzact': |
---|
| 52 | return False |
---|
[15702] | 53 | try: |
---|
| 54 | return getattr(grok.getSite()['configuration'][str(session)], |
---|
| 55 | 'etranzact_payoutlet_enabled', False) |
---|
| 56 | except KeyError: |
---|
[16246] | 57 | session = datetime.now().year |
---|
| 58 | try: |
---|
| 59 | return getattr(grok.getSite()['configuration'][str(session)], |
---|
| 60 | 'etranzact_payoutlet_enabled', False) |
---|
| 61 | except KeyError: |
---|
| 62 | return False |
---|
[15702] | 63 | |
---|
| 64 | class EtranzactEnterPinActionButtonApplicant(APABApplicant): |
---|
| 65 | grok.context(INigeriaApplicantOnlinePayment) |
---|
| 66 | grok.require('waeup.payApplicant') |
---|
| 67 | grok.order(3) |
---|
[15796] | 68 | icon = 'actionicon_pay.png' |
---|
| 69 | text = _('Pay via Etranzact PayOutlet') |
---|
[15702] | 70 | target = 'enterpin' |
---|
| 71 | |
---|
| 72 | @property |
---|
| 73 | def target_url(self): |
---|
[15772] | 74 | if not payoutlet_module_activated( |
---|
[15770] | 75 | self.context.__parent__.__parent__.year, self.context): |
---|
[15702] | 76 | return '' |
---|
[15796] | 77 | if self.context.p_state in ('paid', 'waived', 'scholarship'): |
---|
[15702] | 78 | return '' |
---|
| 79 | return self.view.url(self.view.context, self.target) |
---|
| 80 | |
---|
| 81 | class EtranzactEnterPinActionButtonStudent(APABStudent): |
---|
| 82 | grok.context(INigeriaStudentOnlinePayment) |
---|
| 83 | grok.require('waeup.payStudent') |
---|
[16484] | 84 | grok.order(10) |
---|
[15796] | 85 | icon = 'actionicon_pay.png' |
---|
| 86 | text = _('Pay via Etranzact PayOutlet') |
---|
[15702] | 87 | target = 'enterpin' |
---|
| 88 | |
---|
| 89 | @property |
---|
| 90 | def target_url(self): |
---|
[15772] | 91 | if not payoutlet_module_activated( |
---|
[15770] | 92 | self.context.student.current_session, self.context): |
---|
[15702] | 93 | return '' |
---|
[15796] | 94 | if self.context.p_state in ('paid', 'waived', 'scholarship'): |
---|
[15702] | 95 | return '' |
---|
| 96 | return self.view.url(self.view.context, self.target) |
---|
| 97 | |
---|
| 98 | class EtranzactEnterPinPageStudent(KofaPage): |
---|
[15755] | 99 | """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageStudent` |
---|
[15702] | 100 | """ |
---|
| 101 | grok.context(INigeriaStudentOnlinePayment) |
---|
| 102 | grok.name('enterpin') |
---|
| 103 | grok.template('enterpin') |
---|
| 104 | grok.require('waeup.payStudent') |
---|
| 105 | |
---|
[16484] | 106 | buttonname = _('Requery now') |
---|
[15796] | 107 | label = _('Requery Etranzact PayOutlet History') |
---|
[15702] | 108 | action = 'query_payoutlet_history' |
---|
| 109 | placeholder = _('Confirmation Number (PIN)') |
---|
[15755] | 110 | gateway_amt = GATEWAY_AMT |
---|
[15702] | 111 | |
---|
| 112 | def update(self): |
---|
[15772] | 113 | if not payoutlet_module_activated( |
---|
[15770] | 114 | self.context.student.current_session, self.context): |
---|
[15974] | 115 | self.flash(_('Forbidden'), type='danger') |
---|
| 116 | self.redirect(self.url(self.context, '@@index')) |
---|
[15702] | 117 | return |
---|
[15755] | 118 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
| 119 | # and add the gateway amount. |
---|
| 120 | if not self.context.r_company: |
---|
| 121 | self.context.net_amt = self.context.amount_auth |
---|
| 122 | self.context.amount_auth += self.gateway_amt |
---|
| 123 | self.context.gateway_amt = self.gateway_amt |
---|
| 124 | self.context.r_company = u'etranzact' |
---|
[15702] | 125 | return |
---|
| 126 | |
---|
[15771] | 127 | class EtranzactEnterPinPageApplicant(KofaPage): |
---|
[15755] | 128 | """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant` |
---|
[15702] | 129 | """ |
---|
| 130 | grok.require('waeup.payApplicant') |
---|
| 131 | grok.context(INigeriaApplicantOnlinePayment) |
---|
[15771] | 132 | grok.name('enterpin') |
---|
| 133 | grok.template('enterpin') |
---|
[15702] | 134 | |
---|
[16484] | 135 | buttonname = _('Requery now') |
---|
[15796] | 136 | label = _('Requery Etranzact PayOutlet History') |
---|
| 137 | action = 'query_payoutlet_history' |
---|
| 138 | placeholder = _('Confirmation Number (PIN)') |
---|
| 139 | gateway_amt = GATEWAY_AMT |
---|
| 140 | |
---|
[15771] | 141 | def update(self): |
---|
[15772] | 142 | if not payoutlet_module_activated( |
---|
[15771] | 143 | self.context.__parent__.__parent__.year, self.context): |
---|
[15974] | 144 | self.flash(_('Forbidden'), type='danger') |
---|
| 145 | self.redirect(self.url(self.context, '@@index')) |
---|
[15771] | 146 | return |
---|
| 147 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
| 148 | # and add the gateway amount. |
---|
| 149 | if not self.context.r_company: |
---|
| 150 | self.context.net_amt = self.context.amount_auth |
---|
| 151 | self.context.amount_auth += self.gateway_amt |
---|
| 152 | self.context.gateway_amt = self.gateway_amt |
---|
| 153 | self.context.r_company = u'etranzact' |
---|
| 154 | return |
---|
| 155 | |
---|
[15796] | 156 | class PayoutletPaymentReceiptActionButtonApplicant(PRABApplicant): |
---|
| 157 | |
---|
| 158 | grok.view(EtranzactEnterPinPageApplicant) |
---|
| 159 | |
---|
| 160 | @property |
---|
| 161 | def target_url(self): |
---|
| 162 | if not self.context.r_company: |
---|
| 163 | return '' |
---|
| 164 | return self.view.url(self.view.context, self.target) |
---|
| 165 | |
---|
| 166 | class PayoutletPaymentReceiptActionButtonStudent(PRABStudent): |
---|
| 167 | |
---|
| 168 | grok.view(EtranzactEnterPinPageStudent) |
---|
| 169 | |
---|
| 170 | @property |
---|
| 171 | def target_url(self): |
---|
| 172 | if not self.context.r_company: |
---|
| 173 | return '' |
---|
| 174 | return self.view.url(self.view.context, self.target) |
---|
| 175 | |
---|
[15702] | 176 | class EtranzactQueryHistoryPageStudent(UtilityView, grok.View): |
---|
| 177 | """ Query history of Etranzact payments |
---|
| 178 | """ |
---|
| 179 | grok.context(INigeriaStudentOnlinePayment) |
---|
| 180 | grok.name('query_payoutlet_history') |
---|
| 181 | grok.require('waeup.payStudent') |
---|
| 182 | terminal_id = TERMINAL_ID |
---|
[15730] | 183 | host = HOST |
---|
| 184 | https = HTTPS |
---|
[15702] | 185 | |
---|
| 186 | def update(self, confirmation_number=None): |
---|
[15772] | 187 | if not payoutlet_module_activated( |
---|
[15770] | 188 | self.context.student.current_session, self.context): |
---|
[15974] | 189 | self.flash(_('Forbidden'), type='danger') |
---|
| 190 | self.redirect(self.url(self.context, '@@index')) |
---|
[15702] | 191 | return |
---|
| 192 | if self.context.p_state == 'paid': |
---|
| 193 | self.flash(_('This ticket has already been paid.')) |
---|
| 194 | return |
---|
| 195 | student = self.context.student |
---|
| 196 | success, msg, log = query_payoutlet( |
---|
[15730] | 197 | self.host, self.terminal_id, confirmation_number, |
---|
| 198 | self.context, self.https) |
---|
[15702] | 199 | student.writeLogMessage(self, log) |
---|
| 200 | if not success: |
---|
[15788] | 201 | self.flash(msg, type="danger") |
---|
[15702] | 202 | return |
---|
| 203 | flashtype, msg, log = self.context.doAfterStudentPayment() |
---|
| 204 | if log is not None: |
---|
| 205 | student.writeLogMessage(self, log) |
---|
| 206 | self.flash(msg, type=flashtype) |
---|
| 207 | return |
---|
| 208 | |
---|
| 209 | def render(self): |
---|
| 210 | self.redirect(self.url(self.context, '@@index')) |
---|
| 211 | return |
---|
| 212 | |
---|
| 213 | class EtranzactQueryHistoryPageApplicant(UtilityView, grok.View): |
---|
| 214 | """ Query history of Etranzact payments |
---|
| 215 | """ |
---|
| 216 | grok.context(INigeriaApplicantOnlinePayment) |
---|
| 217 | grok.name('query_payoutlet_history') |
---|
| 218 | grok.require('waeup.payApplicant') |
---|
| 219 | terminal_id = TERMINAL_ID |
---|
[15730] | 220 | host = HOST |
---|
| 221 | https = HTTPS |
---|
[15702] | 222 | |
---|
| 223 | def update(self, confirmation_number=None): |
---|
[15772] | 224 | if not payoutlet_module_activated( |
---|
[15770] | 225 | self.context.__parent__.__parent__.year, self.context): |
---|
[15974] | 226 | self.flash(_('Forbidden'), type='danger') |
---|
| 227 | self.redirect(self.url(self.context, '@@index')) |
---|
[15702] | 228 | return |
---|
| 229 | if self.context.p_state == 'paid': |
---|
| 230 | self.flash(_('This ticket has already been paid.')) |
---|
| 231 | return |
---|
| 232 | applicant = self.context.__parent__ |
---|
| 233 | success, msg, log = query_payoutlet( |
---|
[15730] | 234 | self.host, self.terminal_id, confirmation_number, |
---|
| 235 | self.context, self.https) |
---|
[15702] | 236 | applicant.writeLogMessage(self, log) |
---|
| 237 | if not success: |
---|
| 238 | self.flash(msg) |
---|
| 239 | return |
---|
| 240 | flashtype, msg, log = self.context.doAfterApplicantPayment() |
---|
| 241 | if log is not None: |
---|
| 242 | applicant.writeLogMessage(self, log) |
---|
| 243 | self.flash(msg, type=flashtype) |
---|
| 244 | return |
---|
| 245 | |
---|
| 246 | def render(self): |
---|
| 247 | self.redirect(self.url(self.context, '@@index')) |
---|
| 248 | return |
---|