1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the TYPO3 CMS project. |
6
|
|
|
* |
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
9
|
|
|
* of the License, or any later version. |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please read the |
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
13
|
|
|
* |
14
|
|
|
* The TYPO3 project - inspiring people to share! |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
use DERHANSEN\SfEventMgt\Payment\AbstractPayment; |
18
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
19
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* PaymentService |
23
|
|
|
* |
24
|
|
|
* @author Torben Hansen <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class PaymentService |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Returns an array of configured payment methods |
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
public function getPaymentMethods() |
35
|
|
|
{ |
36
|
|
|
$paymentMethods = []; |
37
|
|
|
$configuredPaymentMethods = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sf_event_mgt']['paymentMethods']; |
38
|
|
|
foreach ($configuredPaymentMethods as $key => $value) { |
39
|
|
|
$paymentMethods[$key] = LocalizationUtility::translate('payment.title.' . $key, $value['extkey']); |
40
|
|
|
} |
41
|
|
|
return $paymentMethods; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns an instance of the given payment method |
46
|
|
|
* |
47
|
|
|
* @param string $paymentMethod |
48
|
|
|
* @return null|AbstractPayment |
49
|
|
|
*/ |
50
|
|
|
public function getPaymentInstance($paymentMethod) |
51
|
|
|
{ |
52
|
|
|
$paymentInstance = null; |
53
|
|
|
$configuredPaymentMethods = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sf_event_mgt']['paymentMethods']; |
54
|
|
|
if (isset($configuredPaymentMethods[$paymentMethod]) && |
55
|
|
|
class_exists($configuredPaymentMethods[$paymentMethod]['class'])) { |
56
|
|
|
$paymentInstance = GeneralUtility::makeInstance($configuredPaymentMethods[$paymentMethod]['class']); |
57
|
|
|
} |
58
|
|
|
return $paymentInstance; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns, if the given action is enabled for the payment method |
63
|
|
|
* |
64
|
|
|
* @param string $paymentMethod |
65
|
|
|
* @param string $action |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
public function paymentActionEnabled($paymentMethod, $action) |
69
|
|
|
{ |
70
|
|
|
$result = false; |
71
|
|
|
$paymentInstance = $this->getPaymentInstance($paymentMethod); |
72
|
|
|
switch ($action) { |
73
|
|
|
case 'redirectAction': |
74
|
|
|
$result = $paymentInstance->isRedirectEnabled(); |
75
|
|
|
break; |
76
|
|
|
case 'successAction': |
77
|
|
|
$result = $paymentInstance->isSuccessLinkEnabled(); |
78
|
|
|
break; |
79
|
|
|
case 'failureAction': |
80
|
|
|
$result = $paymentInstance->isFailureLinkEnabled(); |
81
|
|
|
break; |
82
|
|
|
case 'cancelAction': |
83
|
|
|
$result = $paymentInstance->isCancelLinkEnabled(); |
84
|
|
|
break; |
85
|
|
|
case 'notifyAction': |
86
|
|
|
$result = $paymentInstance->isNotifyLinkEnabled(); |
87
|
|
|
break; |
88
|
|
|
} |
89
|
|
|
return $result; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |