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