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