[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 |
---|
| 33 | from kofacustom.nigeria.interswitch.browser import ( |
---|
| 34 | InterswitchActionButtonStudent, |
---|
| 35 | InterswitchRequestWebserviceActionButtonStudent, |
---|
| 36 | InterswitchActionButtonApplicant, |
---|
| 37 | InterswitchRequestWebserviceActionButtonApplicant) |
---|
| 38 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
| 39 | from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment |
---|
| 40 | from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment |
---|
[15755] | 41 | from kofacustom.nigeria.etranzact.tests import HOST, TERMINAL_ID, HTTPS, GATEWAY_AMT |
---|
[15730] | 42 | from kofacustom.nigeria.etranzact.helpers import query_payoutlet |
---|
[15702] | 43 | |
---|
| 44 | grok.templatedir('browser_templates') |
---|
| 45 | |
---|
[15772] | 46 | def payoutlet_module_activated(session, payment): |
---|
[15770] | 47 | if payment.r_company and payment.r_company != 'etranzact': |
---|
| 48 | return False |
---|
[15702] | 49 | try: |
---|
| 50 | return getattr(grok.getSite()['configuration'][str(session)], |
---|
| 51 | 'etranzact_payoutlet_enabled', False) |
---|
| 52 | except KeyError: |
---|
| 53 | return False |
---|
| 54 | |
---|
| 55 | class EtranzactEnterPinActionButtonApplicant(APABApplicant): |
---|
| 56 | grok.context(INigeriaApplicantOnlinePayment) |
---|
| 57 | grok.require('waeup.payApplicant') |
---|
| 58 | grok.order(3) |
---|
| 59 | icon = 'actionicon_call.png' |
---|
| 60 | text = _('Enter Etranzact PIN') |
---|
| 61 | target = 'enterpin' |
---|
| 62 | |
---|
| 63 | @property |
---|
| 64 | def target_url(self): |
---|
[15772] | 65 | if not payoutlet_module_activated( |
---|
[15770] | 66 | self.context.__parent__.__parent__.year, self.context): |
---|
[15702] | 67 | return '' |
---|
[15730] | 68 | if self.context.p_state in ('paid', 'waived'): |
---|
[15702] | 69 | return '' |
---|
| 70 | return self.view.url(self.view.context, self.target) |
---|
| 71 | |
---|
| 72 | class EtranzactEnterPinActionButtonStudent(APABStudent): |
---|
| 73 | grok.context(INigeriaStudentOnlinePayment) |
---|
| 74 | grok.require('waeup.payStudent') |
---|
| 75 | grok.order(3) |
---|
| 76 | icon = 'actionicon_call.png' |
---|
| 77 | text = _('Enter Etranzact PIN') |
---|
| 78 | target = 'enterpin' |
---|
| 79 | |
---|
| 80 | @property |
---|
| 81 | def target_url(self): |
---|
[15772] | 82 | if not payoutlet_module_activated( |
---|
[15770] | 83 | self.context.student.current_session, self.context): |
---|
[15702] | 84 | return '' |
---|
[15730] | 85 | if self.context.p_state in ('paid', 'waived'): |
---|
[15702] | 86 | return '' |
---|
| 87 | return self.view.url(self.view.context, self.target) |
---|
| 88 | |
---|
| 89 | class EtranzactEnterPinPageStudent(KofaPage): |
---|
[15755] | 90 | """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageStudent` |
---|
[15702] | 91 | """ |
---|
| 92 | grok.context(INigeriaStudentOnlinePayment) |
---|
| 93 | grok.name('enterpin') |
---|
| 94 | grok.template('enterpin') |
---|
| 95 | grok.require('waeup.payStudent') |
---|
| 96 | |
---|
| 97 | buttonname = _('Submit to Etranzact') |
---|
| 98 | label = _('Requery Etranzact History') |
---|
| 99 | action = 'query_payoutlet_history' |
---|
| 100 | placeholder = _('Confirmation Number (PIN)') |
---|
[15755] | 101 | gateway_amt = GATEWAY_AMT |
---|
[15702] | 102 | |
---|
| 103 | def update(self): |
---|
[15772] | 104 | if not payoutlet_module_activated( |
---|
[15770] | 105 | self.context.student.current_session, self.context): |
---|
[15702] | 106 | return |
---|
| 107 | super(EtranzactEnterPinPageStudent, self).update() |
---|
[15755] | 108 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
| 109 | # and add the gateway amount. |
---|
| 110 | if not self.context.r_company: |
---|
| 111 | self.context.net_amt = self.context.amount_auth |
---|
| 112 | self.context.amount_auth += self.gateway_amt |
---|
| 113 | self.context.gateway_amt = self.gateway_amt |
---|
| 114 | self.context.r_company = u'etranzact' |
---|
[15702] | 115 | return |
---|
| 116 | |
---|
[15771] | 117 | class EtranzactEnterPinPageApplicant(KofaPage): |
---|
[15755] | 118 | """Enter confirmation PIN and submit to `EtranzactQueryHistoryPageApplicant` |
---|
[15702] | 119 | """ |
---|
| 120 | grok.require('waeup.payApplicant') |
---|
| 121 | grok.context(INigeriaApplicantOnlinePayment) |
---|
[15771] | 122 | grok.name('enterpin') |
---|
| 123 | grok.template('enterpin') |
---|
[15702] | 124 | |
---|
[15771] | 125 | def update(self): |
---|
[15772] | 126 | if not payoutlet_module_activated( |
---|
[15771] | 127 | self.context.__parent__.__parent__.year, self.context): |
---|
| 128 | return |
---|
| 129 | super(EtranzactEnterPinPageStudent, self).update() |
---|
| 130 | # Already now it becomes an Etranzact payment. We set the net amount |
---|
| 131 | # and add the gateway amount. |
---|
| 132 | if not self.context.r_company: |
---|
| 133 | self.context.net_amt = self.context.amount_auth |
---|
| 134 | self.context.amount_auth += self.gateway_amt |
---|
| 135 | self.context.gateway_amt = self.gateway_amt |
---|
| 136 | self.context.r_company = u'etranzact' |
---|
| 137 | return |
---|
| 138 | |
---|
[15702] | 139 | class EtranzactQueryHistoryPageStudent(UtilityView, grok.View): |
---|
| 140 | """ Query history of Etranzact payments |
---|
| 141 | """ |
---|
| 142 | grok.context(INigeriaStudentOnlinePayment) |
---|
| 143 | grok.name('query_payoutlet_history') |
---|
| 144 | grok.require('waeup.payStudent') |
---|
| 145 | terminal_id = TERMINAL_ID |
---|
[15730] | 146 | host = HOST |
---|
| 147 | https = HTTPS |
---|
[15702] | 148 | |
---|
| 149 | def update(self, confirmation_number=None): |
---|
[15772] | 150 | if not payoutlet_module_activated( |
---|
[15770] | 151 | self.context.student.current_session, self.context): |
---|
[15702] | 152 | return |
---|
| 153 | if self.context.p_state == 'paid': |
---|
| 154 | self.flash(_('This ticket has already been paid.')) |
---|
| 155 | return |
---|
| 156 | student = self.context.student |
---|
| 157 | success, msg, log = query_payoutlet( |
---|
[15730] | 158 | self.host, self.terminal_id, confirmation_number, |
---|
| 159 | self.context, self.https) |
---|
[15702] | 160 | student.writeLogMessage(self, log) |
---|
| 161 | if not success: |
---|
[15788] | 162 | self.flash(msg, type="danger") |
---|
[15702] | 163 | return |
---|
| 164 | flashtype, msg, log = self.context.doAfterStudentPayment() |
---|
| 165 | if log is not None: |
---|
| 166 | student.writeLogMessage(self, log) |
---|
| 167 | self.flash(msg, type=flashtype) |
---|
| 168 | return |
---|
| 169 | |
---|
| 170 | def render(self): |
---|
| 171 | self.redirect(self.url(self.context, '@@index')) |
---|
| 172 | return |
---|
| 173 | |
---|
| 174 | class EtranzactQueryHistoryPageApplicant(UtilityView, grok.View): |
---|
| 175 | """ Query history of Etranzact payments |
---|
| 176 | """ |
---|
| 177 | grok.context(INigeriaApplicantOnlinePayment) |
---|
| 178 | grok.name('query_payoutlet_history') |
---|
| 179 | grok.require('waeup.payApplicant') |
---|
| 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.__parent__.__parent__.year, self.context): |
---|
[15702] | 187 | return |
---|
| 188 | if self.context.p_state == 'paid': |
---|
| 189 | self.flash(_('This ticket has already been paid.')) |
---|
| 190 | return |
---|
| 191 | applicant = self.context.__parent__ |
---|
| 192 | success, msg, log = query_payoutlet( |
---|
[15730] | 193 | self.host, self.terminal_id, confirmation_number, |
---|
| 194 | self.context, self.https) |
---|
[15702] | 195 | applicant.writeLogMessage(self, log) |
---|
| 196 | if not success: |
---|
| 197 | self.flash(msg) |
---|
| 198 | return |
---|
| 199 | flashtype, msg, log = self.context.doAfterApplicantPayment() |
---|
| 200 | if log is not None: |
---|
| 201 | applicant.writeLogMessage(self, log) |
---|
| 202 | self.flash(msg, type=flashtype) |
---|
| 203 | return |
---|
| 204 | |
---|
| 205 | def render(self): |
---|
| 206 | self.redirect(self.url(self.context, '@@index')) |
---|
| 207 | return |
---|