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