PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / Settings / FeaturesIntegrations / ToggleFeatureIntegrationCommandHandler.php
ameliabooking / src / Application / Commands / Settings / FeaturesIntegrations Last commit date
ToggleFeatureIntegrationCommand.php 6 months ago ToggleFeatureIntegrationCommandHandler.php 2 weeks ago
ToggleFeatureIntegrationCommandHandler.php
96 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Settings\FeaturesIntegrations;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Domain\Entity\Entities;
9 use AmeliaBooking\Domain\Services\Settings\SettingsService;
10 use AmeliaBooking\Infrastructure\WP\Integrations\PluginInstaller;
11
12 class ToggleFeatureIntegrationCommandHandler extends CommandHandler
13 {
14 public $mandatoryFields = [
15 'code'
16 ];
17
18 public function handle(ToggleFeatureIntegrationCommand $command)
19 {
20 $result = new CommandResult();
21
22 if (!$command->getPermissionService()->currentUserCanWrite(Entities::SETTINGS)) {
23 throw new AccessDeniedException('You are not allowed to write settings.');
24 }
25
26 $this->checkMandatoryFields($command);
27
28 $code = $command->getField('code');
29
30 /** @var SettingsService $settingsService */
31 $settingsService = $this->getContainer()->get('domain.settings.service');
32
33 $payments = $settingsService->getCategorySettings('payments');
34
35 $featuresIntegrations = $settingsService->getCategorySettings('featuresIntegrations');
36
37 if (!isset($featuresIntegrations[$code])) {
38 $result->setResult(CommandResult::RESULT_ERROR);
39 $result->setMessage('Feature or integration does not exist.');
40
41 return $result;
42 }
43
44 if ($code === 'ivy' && (!PluginInstaller::isPluginInstalled('ivyforms') || !PluginInstaller::isPluginActive('ivyforms'))) {
45 $ivyResult = [];
46
47 // if IvyForms is not installed or not active, install and activate it
48 if (!PluginInstaller::isPluginInstalled('ivyforms')) {
49 $ivyResult = PluginInstaller::installAndActivatePlugin('ivyforms');
50 } elseif (!PluginInstaller::isPluginActive('ivyforms')) {
51 $ivyResult = PluginInstaller::activatePlugin('ivyforms');
52 }
53
54 if (empty($ivyResult['success'])) {
55 $result->setResult(CommandResult::RESULT_ERROR);
56 $result->setMessage($ivyResult['message']);
57
58 return $result;
59 }
60
61 $result->setMessage($ivyResult['message']);
62 }
63
64 $featuresIntegrations[$code]['enabled'] = !$featuresIntegrations[$code]['enabled'];
65 $settingsService->setCategorySettings('featuresIntegrations', $featuresIntegrations);
66
67 if (
68 isset($payments[$code]['enabled'], $featuresIntegrations[$code]) &&
69 !$featuresIntegrations[$code]['enabled'] &&
70 $payments[$code]['enabled']
71 ) {
72 $defaultPaymentMethod = 'onSite';
73
74 $payments[$code]['enabled'] = false;
75
76 foreach (['stripe', 'payPal', 'wc', 'mollie', 'razorpay', 'square', 'barion'] as $method) {
77 if ($featuresIntegrations[$method]['enabled'] && $payments[$method]['enabled']) {
78 $defaultPaymentMethod = $method;
79
80 break;
81 }
82 }
83
84 if ($defaultPaymentMethod === 'onSite') {
85 $payments['onSite'] = true;
86 }
87
88 $payments['defaultPaymentMethod'] = $defaultPaymentMethod;
89
90 $settingsService->setCategorySettings('payments', $payments);
91 }
92
93 return $result;
94 }
95 }
96