[9781] | 1 | ## $Id: browser.py 12477 2015-01-15 21:01:38Z 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 | import grok |
---|
[11630] | 19 | from zope.component import getUtility |
---|
| 20 | from waeup.kofa.interfaces import IKofaUtils |
---|
| 21 | from waeup.kofa.utils.helpers import to_timezone |
---|
| 22 | from waeup.kofa.browser.layout import UtilityView, KofaPage |
---|
[9781] | 23 | from waeup.kofa.browser.viewlets import ManageActionButton |
---|
[11642] | 24 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[9781] | 25 | from waeup.kofa.students.browser import OnlinePaymentDisplayFormPage as OPDPStudent |
---|
| 26 | from waeup.kofa.applicants.browser import OnlinePaymentDisplayFormPage as OPDPApplicant |
---|
| 27 | from kofacustom.nigeria.interswitch.helpers import ( |
---|
| 28 | query_interswitch, write_payments_log) |
---|
| 29 | from kofacustom.nigeria.payments.interfaces import INigeriaOnlinePayment |
---|
| 30 | from kofacustom.nigeria.students.interfaces import INigeriaStudentOnlinePayment |
---|
| 31 | from kofacustom.nigeria.applicants.interfaces import INigeriaApplicantOnlinePayment |
---|
| 32 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
| 33 | |
---|
| 34 | class InterswitchActionButtonStudent(ManageActionButton): |
---|
| 35 | grok.order(1) |
---|
| 36 | grok.context(INigeriaOnlinePayment) |
---|
| 37 | grok.view(OPDPStudent) |
---|
| 38 | grok.require('waeup.payStudent') |
---|
| 39 | icon = 'actionicon_pay.png' |
---|
| 40 | text = _('CollegePAY') |
---|
| 41 | target = 'goto_interswitch' |
---|
| 42 | |
---|
| 43 | @property |
---|
| 44 | def target_url(self): |
---|
| 45 | if self.context.p_state != 'unpaid': |
---|
| 46 | return '' |
---|
| 47 | return self.view.url(self.view.context, self.target) |
---|
| 48 | |
---|
| 49 | class InterswitchActionButtonApplicant(InterswitchActionButtonStudent): |
---|
| 50 | grok.view(OPDPApplicant) |
---|
| 51 | grok.require('waeup.payApplicant') |
---|
| 52 | |
---|
| 53 | class InterswitchRequestWebserviceActionButtonStudent(ManageActionButton): |
---|
| 54 | grok.order(2) |
---|
| 55 | grok.context(INigeriaOnlinePayment) |
---|
| 56 | grok.view(OPDPStudent) |
---|
| 57 | grok.require('waeup.payStudent') |
---|
| 58 | icon = 'actionicon_call.png' |
---|
| 59 | text = _('Requery CollegePAY') |
---|
| 60 | target = 'request_webservice' |
---|
| 61 | |
---|
| 62 | @property |
---|
| 63 | def target_url(self): |
---|
| 64 | if self.context.p_state == 'paid': |
---|
| 65 | return '' |
---|
| 66 | return self.view.url(self.view.context, self.target) |
---|
| 67 | |
---|
| 68 | class InterswitchRequestWebserviceActionButtonApplicant( |
---|
| 69 | InterswitchRequestWebserviceActionButtonStudent): |
---|
| 70 | grok.view(OPDPApplicant) |
---|
| 71 | grok.require('waeup.payApplicant') |
---|
| 72 | |
---|
| 73 | class InterswitchPaymentRequestWebservicePageStudent(UtilityView, grok.View): |
---|
| 74 | """ Request webservice view for the CollegePAY gateway |
---|
| 75 | """ |
---|
| 76 | grok.context(INigeriaStudentOnlinePayment) |
---|
| 77 | grok.name('request_webservice') |
---|
| 78 | grok.require('waeup.payStudent') |
---|
| 79 | |
---|
| 80 | product_id = None |
---|
| 81 | gateway_host = None |
---|
| 82 | gateway_url = None |
---|
[11915] | 83 | https = False |
---|
[9781] | 84 | |
---|
| 85 | def update(self): |
---|
| 86 | if self.context.p_state == 'paid': |
---|
[11579] | 87 | self.flash(_('This ticket has already been paid.'), type='warning') |
---|
[9781] | 88 | return |
---|
| 89 | student = self.context.student |
---|
| 90 | success, msg, log = query_interswitch( |
---|
[11915] | 91 | self.context, self.product_id, |
---|
| 92 | self.gateway_host, self.gateway_url, |
---|
| 93 | self.https) |
---|
[9781] | 94 | student.writeLogMessage(self, log) |
---|
| 95 | if not success: |
---|
[11579] | 96 | self.flash(msg, type='danger') |
---|
[9781] | 97 | return |
---|
| 98 | write_payments_log(student.student_id, self.context) |
---|
[11581] | 99 | flashtype, msg, log = self.context.doAfterStudentPayment() |
---|
[9781] | 100 | if log is not None: |
---|
| 101 | student.writeLogMessage(self, log) |
---|
[11581] | 102 | self.flash(msg, type=flashtype) |
---|
[9781] | 103 | return |
---|
| 104 | |
---|
| 105 | def render(self): |
---|
| 106 | self.redirect(self.url(self.context, '@@index')) |
---|
| 107 | return |
---|
| 108 | |
---|
| 109 | class InterswitchPaymentRequestWebservicePageApplicant(UtilityView, grok.View): |
---|
| 110 | """ Request webservice view for the CollegePAY gateway |
---|
| 111 | """ |
---|
| 112 | grok.context(INigeriaApplicantOnlinePayment) |
---|
| 113 | grok.name('request_webservice') |
---|
| 114 | grok.require('waeup.payApplicant') |
---|
| 115 | |
---|
| 116 | product_id = None |
---|
| 117 | gateway_host = None |
---|
| 118 | gateway_url = None |
---|
[11915] | 119 | https = False |
---|
[9781] | 120 | |
---|
| 121 | def update(self): |
---|
| 122 | if self.context.p_state == 'paid': |
---|
[11642] | 123 | self.flash(_('This ticket has already been paid.'), type='danger') |
---|
[9781] | 124 | return |
---|
| 125 | applicant = self.context.__parent__ |
---|
| 126 | success, msg, log = query_interswitch( |
---|
[11915] | 127 | self.context, self.product_id, |
---|
| 128 | self.gateway_host, self.gateway_url, |
---|
| 129 | self.https) |
---|
[9781] | 130 | applicant.writeLogMessage(self, log) |
---|
| 131 | if not success: |
---|
[11579] | 132 | self.flash(msg, type='danger') |
---|
[9781] | 133 | return |
---|
| 134 | write_payments_log(applicant.applicant_id, self.context) |
---|
[11581] | 135 | flashtype, msg, log = self.context.doAfterApplicantPayment() |
---|
[9781] | 136 | if log is not None: |
---|
| 137 | applicant.writeLogMessage(self, log) |
---|
[11581] | 138 | self.flash(msg, type=flashtype) |
---|
[9781] | 139 | return |
---|
| 140 | |
---|
| 141 | def render(self): |
---|
| 142 | self.redirect(self.url(self.context, '@@index')) |
---|
| 143 | return |
---|
[11630] | 144 | |
---|
| 145 | class InterswitchPageStudent(KofaPage): |
---|
| 146 | """ View which sends a POST request to the Interswitch |
---|
| 147 | CollegePAY payment gateway. |
---|
| 148 | """ |
---|
| 149 | grok.context(INigeriaOnlinePayment) |
---|
| 150 | grok.name('goto_interswitch') |
---|
| 151 | grok.template('student_goto_interswitch') |
---|
| 152 | grok.require('waeup.payStudent') |
---|
| 153 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 154 | submit_button = _('Submit') |
---|
| 155 | |
---|
[11639] | 156 | action = None |
---|
| 157 | site_name = None |
---|
| 158 | currency = None |
---|
| 159 | pay_item_id = None |
---|
| 160 | product_id = None |
---|
| 161 | xml_data = None |
---|
[12477] | 162 | hashvalue = None |
---|
[11639] | 163 | |
---|
[11642] | 164 | def init_update(self): |
---|
[11630] | 165 | if self.context.p_state == 'paid': |
---|
[11642] | 166 | return _("Payment ticket can't be re-sent to CollegePAY.") |
---|
| 167 | student = self.context.student |
---|
[11630] | 168 | certificate = getattr(student['studycourse'],'certificate',None) |
---|
| 169 | if certificate is None: |
---|
[11642] | 170 | return _("Study course data are incomplete.") |
---|
[11639] | 171 | kofa_utils = getUtility(IKofaUtils) |
---|
[11642] | 172 | student_utils = getUtility(IStudentsUtils) |
---|
| 173 | if student_utils.samePaymentMade(student, self.context.p_category, |
---|
| 174 | self.context.p_item, self.context.p_session): |
---|
| 175 | return _("This type of payment has already been made.") |
---|
[11767] | 176 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[11630] | 177 | xmldict = {} |
---|
| 178 | if certificate is not None: |
---|
| 179 | xmldict['department'] = certificate.__parent__.__parent__.code |
---|
| 180 | xmldict['faculty'] = certificate.__parent__.__parent__.__parent__.code |
---|
| 181 | else: |
---|
| 182 | xmldict['department'] = None |
---|
| 183 | xmldict['faculty'] = None |
---|
[11639] | 184 | self.category = kofa_utils.PAYMENT_CATEGORIES[self.context.p_category] |
---|
| 185 | tz = kofa_utils.tzinfo |
---|
[11630] | 186 | self.local_date_time = to_timezone( |
---|
| 187 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
| 188 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[11642] | 189 | self.student = student |
---|
| 190 | self.xmldict = xmldict |
---|
| 191 | return |
---|
[11630] | 192 | |
---|
[11642] | 193 | def update(self): |
---|
| 194 | error = self.init_update() |
---|
| 195 | if error: |
---|
| 196 | self.flash(error, type='danger') |
---|
| 197 | self.redirect(self.url(self.context, '@@index')) |
---|
| 198 | return |
---|
| 199 | |
---|
[11630] | 200 | class InterswitchPageApplicant(KofaPage): |
---|
| 201 | """ View which sends a POST request to the Interswitch |
---|
| 202 | CollegePAY payment gateway. |
---|
| 203 | """ |
---|
| 204 | grok.context(INigeriaApplicantOnlinePayment) |
---|
| 205 | grok.require('waeup.payApplicant') |
---|
| 206 | grok.template('applicant_goto_interswitch') |
---|
| 207 | grok.name('goto_interswitch') |
---|
| 208 | label = _('Submit data to CollegePAY (Interswitch Payment Gateway)') |
---|
| 209 | submit_button = _('Submit') |
---|
[12477] | 210 | hashvalue = None |
---|
[11630] | 211 | |
---|
[11639] | 212 | action = None |
---|
| 213 | site_name = None |
---|
| 214 | currency = None |
---|
| 215 | pay_item_id = None |
---|
| 216 | product_id = None |
---|
| 217 | xml_data = None |
---|
| 218 | |
---|
[11642] | 219 | def init_update(self): |
---|
[11630] | 220 | if self.context.p_state != 'unpaid': |
---|
[11642] | 221 | return _("Payment ticket can't be re-sent to CollegePAY.") |
---|
[11630] | 222 | if self.context.__parent__.__parent__.expired \ |
---|
| 223 | and self.context.__parent__.__parent__.strict_deadline: |
---|
[11642] | 224 | return _("Payment ticket can't be send to CollegePAY. " |
---|
| 225 | "Application period has expired.") |
---|
[11630] | 226 | self.applicant = self.context.__parent__ |
---|
[11767] | 227 | self.amount_auth = int(100 * self.context.amount_auth) |
---|
[11630] | 228 | self.category = getUtility(IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category] |
---|
| 229 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 230 | self.local_date_time = to_timezone( |
---|
| 231 | self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z") |
---|
| 232 | self.site_redirect_url = self.url(self.context, 'request_webservice') |
---|
[11642] | 233 | return |
---|
| 234 | |
---|
| 235 | def update(self): |
---|
| 236 | error = self.init_update() |
---|
| 237 | if error: |
---|
| 238 | self.flash(error, type='danger') |
---|
| 239 | self.redirect(self.url(self.context, '@@index')) |
---|
[11630] | 240 | return |
---|