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