[7250] | 1 | ## $Id: payment.py 15395 2019-04-23 15:44:31Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 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 | """ |
---|
[8260] | 19 | Application fee payment. |
---|
[7250] | 20 | """ |
---|
| 21 | import grok |
---|
[8431] | 22 | import sys |
---|
| 23 | from hurry.workflow.interfaces import ( |
---|
| 24 | IWorkflowInfo, InvalidTransitionError) |
---|
[7250] | 25 | from zope.component.interfaces import IFactory |
---|
| 26 | from zope.interface import implementedBy |
---|
[8422] | 27 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[7811] | 28 | from waeup.kofa.payments import OnlinePayment |
---|
[10030] | 29 | from waeup.kofa.payments.interfaces import IPayer |
---|
[7811] | 30 | from waeup.kofa.applicants.interfaces import IApplicantOnlinePayment |
---|
[11599] | 31 | from waeup.kofa.applicants.workflow import PAID |
---|
[7811] | 32 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[7250] | 33 | |
---|
| 34 | class ApplicantOnlinePayment(OnlinePayment): |
---|
| 35 | """This is an online payment. |
---|
| 36 | """ |
---|
| 37 | grok.implements(IApplicantOnlinePayment) |
---|
| 38 | grok.provides(IApplicantOnlinePayment) |
---|
| 39 | |
---|
| 40 | def __init__(self): |
---|
| 41 | super(ApplicantOnlinePayment, self).__init__() |
---|
| 42 | return |
---|
| 43 | |
---|
[8453] | 44 | def doAfterApplicantPaymentApproval(self): |
---|
| 45 | """Process applicant after payment was approved. |
---|
| 46 | """ |
---|
[11599] | 47 | if not (self.__parent__.special and self.__parent__.state == PAID): |
---|
[11575] | 48 | wf_info = IWorkflowInfo(self.__parent__) |
---|
| 49 | try: |
---|
| 50 | wf_info.fireTransition('approve') |
---|
| 51 | except InvalidTransitionError: |
---|
| 52 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
[11580] | 53 | return 'danger', msg, log |
---|
[12893] | 54 | log = 'approved: %s' % self.p_id |
---|
[8453] | 55 | msg = _('Payment approved') |
---|
[11580] | 56 | flashtype = 'success' |
---|
| 57 | return flashtype, msg, log |
---|
[8453] | 58 | |
---|
[8422] | 59 | def doAfterApplicantPayment(self): |
---|
| 60 | """Process applicant after payment was made. |
---|
| 61 | """ |
---|
[11599] | 62 | if not (self.__parent__.special and self.__parent__.state == PAID): |
---|
[11575] | 63 | wf_info = IWorkflowInfo(self.__parent__) |
---|
| 64 | try: |
---|
| 65 | wf_info.fireTransition('pay') |
---|
| 66 | except InvalidTransitionError: |
---|
| 67 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
[11580] | 68 | return 'danger', msg, log |
---|
[8428] | 69 | log = 'successful payment: %s' % self.p_id |
---|
[15395] | 70 | msg = _('Payment successfully completed. Kindly submit form for processing.') |
---|
[11580] | 71 | flashtype = 'success' |
---|
| 72 | return flashtype, msg, log |
---|
[8422] | 73 | |
---|
| 74 | def approveApplicantPayment(self): |
---|
| 75 | """Approve payment and process applicant. |
---|
| 76 | """ |
---|
| 77 | if self.p_state == 'paid': |
---|
[11580] | 78 | return 'warning', _('This ticket has already been paid.'), None |
---|
[8422] | 79 | self.approve() |
---|
[8453] | 80 | return self.doAfterApplicantPaymentApproval() |
---|
[8422] | 81 | |
---|
[9984] | 82 | ApplicantOnlinePayment = attrs_to_fields( |
---|
| 83 | ApplicantOnlinePayment, omit=['display_item']) |
---|
[7250] | 84 | |
---|
[10030] | 85 | class Payer(grok.Adapter): |
---|
| 86 | """An adapter to publish applicant data through a simple webservice. |
---|
[8703] | 87 | """ |
---|
| 88 | grok.context(IApplicantOnlinePayment) |
---|
[10030] | 89 | grok.implements(IPayer) |
---|
[8703] | 90 | |
---|
| 91 | @property |
---|
[8708] | 92 | def display_fullname(self): |
---|
[10030] | 93 | "Name of payer" |
---|
[8703] | 94 | return self.context.__parent__.display_fullname |
---|
| 95 | |
---|
[8708] | 96 | @property |
---|
| 97 | def id(self): |
---|
[10030] | 98 | "Id of payer" |
---|
[8708] | 99 | return self.context.__parent__.applicant_id |
---|
| 100 | |
---|
| 101 | @property |
---|
[9733] | 102 | def reg_number(self): |
---|
[10030] | 103 | "Reg number of payer" |
---|
[9506] | 104 | return self.context.__parent__.reg_number |
---|
| 105 | |
---|
| 106 | @property |
---|
[9733] | 107 | def matric_number(self): |
---|
[10392] | 108 | return 'N/A' |
---|
[9733] | 109 | |
---|
| 110 | @property |
---|
[8708] | 111 | def faculty(self): |
---|
[10392] | 112 | return 'N/A' |
---|
[8708] | 113 | |
---|
| 114 | @property |
---|
| 115 | def department(self): |
---|
[10392] | 116 | return 'N/A' |
---|
[8708] | 117 | |
---|
[10914] | 118 | @property |
---|
| 119 | def email(self): |
---|
| 120 | "Email of payer" |
---|
| 121 | return self.context.__parent__.email |
---|
| 122 | |
---|
| 123 | @property |
---|
| 124 | def phone(self): |
---|
| 125 | "Phone number of payer" |
---|
| 126 | return self.context.__parent__.phone |
---|
| 127 | |
---|
| 128 | @property |
---|
| 129 | def current_mode(self): |
---|
| 130 | "Current study mode of payer" |
---|
| 131 | return 'N/A' |
---|
| 132 | |
---|
| 133 | @property |
---|
| 134 | def current_level(self): |
---|
| 135 | "Current level of payer" |
---|
| 136 | return 'N/A' |
---|
| 137 | |
---|
[7250] | 138 | # Applicant online payments must be importable. So we might need a factory. |
---|
| 139 | class ApplicantOnlinePaymentFactory(grok.GlobalUtility): |
---|
| 140 | """A factory for applicant online payments. |
---|
| 141 | """ |
---|
| 142 | grok.implements(IFactory) |
---|
| 143 | grok.name(u'waeup.ApplicantOnlinePayment') |
---|
| 144 | title = u"Create a new online payment.", |
---|
| 145 | description = u"This factory instantiates new online payment instances." |
---|
| 146 | |
---|
| 147 | def __call__(self, *args, **kw): |
---|
| 148 | return ApplicantOnlinePayment() |
---|
| 149 | |
---|
| 150 | def getInterfaces(self): |
---|
[7811] | 151 | return implementedBy(ApplicantOnlinePayment) |
---|