[7250] | 1 | ## $Id: payment.py 8453 2012-05-15 20:29:34Z 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 |
---|
| 29 | from waeup.kofa.applicants.interfaces import IApplicantOnlinePayment |
---|
| 30 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[7250] | 31 | |
---|
| 32 | class ApplicantOnlinePayment(OnlinePayment): |
---|
| 33 | """This is an online payment. |
---|
| 34 | """ |
---|
| 35 | grok.implements(IApplicantOnlinePayment) |
---|
| 36 | grok.provides(IApplicantOnlinePayment) |
---|
| 37 | |
---|
| 38 | def __init__(self): |
---|
| 39 | super(ApplicantOnlinePayment, self).__init__() |
---|
| 40 | return |
---|
| 41 | |
---|
[8453] | 42 | def doAfterApplicantPaymentApproval(self): |
---|
| 43 | """Process applicant after payment was approved. |
---|
| 44 | """ |
---|
| 45 | wf_info = IWorkflowInfo(self.__parent__) |
---|
| 46 | try: |
---|
| 47 | wf_info.fireTransition('approve') |
---|
| 48 | except InvalidTransitionError: |
---|
| 49 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
| 50 | return False, msg, log |
---|
| 51 | log = 'payment approved: %s' % self.p_id |
---|
| 52 | msg = _('Payment approved') |
---|
| 53 | return False, msg, log |
---|
| 54 | |
---|
[8422] | 55 | def doAfterApplicantPayment(self): |
---|
| 56 | """Process applicant after payment was made. |
---|
| 57 | """ |
---|
| 58 | wf_info = IWorkflowInfo(self.__parent__) |
---|
| 59 | try: |
---|
[8453] | 60 | wf_info.fireTransition('pay') |
---|
[8422] | 61 | except InvalidTransitionError: |
---|
[8428] | 62 | msg = log = 'Error: %s' % sys.exc_info()[1] |
---|
| 63 | return False, msg, log |
---|
| 64 | log = 'successful payment: %s' % self.p_id |
---|
| 65 | msg = _('Successful payment') |
---|
| 66 | return False, msg, log |
---|
[8422] | 67 | |
---|
| 68 | def approveApplicantPayment(self): |
---|
| 69 | """Approve payment and process applicant. |
---|
| 70 | """ |
---|
| 71 | if self.p_state == 'paid': |
---|
[8428] | 72 | return False, _('This ticket has already been paid.'), None |
---|
[8422] | 73 | self.approve() |
---|
[8453] | 74 | return self.doAfterApplicantPaymentApproval() |
---|
[8422] | 75 | |
---|
[7250] | 76 | ApplicantOnlinePayment = attrs_to_fields(ApplicantOnlinePayment) |
---|
| 77 | |
---|
| 78 | # Applicant online payments must be importable. So we might need a factory. |
---|
| 79 | class ApplicantOnlinePaymentFactory(grok.GlobalUtility): |
---|
| 80 | """A factory for applicant online payments. |
---|
| 81 | """ |
---|
| 82 | grok.implements(IFactory) |
---|
| 83 | grok.name(u'waeup.ApplicantOnlinePayment') |
---|
| 84 | title = u"Create a new online payment.", |
---|
| 85 | description = u"This factory instantiates new online payment instances." |
---|
| 86 | |
---|
| 87 | def __call__(self, *args, **kw): |
---|
| 88 | return ApplicantOnlinePayment() |
---|
| 89 | |
---|
| 90 | def getInterfaces(self): |
---|
[7811] | 91 | return implementedBy(ApplicantOnlinePayment) |
---|