PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
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 6 months ago
ToggleFeatureIntegrationCommandHandler.php
69 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\Domain\Services\Settings\SettingsService;
8
9 class ToggleFeatureIntegrationCommandHandler extends CommandHandler
10 {
11 public $mandatoryFields = [
12 'code'
13 ];
14
15 public function handle(ToggleFeatureIntegrationCommand $command)
16 {
17 $result = new CommandResult();
18
19 $this->checkMandatoryFields($command);
20
21 $code = $command->getField('code');
22
23 /** @var SettingsService $settingsService */
24 $settingsService = $this->getContainer()->get('domain.settings.service');
25
26 $payments = $settingsService->getCategorySettings('payments');
27
28 $featuresIntegrations = $settingsService->getCategorySettings('featuresIntegrations');
29
30 if (!isset($featuresIntegrations[$code])) {
31 $result->setResult(CommandResult::RESULT_ERROR);
32 $result->setMessage('Feature or integration does not exist.');
33
34 return $result;
35 }
36
37 $featuresIntegrations[$code]['enabled'] = !$featuresIntegrations[$code]['enabled'];
38 $settingsService->setCategorySettings('featuresIntegrations', $featuresIntegrations);
39
40 if (
41 isset($payments[$code]['enabled'], $featuresIntegrations[$code]) &&
42 !$featuresIntegrations[$code]['enabled'] &&
43 $payments[$code]['enabled']
44 ) {
45 $defaultPaymentMethod = 'onSite';
46
47 $payments[$code]['enabled'] = false;
48
49 foreach (['stripe', 'payPal', 'wc', 'mollie', 'razorpay', 'square', 'barion'] as $method) {
50 if ($featuresIntegrations[$method]['enabled'] && $payments[$method]['enabled']) {
51 $defaultPaymentMethod = $method;
52
53 break;
54 }
55 }
56
57 if ($defaultPaymentMethod === 'onSite') {
58 $payments['onSite'] = true;
59 }
60
61 $payments['defaultPaymentMethod'] = $defaultPaymentMethod;
62
63 $settingsService->setCategorySettings('payments', $payments);
64 }
65
66 return $result;
67 }
68 }
69