SettingsStorage.php
1020 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Infrastructure\WP\SettingsService; |
| 4 | |
| 5 | use AmeliaBooking\Application\Services\Location\AbstractCurrentLocation; |
| 6 | use AmeliaBooking\Domain\Services\DateTime\DateTimeService; |
| 7 | use AmeliaBooking\Domain\Services\Settings\SettingsStorageInterface; |
| 8 | use AmeliaBooking\Infrastructure\Licence; |
| 9 | use AmeliaBooking\Plugin; |
| 10 | use AmeliaBooking\Infrastructure\WP\Integrations\PluginInstaller; |
| 11 | use AmeliaBooking\Infrastructure\WP\UserRoles\SuperAdminRoleService; |
| 12 | |
| 13 | /** |
| 14 | * Class SettingsStorage |
| 15 | * |
| 16 | * @package AmeliaBooking\Infrastructure\WP\SettingsService |
| 17 | */ |
| 18 | class SettingsStorage implements SettingsStorageInterface |
| 19 | { |
| 20 | /** @var array|mixed */ |
| 21 | private $settingsCache; |
| 22 | |
| 23 | /** @var AbstractCurrentLocation */ |
| 24 | private $locationService; |
| 25 | |
| 26 | private static $wpSettings = [ |
| 27 | 'dateFormat' => 'date_format', |
| 28 | 'timeFormat' => 'time_format', |
| 29 | 'startOfWeek' => 'start_of_week', |
| 30 | 'timeZoneString' => 'timezone_string', |
| 31 | 'gmtOffset' => 'gmt_offset' |
| 32 | ]; |
| 33 | |
| 34 | public function __construct() |
| 35 | { |
| 36 | if (!defined('AMELIA_LOCALE')) { |
| 37 | define('AMELIA_LOCALE', get_user_locale()); |
| 38 | } |
| 39 | |
| 40 | $this->locationService = Licence\ApplicationService::getCurrentLocationService(); |
| 41 | |
| 42 | $this->settingsCache = self::getSavedSettings(); |
| 43 | |
| 44 | Licence\DataModifier::modifySettings($this->settingsCache); |
| 45 | |
| 46 | foreach (self::$wpSettings as $ameliaSetting => $wpSetting) { |
| 47 | $this->settingsCache['wordpress'][$ameliaSetting] = get_option($wpSetting); |
| 48 | } |
| 49 | |
| 50 | $this->settingsCache['wordpress']['locale'] = AMELIA_LOCALE; |
| 51 | |
| 52 | DateTimeService::setTimeZone($this->getAllSettings()); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return array |
| 57 | */ |
| 58 | private function getSavedSettings() |
| 59 | { |
| 60 | return json_decode(get_option('amelia_settings'), true); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param $settingCategoryKey |
| 65 | * @param $settingKey |
| 66 | * |
| 67 | * @return mixed |
| 68 | */ |
| 69 | public function getSetting($settingCategoryKey, $settingKey) |
| 70 | { |
| 71 | return $this->settingsCache[$settingCategoryKey][$settingKey] ?? null; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @param $settingCategoryKey |
| 76 | * |
| 77 | * @return mixed |
| 78 | */ |
| 79 | public function getCategorySettings($settingCategoryKey) |
| 80 | { |
| 81 | return $this->settingsCache[$settingCategoryKey] ?? null; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @return array|mixed|null |
| 86 | */ |
| 87 | public function getAllSettings() |
| 88 | { |
| 89 | $settings = []; |
| 90 | |
| 91 | if (null !== $this->settingsCache) { |
| 92 | foreach ((array)$this->settingsCache as $settingsCategoryName => $settingsCategory) { |
| 93 | if ($settingsCategoryName !== 'daysOff') { |
| 94 | foreach ((array)$settingsCategory as $settingName => $settingValue) { |
| 95 | $settings[$settingName] = $settingValue; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return $settings; |
| 101 | } |
| 102 | |
| 103 | return null; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @return array|mixed|null |
| 108 | */ |
| 109 | public function getAllSettingsCategorized() |
| 110 | { |
| 111 | return $this->settingsCache ?? null; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Return settings for frontend |
| 116 | * |
| 117 | * @return array|mixed |
| 118 | */ |
| 119 | public function getFrontendSettings() |
| 120 | { |
| 121 | $phoneCountryCode = $this->getSetting('general', 'phoneDefaultCountryCode'); |
| 122 | $ipLocateApyKey = $this->getSetting('general', 'ipLocateApiKey'); |
| 123 | |
| 124 | $capabilities = []; |
| 125 | $additionalCapabilities = []; |
| 126 | if (is_admin()) { |
| 127 | $currentScreenId = get_current_screen()->id; |
| 128 | $currentScreen = substr($currentScreenId, strrpos($currentScreenId, '-') + 1); |
| 129 | |
| 130 | $capabilities = [ |
| 131 | 'canRead' => current_user_can('amelia_read_' . $currentScreen), |
| 132 | 'canReadOthers' => current_user_can('amelia_read_others_' . $currentScreen), |
| 133 | 'canWrite' => current_user_can('amelia_write_' . $currentScreen), |
| 134 | 'canWriteOthers' => current_user_can('amelia_write_others_' . $currentScreen), |
| 135 | 'canDelete' => current_user_can('amelia_delete_' . $currentScreen), |
| 136 | 'canWriteStatus' => current_user_can('amelia_write_status_' . $currentScreen), |
| 137 | ]; |
| 138 | |
| 139 | $additionalCapabilities = [ |
| 140 | 'canWriteCustomers' => current_user_can('amelia_write_customers'), |
| 141 | ]; |
| 142 | } |
| 143 | |
| 144 | $wpUser = wp_get_current_user(); |
| 145 | $superAdminService = new SuperAdminRoleService(); |
| 146 | |
| 147 | $userType = 'customer'; |
| 148 | |
| 149 | if ( |
| 150 | in_array('administrator', $wpUser->roles, true) || |
| 151 | in_array(SuperAdminRoleService::ROLE, $wpUser->roles, true) || |
| 152 | is_super_admin($wpUser->ID) |
| 153 | ) { |
| 154 | $userType = 'admin'; |
| 155 | } elseif (in_array('wpamelia-manager', $wpUser->roles, true)) { |
| 156 | $userType = 'manager'; |
| 157 | } elseif (in_array('wpamelia-provider', $wpUser->roles, true)) { |
| 158 | $userType = 'provider'; |
| 159 | } |
| 160 | |
| 161 | return [ |
| 162 | 'capabilities' => $capabilities, |
| 163 | 'additionalCapabilities' => $additionalCapabilities, |
| 164 | 'daysOff' => $this->getCategorySettings('daysOff'), |
| 165 | 'general' => [ |
| 166 | 'itemsPerPage' => $this->getSetting('general', 'itemsPerPage'), |
| 167 | 'appointmentsPerPage' => $this->getSetting('general', 'appointmentsPerPage'), |
| 168 | 'eventsPerPage' => $this->getSetting('general', 'eventsPerPage'), |
| 169 | 'servicesPerPage' => $this->getSetting('general', 'servicesPerPage'), |
| 170 | 'customersFilterLimit' => $this->getSetting('general', 'customersFilterLimit'), |
| 171 | 'eventsFilterLimit' => $this->getSetting( |
| 172 | 'general', |
| 173 | 'eventsFilterLimit' |
| 174 | ) ?: 1000, |
| 175 | 'calendarEmployeesPreselected' => $this->getSetting( |
| 176 | 'general', |
| 177 | 'calendarEmployeesPreselected' |
| 178 | ), |
| 179 | 'phoneDefaultCountryCode' => $phoneCountryCode === 'auto' ? |
| 180 | $this->locationService->getCurrentLocationCountryIso($ipLocateApyKey) : $phoneCountryCode, |
| 181 | 'timeSlotLength' => $this->getSetting('general', 'timeSlotLength'), |
| 182 | 'serviceDurationAsSlot' => $this->getSetting('general', 'serviceDurationAsSlot'), |
| 183 | 'defaultAppointmentStatus' => $this->getSetting('general', 'defaultAppointmentStatus'), |
| 184 | 'gMapApiKey' => !empty($this->getSetting('general', 'gMapApiKey')), |
| 185 | 'googleClientId' => $this->getSetting('googleCalendar', 'clientID'), |
| 186 | 'googleAccessToken' => !empty($this->getSetting('googleCalendar', 'accessToken')), |
| 187 | 'googleAccountData' => $this->getSetting('googleCalendar', 'googleAccountData'), |
| 188 | 'outlookAccountData' => $this->getSetting('outlookCalendar', 'outlookAccountData'), |
| 189 | 'addToCalendar' => $this->getSetting('general', 'addToCalendar'), |
| 190 | 'requiredPhoneNumberField' => $this->getSetting('general', 'requiredPhoneNumberField'), |
| 191 | 'requiredEmailField' => $this->getSetting('general', 'requiredEmailField'), |
| 192 | 'numberOfDaysAvailableForBooking' => $this->getSetting( |
| 193 | 'general', |
| 194 | 'numberOfDaysAvailableForBooking' |
| 195 | ), |
| 196 | 'minimumTimeRequirementPriorToBooking' => |
| 197 | $this->getSetting('general', 'minimumTimeRequirementPriorToBooking'), |
| 198 | 'minimumTimeRequirementPriorToCanceling' => |
| 199 | $this->getSetting('general', 'minimumTimeRequirementPriorToCanceling'), |
| 200 | 'minimumTimeRequirementPriorToRescheduling' => |
| 201 | $this->getSetting('general', 'minimumTimeRequirementPriorToRescheduling'), |
| 202 | 'showClientTimeZone' => $this->getSetting( |
| 203 | 'general', |
| 204 | 'showClientTimeZone' |
| 205 | ), |
| 206 | 'redirectUrlAfterAppointment' => $this->getSetting( |
| 207 | 'general', |
| 208 | 'redirectUrlAfterAppointment' |
| 209 | ), |
| 210 | 'customFieldsUploadsPath' => $this->getSetting('general', 'customFieldsUploadsPath'), |
| 211 | 'customFieldsAllowedExtensions' => $this->getSetting( |
| 212 | 'general', |
| 213 | 'customFieldsAllowedExtensions' |
| 214 | ), |
| 215 | 'runInstantPostBookingActions' => $this->getSetting( |
| 216 | 'general', |
| 217 | 'runInstantPostBookingActions' |
| 218 | ), |
| 219 | 'sortingPackages' => $this->getSetting('general', 'sortingPackages'), |
| 220 | 'backLink' => $this->getSetting('general', 'backLink'), |
| 221 | 'sortingServices' => $this->getSetting('general', 'sortingServices'), |
| 222 | 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense( |
| 223 | 'recaptcha', |
| 224 | $this->getSetting('featuresIntegrations', 'recaptcha') |
| 225 | ) && |
| 226 | $this->getSetting('general', 'googleRecaptcha')['siteKey'] && |
| 227 | $this->getSetting('general', 'googleRecaptcha')['secret'] ? [ |
| 228 | 'enabled' => true, |
| 229 | 'invisible' => $this->getSetting('general', 'googleRecaptcha')['invisible'], |
| 230 | 'siteKey' => $this->getSetting('general', 'googleRecaptcha')['siteKey'], |
| 231 | ] : [ |
| 232 | 'enabled' => false, |
| 233 | 'invisible' => true, |
| 234 | 'siteKey' => '', |
| 235 | ], |
| 236 | 'usedLanguages' => $this->getSetting('general', 'usedLanguages'), |
| 237 | ], |
| 238 | 'googleMeet' => [ |
| 239 | 'enabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet'), |
| 240 | ], |
| 241 | 'microsoftTeams' => [ |
| 242 | 'enabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'), |
| 243 | ], |
| 244 | 'googleCalendar' => [ |
| 245 | 'enabled' => |
| 246 | ( |
| 247 | ( |
| 248 | $this->getSetting('googleCalendar', 'clientID') && |
| 249 | $this->getSetting('googleCalendar', 'clientSecret') |
| 250 | ) || |
| 251 | !empty($this->getSetting('googleCalendar', 'accessToken')) && |
| 252 | $this->getSetting('googleCalendar', 'accessToken') !== 'null' |
| 253 | ) && |
| 254 | Licence\Licence::isFeatureEnabledWithLicense( |
| 255 | 'googleCalendar', |
| 256 | $this->getSetting('featuresIntegrations', 'googleCalendar') |
| 257 | ), |
| 258 | 'googleMeetEnabled' => $this->getSetting('googleCalendar', 'enableGoogleMeet'), |
| 259 | 'accessToken' => !empty($this->getSetting('googleCalendar', 'accessToken')), |
| 260 | ], |
| 261 | 'outlookCalendar' => [ |
| 262 | 'enabled' => |
| 263 | ( |
| 264 | ( |
| 265 | $this->getSetting('outlookCalendar', 'clientID') && |
| 266 | $this->getSetting('outlookCalendar', 'clientSecret') |
| 267 | ) || |
| 268 | !empty($this->getSetting('outlookCalendar', 'accessToken')) && |
| 269 | $this->getSetting('outlookCalendar', 'accessToken') !== 'null' |
| 270 | ) && |
| 271 | Licence\Licence::isFeatureEnabledWithLicense( |
| 272 | 'outlookCalendar', |
| 273 | $this->getSetting('featuresIntegrations', 'outlookCalendar') |
| 274 | ), |
| 275 | 'microsoftTeamsEnabled' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'), |
| 276 | 'accessToken' => !empty($this->getSetting('outlookCalendar', 'accessToken')), |
| 277 | ], |
| 278 | 'appleCalendar' => [ |
| 279 | 'enabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 280 | 'appleCalendar', |
| 281 | $this->getSetting('featuresIntegrations', 'appleCalendar') |
| 282 | ) && |
| 283 | $this->getSetting('appleCalendar', 'clientID') && $this->getSetting('appleCalendar', 'clientSecret'), |
| 284 | |
| 285 | ], |
| 286 | 'zoom' => [ |
| 287 | 'enabled' => ( |
| 288 | Licence\Licence::isFeatureEnabledWithLicense( |
| 289 | 'zoom', |
| 290 | $this->getSetting('featuresIntegrations', 'zoom') |
| 291 | ) && |
| 292 | $this->getSetting('zoom', 'accountId') && |
| 293 | $this->getSetting('zoom', 'clientId') && |
| 294 | $this->getSetting('zoom', 'clientSecret') |
| 295 | ) |
| 296 | ], |
| 297 | 'facebookPixel' => Licence\Licence::isFeatureEnabledWithLicense( |
| 298 | 'facebookPixel', |
| 299 | $this->getSetting('featuresIntegrations', 'facebookPixel') |
| 300 | ) |
| 301 | ? $this->getCategorySettings('facebookPixel') |
| 302 | : array_merge( |
| 303 | $this->getCategorySettings('facebookPixel') ?: [], |
| 304 | ['id' => ''] |
| 305 | ), |
| 306 | 'googleAnalytics' => Licence\Licence::isFeatureEnabledWithLicense( |
| 307 | 'googleAnalytics', |
| 308 | $this->getSetting('featuresIntegrations', 'googleAnalytics') |
| 309 | ) |
| 310 | ? $this->getCategorySettings('googleAnalytics') |
| 311 | : array_merge( |
| 312 | $this->getCategorySettings('googleAnalytics') ?: [], |
| 313 | ['id' => ''] |
| 314 | ), |
| 315 | 'googleTag' => Licence\Licence::isFeatureEnabledWithLicense( |
| 316 | 'googleTag', |
| 317 | $this->getSetting('featuresIntegrations', 'googleTag') |
| 318 | ) |
| 319 | ? $this->getCategorySettings('googleTag') |
| 320 | : array_merge( |
| 321 | $this->getCategorySettings('googleTag') ?: [], |
| 322 | ['id' => ''] |
| 323 | ), |
| 324 | 'mailchimp' => [ |
| 325 | 'subscribeFieldVisible' => |
| 326 | Licence\Licence::isFeatureEnabledWithLicense( |
| 327 | 'mailchimp', |
| 328 | $this->getSetting('featuresIntegrations', 'mailchimp') |
| 329 | ) && |
| 330 | !empty($this->getSetting('mailchimp', 'accessToken')) && |
| 331 | !empty($this->getSetting('mailchimp', 'list')) && |
| 332 | !empty($this->getSetting('mailchimp', 'server')), |
| 333 | 'checkedByDefault' => $this->getSetting('mailchimp', 'checkedByDefault'), |
| 334 | ], |
| 335 | 'lessonSpace' => [ |
| 336 | 'enabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 337 | 'lessonSpace', |
| 338 | $this->getSetting('featuresIntegrations', 'lessonSpace') |
| 339 | ) && $this->getSetting('lessonSpace', 'apiKey') |
| 340 | ], |
| 341 | 'socialLogin' => [ |
| 342 | 'googleLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 343 | 'googleSocialLogin', |
| 344 | $this->getSetting('featuresIntegrations', 'googleSocialLogin') |
| 345 | ), |
| 346 | 'facebookLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 347 | 'facebookSocialLogin', |
| 348 | $this->getSetting('featuresIntegrations', 'facebookSocialLogin') |
| 349 | ), |
| 350 | 'facebookAppId' => $this->getSetting('socialLogin', 'facebookAppId'), |
| 351 | 'facebookCredentialsEnabled' => $this->getSetting('socialLogin', 'facebookAppId') && |
| 352 | $this->getSetting('socialLogin', 'facebookAppSecret'), |
| 353 | ], |
| 354 | 'notifications' => [ |
| 355 | 'senderName' => $this->getSetting('notifications', 'senderName'), |
| 356 | 'replyTo' => $this->getSetting('notifications', 'replyTo'), |
| 357 | 'senderEmail' => $this->getSetting('notifications', 'senderEmail'), |
| 358 | 'invoiceFormat' => $this->getSetting('notifications', 'invoiceFormat'), |
| 359 | 'sendAllCF' => $this->getSetting('notifications', 'sendAllCF'), |
| 360 | 'cancelSuccessUrl' => $this->getSetting('notifications', 'cancelSuccessUrl'), |
| 361 | 'cancelErrorUrl' => $this->getSetting('notifications', 'cancelErrorUrl'), |
| 362 | 'approveSuccessUrl' => $this->getSetting('notifications', 'approveSuccessUrl'), |
| 363 | 'approveErrorUrl' => $this->getSetting('notifications', 'approveErrorUrl'), |
| 364 | 'rejectSuccessUrl' => $this->getSetting('notifications', 'rejectSuccessUrl'), |
| 365 | 'rejectErrorUrl' => $this->getSetting('notifications', 'rejectErrorUrl'), |
| 366 | 'smsSignedIn' => $this->getSetting('notifications', 'smsSignedIn'), |
| 367 | 'bccEmail' => $this->getSetting('notifications', 'bccEmail'), |
| 368 | 'bccSms' => $this->getSetting('notifications', 'bccSms'), |
| 369 | 'smsBalanceEmail' => $this->getSetting('notifications', 'smsBalanceEmail'), |
| 370 | 'whatsAppEnabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 371 | 'whatsapp', |
| 372 | $this->getSetting('featuresIntegrations', 'whatsapp') |
| 373 | ) && |
| 374 | !empty($this->getSetting('notifications', 'whatsAppPhoneID')) && |
| 375 | !empty($this->getSetting('notifications', 'whatsAppAccessToken')) && |
| 376 | !empty($this->getSetting('notifications', 'whatsAppBusinessID')), |
| 377 | ], |
| 378 | 'payments' => [ |
| 379 | 'currency' => $this->getSetting('payments', 'symbol'), |
| 380 | 'currencyCode' => $this->getSetting('payments', 'currency'), |
| 381 | 'priceSymbolPosition' => $this->getSetting('payments', 'priceSymbolPosition'), |
| 382 | 'priceNumberOfDecimals' => $this->getSetting('payments', 'priceNumberOfDecimals'), |
| 383 | 'priceSeparator' => $this->getSetting('payments', 'priceSeparator'), |
| 384 | 'hideCurrencySymbolFrontend' => $this->getSetting('payments', 'hideCurrencySymbolFrontend'), |
| 385 | 'defaultPaymentMethod' => $this->getSetting('payments', 'defaultPaymentMethod'), |
| 386 | 'onSite' => $this->getSetting('payments', 'onSite'), |
| 387 | 'couponsCaseInsensitive' => $this->getSetting('payments', 'couponsCaseInsensitive'), |
| 388 | 'coupons' => Licence\Licence::isFeatureEnabledWithLicense( |
| 389 | 'coupons', |
| 390 | $this->getSetting('featuresIntegrations', 'coupons') |
| 391 | ), |
| 392 | 'taxes' => array_merge( |
| 393 | $this->getSetting('payments', 'taxes'), |
| 394 | [ |
| 395 | 'enabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 396 | 'tax', |
| 397 | $this->getSetting('featuresIntegrations', 'tax') |
| 398 | ) |
| 399 | ] |
| 400 | ), |
| 401 | 'cart' => Licence\Licence::isFeatureEnabledWithLicense( |
| 402 | 'cart', |
| 403 | $this->getSetting('featuresIntegrations', 'cart') |
| 404 | ), |
| 405 | 'paymentLinks' => [ |
| 406 | 'enabled' => $this->getSetting('payments', 'paymentLinks')['enabled'], |
| 407 | 'changeBookingStatus' => $this->getSetting('payments', 'paymentLinks')['changeBookingStatus'], |
| 408 | 'redirectUrl' => $this->getSetting('payments', 'paymentLinks')['redirectUrl'] |
| 409 | ], |
| 410 | 'payPal' => [ |
| 411 | 'enabled' => $this->getSetting('payments', 'payPal')['enabled'], |
| 412 | 'sandboxMode' => $this->getSetting('payments', 'payPal')['sandboxMode'], |
| 413 | 'testApiClientId' => $this->getSetting('payments', 'payPal')['testApiClientId'], |
| 414 | 'liveApiClientId' => $this->getSetting('payments', 'payPal')['liveApiClientId'], |
| 415 | ], |
| 416 | 'stripe' => [ |
| 417 | 'enabled' => $this->getSetting('payments', 'stripe')['enabled'], |
| 418 | 'testMode' => $this->getSetting('payments', 'stripe')['testMode'], |
| 419 | 'livePublishableKey' => $this->getSetting('payments', 'stripe')['livePublishableKey'], |
| 420 | 'testPublishableKey' => $this->getSetting('payments', 'stripe')['testPublishableKey'], |
| 421 | 'connect' => $this->getSetting('payments', 'stripe')['connect'], |
| 422 | 'address' => $this->getSetting('payments', 'stripe')['address'], |
| 423 | ], |
| 424 | 'wc' => [ |
| 425 | 'enabled' => $this->getSetting('payments', 'wc')['enabled'], |
| 426 | 'productId' => $this->getSetting('payments', 'wc')['productId'], |
| 427 | 'page' => $this->getSetting('payments', 'wc')['page'], |
| 428 | 'onSiteIfFree' => $this->getSetting('payments', 'wc')['onSiteIfFree'] |
| 429 | ], |
| 430 | 'mollie' => [ |
| 431 | 'enabled' => $this->getSetting('payments', 'mollie')['enabled'], |
| 432 | 'cancelBooking' => $this->getSetting('payments', 'mollie')['cancelBooking'], |
| 433 | ], |
| 434 | 'square' => [ |
| 435 | 'enabled' => $this->getSetting('payments', 'square')['enabled'], |
| 436 | 'countryCode' => $this->getSetting('payments', 'square')['countryCode'], |
| 437 | 'clientLiveId' => $this->getSetting('payments', 'square')['clientLiveId'], |
| 438 | 'clientTestId' => $this->getSetting('payments', 'square')['clientTestId'], |
| 439 | 'testMode' => $this->getSetting('payments', 'square')['testMode'], |
| 440 | 'locationId' => $this->getSetting('payments', 'square')['locationId'] |
| 441 | ], |
| 442 | 'razorpay' => [ |
| 443 | 'enabled' => $this->getSetting('payments', 'razorpay')['enabled'], |
| 444 | ], |
| 445 | 'barion' => [ |
| 446 | 'enabled' => $this->getSetting('payments', 'barion')['enabled'], |
| 447 | ], |
| 448 | ], |
| 449 | 'role' => $userType, |
| 450 | 'weekSchedule' => $this->getCategorySettings('weekSchedule'), |
| 451 | 'wordpress' => [ |
| 452 | 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'), |
| 453 | 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'), |
| 454 | 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'), |
| 455 | 'timezone' => $this->getSetting('wordpress', 'timeZoneString'), |
| 456 | 'locale' => AMELIA_LOCALE |
| 457 | ], |
| 458 | 'labels' => [ |
| 459 | 'enabled' => $this->getSetting('labels', 'enabled') |
| 460 | ], |
| 461 | 'activation' => [ |
| 462 | 'showAmeliaSurvey' => $this->getSetting('activation', 'showAmeliaSurvey'), |
| 463 | 'showAmeliaPromoCustomizePopup' => $this->getSetting('activation', 'showAmeliaPromoCustomizePopup'), |
| 464 | 'showActivationSettings' => $this->getSetting('activation', 'showActivationSettings'), |
| 465 | 'stash' => $this->getSetting('activation', 'stash'), |
| 466 | 'disableUrlParams' => $this->getSetting('activation', 'disableUrlParams'), |
| 467 | 'isNewInstallation' => $this->getSetting('activation', 'isNewInstallation'), |
| 468 | 'hideUnavailableFeatures' => $this->getSetting('activation', 'hideUnavailableFeatures'), |
| 469 | 'licence' => $this->getSetting('activation', 'licence'), |
| 470 | 'premiumBannerVisibility' => $this->getSetting('activation', 'premiumBannerVisibility'), |
| 471 | 'dismissibleBannerVisibility' => $this->getSetting('activation', 'dismissibleBannerVisibility'), |
| 472 | ], |
| 473 | 'roles' => [ |
| 474 | 'allowAdminBookAtAnyTime' => $this->getSetting('roles', 'allowAdminBookAtAnyTime'), |
| 475 | 'allowAdminBookOverApp' => $this->getSetting('roles', 'allowAdminBookOverApp'), |
| 476 | 'adminServiceDurationAsSlot' => $this->getSetting('roles', 'adminServiceDurationAsSlot'), |
| 477 | 'allowConfigureSchedule' => $this->getSetting('roles', 'allowConfigureSchedule'), |
| 478 | 'allowConfigureDaysOff' => $this->getSetting('roles', 'allowConfigureDaysOff'), |
| 479 | 'allowConfigureSpecialDays' => $this->getSetting('roles', 'allowConfigureSpecialDays'), |
| 480 | 'allowConfigureServices' => $this->getSetting('roles', 'allowConfigureServices'), |
| 481 | 'allowWriteAppointments' => $this->getSetting('roles', 'allowWriteAppointments'), |
| 482 | 'allowWriteCustomers' => $this->getSetting('roles', 'allowWriteCustomers'), |
| 483 | 'allowReadAllCustomers' => $this->getSetting('roles', 'allowReadAllCustomers'), |
| 484 | 'automaticallyCreateCustomer' => $this->getSetting('roles', 'automaticallyCreateCustomer'), |
| 485 | 'inspectCustomerInfo' => $this->getSetting('roles', 'inspectCustomerInfo'), |
| 486 | 'allowCustomerReschedule' => $this->getSetting('roles', 'allowCustomerReschedule'), |
| 487 | 'allowCustomerCancelPackages' => $this->getSetting('roles', 'allowCustomerCancelPackages'), |
| 488 | 'allowCustomerDeleteProfile' => $this->getSetting('roles', 'allowCustomerDeleteProfile'), |
| 489 | 'allowWriteEvents' => $this->getSetting('roles', 'allowWriteEvents'), |
| 490 | 'customerCabinet' => [ |
| 491 | 'loginEnabled' => $this->getSetting('roles', 'customerCabinet')['loginEnabled'], |
| 492 | 'tokenValidTime' => $this->getSetting('roles', 'customerCabinet')['tokenValidTime'], |
| 493 | 'pageUrl' => $this->getSetting('roles', 'customerCabinet')['pageUrl'], |
| 494 | 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense( |
| 495 | 'recaptcha', |
| 496 | $this->getSetting('featuresIntegrations', 'recaptcha') |
| 497 | ) && |
| 498 | $this->getSetting('roles', 'customerCabinet')['googleRecaptcha'] && |
| 499 | $this->getSetting('general', 'googleRecaptcha')['siteKey'] && |
| 500 | $this->getSetting('general', 'googleRecaptcha')['secret'], |
| 501 | ], |
| 502 | 'providerCabinet' => [ |
| 503 | 'loginEnabled' => $this->getSetting('roles', 'providerCabinet')['loginEnabled'], |
| 504 | 'tokenValidTime' => $this->getSetting('roles', 'providerCabinet')['tokenValidTime'], |
| 505 | 'googleRecaptcha' => Licence\Licence::isFeatureEnabledWithLicense( |
| 506 | 'recaptcha', |
| 507 | $this->getSetting('featuresIntegrations', 'recaptcha') |
| 508 | ) && |
| 509 | $this->getSetting('roles', 'providerCabinet')['googleRecaptcha'] && |
| 510 | $this->getSetting('general', 'googleRecaptcha')['siteKey'] && |
| 511 | $this->getSetting('general', 'googleRecaptcha')['secret'], |
| 512 | ], |
| 513 | 'providerBadges' => Licence\Licence::isFeatureEnabledWithLicense( |
| 514 | 'employeeBadge', |
| 515 | $this->getSetting('featuresIntegrations', 'employeeBadge') |
| 516 | ) ? $this->getSetting('roles', 'providerBadges') : [], |
| 517 | 'limitPerCustomerService' => $this->getSetting('roles', 'limitPerCustomerService'), |
| 518 | 'limitPerCustomerPackage' => $this->getSetting('roles', 'limitPerCustomerPackage'), |
| 519 | 'limitPerCustomerEvent' => $this->getSetting('roles', 'limitPerCustomerEvent'), |
| 520 | 'limitPerEmployee' => $this->getSetting('roles', 'limitPerEmployee'), |
| 521 | ], |
| 522 | 'customization' => $this->getCategorySettings('customization'), |
| 523 | 'customizedData' => $this->getCategorySettings('customizedData'), |
| 524 | 'appointments' => $this->getCategorySettings('appointments'), |
| 525 | 'events' => $this->getCategorySettings('events'), |
| 526 | 'slotDateConstraints' => [ |
| 527 | 'minDate' => DateTimeService::getNowDateTimeObject() |
| 528 | ->modify( |
| 529 | "+{$this->getSetting('general', 'minimumTimeRequirementPriorToBooking')} seconds" |
| 530 | ) |
| 531 | ->format('Y-m-d H:i:s'), |
| 532 | 'maxDate' => DateTimeService::getNowDateTimeObject() |
| 533 | ->modify( |
| 534 | "+{$this->getSetting('general', 'numberOfDaysAvailableForBooking')} day" |
| 535 | ) |
| 536 | ->format('Y-m-d H:i:s') |
| 537 | ], |
| 538 | 'company' => [ |
| 539 | 'email' => $this->getSetting('company', 'email'), |
| 540 | 'phone' => $this->getSetting('company', 'phone'), |
| 541 | ], |
| 542 | 'ivy' => $this->getCategorySettings('ivy'), |
| 543 | 'pageColumnSettings' => $this->getCategorySettings('pageColumnSettings'), |
| 544 | 'featuresIntegrations' => Licence\Licence::filterFeaturesByLicense( |
| 545 | $this->getCategorySettings('featuresIntegrations') |
| 546 | ), |
| 547 | ]; |
| 548 | } |
| 549 | |
| 550 | public function getBackendSettings() |
| 551 | { |
| 552 | $capabilities = []; |
| 553 | |
| 554 | if (is_admin()) { |
| 555 | $entities = [ |
| 556 | 'appointments', |
| 557 | 'events', |
| 558 | 'customers', |
| 559 | 'employees', |
| 560 | 'services', |
| 561 | 'packages', |
| 562 | 'resources', |
| 563 | 'finance', |
| 564 | 'coupons', |
| 565 | 'taxes', |
| 566 | 'locations', |
| 567 | 'custom_fields', |
| 568 | 'notifications', |
| 569 | 'settings', |
| 570 | ]; |
| 571 | |
| 572 | foreach ($entities as $entity) { |
| 573 | $capabilities = array_merge( |
| 574 | $capabilities, |
| 575 | [ |
| 576 | 'canRead' . ucfirst($entity) => current_user_can('amelia_read_' . $entity), |
| 577 | 'canReadOthers' . ucfirst($entity) => current_user_can('amelia_read_others_' . $entity), |
| 578 | 'canWrite' . ucfirst($entity) => current_user_can('amelia_write_' . $entity), |
| 579 | 'canWriteOthers' . ucfirst($entity) => current_user_can('amelia_write_others_' . $entity), |
| 580 | 'canDelete' . ucfirst($entity) => current_user_can('amelia_delete_' . $entity), |
| 581 | 'canWriteStatus' . ucfirst($entity) => current_user_can('amelia_write_status_' . $entity), |
| 582 | ] |
| 583 | ); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | $phoneCountryCode = $this->getSetting('general', 'phoneDefaultCountryCode'); |
| 588 | $ipLocateApyKey = $this->getSetting('general', 'ipLocateApiKey'); |
| 589 | |
| 590 | $wpUser = wp_get_current_user(); |
| 591 | $superAdminService = new SuperAdminRoleService(); |
| 592 | |
| 593 | $userType = 'customer'; |
| 594 | |
| 595 | if ( |
| 596 | in_array('administrator', $wpUser->roles, true) || |
| 597 | in_array(SuperAdminRoleService::ROLE, $wpUser->roles, true) || |
| 598 | is_super_admin($wpUser->ID) |
| 599 | ) { |
| 600 | $userType = 'admin'; |
| 601 | } elseif (in_array('wpamelia-manager', $wpUser->roles, true)) { |
| 602 | $userType = 'manager'; |
| 603 | } elseif (in_array('wpamelia-provider', $wpUser->roles, true)) { |
| 604 | $userType = 'provider'; |
| 605 | } |
| 606 | |
| 607 | $isCurrentUserSuperAdmin = $superAdminService->isCurrentUserSuperAdmin(); |
| 608 | $canAccessActivation = $superAdminService->canAccessActivationSettings(); |
| 609 | |
| 610 | return [ |
| 611 | 'capabilities' => $capabilities, |
| 612 | 'isSuperAdmin' => $isCurrentUserSuperAdmin, |
| 613 | 'isSuperAdminRoleAvailable' => SuperAdminRoleService::isAvailable(), |
| 614 | 'superAdminCount' => $superAdminService->countSuperAdmins(), |
| 615 | 'activation' => [ |
| 616 | 'active' => (bool)$this->getSetting('activation', 'active'), |
| 617 | 'licence' => $canAccessActivation ? $this->getSetting('activation', 'licence') : null, |
| 618 | 'stash' => $canAccessActivation ? $this->getSetting('activation', 'stash') : false, |
| 619 | 'hideUnavailableFeatures' => $canAccessActivation ? |
| 620 | $this->getSetting('activation', 'hideUnavailableFeatures') : false, |
| 621 | 'hideTipsAndSuggestions' => $canAccessActivation ? |
| 622 | $this->getSetting('activation', 'hideTipsAndSuggestions') : false, |
| 623 | ], |
| 624 | 'whiteLabel' => [ |
| 625 | 'pluginName' => $this->getSetting('whiteLabel', 'pluginName'), |
| 626 | 'hideExternalLinks' => $this->getSetting('whiteLabel', 'hideExternalLinks'), |
| 627 | 'pictureFullPath' => $this->getSetting('whiteLabel', 'pictureFullPath'), |
| 628 | 'pictureThumbPath' => $this->getSetting('whiteLabel', 'pictureThumbPath'), |
| 629 | ], |
| 630 | 'appleCalendar' => [ |
| 631 | 'active' => Licence\Licence::isFeatureEnabledWithLicense( |
| 632 | 'appleCalendar', |
| 633 | $this->getSetting('featuresIntegrations', 'appleCalendar') |
| 634 | ) && |
| 635 | $this->getSetting('appleCalendar', 'clientID') && |
| 636 | $this->getSetting('appleCalendar', 'clientSecret'), |
| 637 | ], |
| 638 | 'appointments' => [ |
| 639 | 'cartPlaceholders' => $this->getSetting('appointments', 'cartPlaceholders'), |
| 640 | 'cartPlaceholdersCustomer' => $this->getSetting('appointments', 'cartPlaceholdersCustomer'), |
| 641 | 'cartPlaceholdersCustomerSms' => $this->getSetting( |
| 642 | 'appointments', |
| 643 | 'cartPlaceholdersCustomerSms' |
| 644 | ), |
| 645 | 'cartPlaceholdersSms' => $this->getSetting('appointments', 'cartPlaceholdersSms'), |
| 646 | 'groupAppointmentPlaceholder' => $this->getSetting( |
| 647 | 'appointments', |
| 648 | 'groupAppointmentPlaceholder' |
| 649 | ), |
| 650 | 'groupAppointmentPlaceholderCustomer' => $this->getSetting( |
| 651 | 'appointments', |
| 652 | 'groupAppointmentPlaceholderCustomer' |
| 653 | ), |
| 654 | 'groupAppointmentPlaceholderSms' => $this->getSetting( |
| 655 | 'appointments', |
| 656 | 'groupAppointmentPlaceholderSms' |
| 657 | ), |
| 658 | 'groupEventPlaceholder' => $this->getSetting('appointments', 'groupEventPlaceholder'), |
| 659 | 'groupEventPlaceholderCustomer' => $this->getSetting( |
| 660 | 'appointments', |
| 661 | 'groupEventPlaceholderCustomer' |
| 662 | ), |
| 663 | 'groupEventPlaceholderSms' => $this->getSetting('appointments', 'groupEventPlaceholderSms'), |
| 664 | 'packagePlaceholders' => $this->getSetting('appointments', 'packagePlaceholders'), |
| 665 | 'packagePlaceholdersCustomer' => $this->getSetting( |
| 666 | 'appointments', |
| 667 | 'packagePlaceholdersCustomer' |
| 668 | ), |
| 669 | 'packagePlaceholdersCustomerSms' => $this->getSetting( |
| 670 | 'appointments', |
| 671 | 'packagePlaceholdersCustomerSms' |
| 672 | ), |
| 673 | 'packagePlaceholdersSms' => $this->getSetting('appointments', 'packagePlaceholdersSms'), |
| 674 | 'recurringPlaceholders' => $this->getSetting('appointments', 'recurringPlaceholders'), |
| 675 | 'recurringPlaceholdersCustomer' => $this->getSetting( |
| 676 | 'appointments', |
| 677 | 'recurringPlaceholdersCustomer' |
| 678 | ), |
| 679 | 'recurringPlaceholdersCustomerSms' => $this->getSetting( |
| 680 | 'appointments', |
| 681 | 'recurringPlaceholdersCustomerSms' |
| 682 | ), |
| 683 | 'recurringPlaceholdersSms' => $this->getSetting('appointments', 'recurringPlaceholdersSms'), |
| 684 | 'waitingListAppointments' => $this->getSetting('appointments', 'waitingListAppointments'), |
| 685 | ], |
| 686 | 'daysOff' => $this->getCategorySettings('daysOff'), |
| 687 | 'events' => [ |
| 688 | 'waitingListEvents' => [ |
| 689 | 'addingMethod' => $this->getSetting('appointments', 'waitingListEvents')['addingMethod'], |
| 690 | ], |
| 691 | 'automaticallyCreateEventCustomPost' => $this->getSetting('appointments', 'automaticallyCreateEventCustomPost'), |
| 692 | ], |
| 693 | 'featuresIntegrations' => Licence\Licence::filterFeaturesByLicense( |
| 694 | $this->getCategorySettings('featuresIntegrations') |
| 695 | ), |
| 696 | 'general' => [ |
| 697 | 'customFieldsBackendValidation' => $this->getSetting('general', 'customFieldsBackendValidation'), |
| 698 | 'customersFilterLimit' => $this->getSetting('general', 'customersFilterLimit'), |
| 699 | 'defaultAppointmentStatus' => $this->getSetting('general', 'defaultAppointmentStatus'), |
| 700 | 'gMapApiKey' => $this->getSetting('general', 'gMapApiKey'), |
| 701 | 'minimumTimeRequirementPriorToBooking' => $this->getSetting( |
| 702 | 'general', |
| 703 | 'minimumTimeRequirementPriorToBooking' |
| 704 | ), |
| 705 | 'minimumTimeRequirementPriorToCanceling' => $this->getSetting( |
| 706 | 'general', |
| 707 | 'minimumTimeRequirementPriorToCanceling' |
| 708 | ), |
| 709 | 'minimumTimeRequirementPriorToRescheduling' => $this->getSetting( |
| 710 | 'general', |
| 711 | 'minimumTimeRequirementPriorToRescheduling' |
| 712 | ), |
| 713 | 'numberOfDaysAvailableForBooking' => $this->getSetting( |
| 714 | 'general', |
| 715 | 'numberOfDaysAvailableForBooking' |
| 716 | ), |
| 717 | 'phoneDefaultCountryCode' => $phoneCountryCode === 'auto' ? $this->locationService->getCurrentLocationCountryIso( |
| 718 | $ipLocateApyKey |
| 719 | ) : $phoneCountryCode, |
| 720 | 'redirectUrlAfterAppointment' => $this->getSetting( |
| 721 | 'general', |
| 722 | 'redirectUrlAfterAppointment' |
| 723 | ), |
| 724 | 'sortingPackages' => $this->getSetting('general', 'sortingPackages'), |
| 725 | 'sortingServices' => $this->getSetting('general', 'sortingServices'), |
| 726 | 'timeSlotLength' => $this->getSetting('general', 'timeSlotLength'), |
| 727 | 'usedLanguages' => $this->getSetting('general', 'usedLanguages'), |
| 728 | ], |
| 729 | 'googleCalendar' => [ |
| 730 | 'active' => Licence\Licence::isFeatureEnabledWithLicense( |
| 731 | 'googleCalendar', |
| 732 | $this->getSetting('featuresIntegrations', 'googleCalendar') |
| 733 | ) && |
| 734 | (($this->getSetting('googleCalendar', 'clientID') && |
| 735 | $this->getSetting('googleCalendar', 'clientSecret')) || |
| 736 | $this->getSetting('googleCalendar', 'accessToken')), |
| 737 | 'googleMeet' => $this->getSetting('googleCalendar', 'enableGoogleMeet'), |
| 738 | 'hasAccessToken' => !empty($this->getSetting('googleCalendar', 'accessToken')) && |
| 739 | $this->getSetting('googleCalendar', 'accessToken') !== 'null', |
| 740 | |
| 741 | ], |
| 742 | 'lessonSpace' => [ |
| 743 | 'active' => |
| 744 | Licence\Licence::isFeatureEnabledWithLicense( |
| 745 | 'lessonSpace', |
| 746 | $this->getSetting('featuresIntegrations', 'lessonSpace') |
| 747 | ) && $this->getSetting('lessonSpace', 'apiKey') |
| 748 | ], |
| 749 | 'socialLogin' => [ |
| 750 | 'googleLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 751 | 'googleSocialLogin', |
| 752 | $this->getSetting('featuresIntegrations', 'googleSocialLogin') |
| 753 | ), |
| 754 | 'facebookLoginEnabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 755 | 'facebookSocialLogin', |
| 756 | $this->getSetting('featuresIntegrations', 'facebookSocialLogin') |
| 757 | ), |
| 758 | 'facebookAppId' => $this->getSetting('socialLogin', 'facebookAppId'), |
| 759 | 'facebookCredentialsEnabled' => $this->getSetting('socialLogin', 'facebookAppId') && |
| 760 | $this->getSetting('socialLogin', 'facebookAppSecret'), |
| 761 | ], |
| 762 | 'mailchimp' => [ |
| 763 | 'subscribeFieldVisible' => |
| 764 | Licence\Licence::isFeatureEnabledWithLicense( |
| 765 | 'mailchimp', |
| 766 | $this->getSetting('featuresIntegrations', 'mailchimp') |
| 767 | ) && |
| 768 | !empty($this->getSetting('mailchimp', 'accessToken')) && |
| 769 | !empty($this->getSetting('mailchimp', 'list')) && |
| 770 | !empty($this->getSetting('mailchimp', 'server')), |
| 771 | 'checkedByDefault' => $this->getSetting('mailchimp', 'checkedByDefault'), |
| 772 | ], |
| 773 | 'notifications' => [ |
| 774 | 'sendAllCF' => $this->getSetting('notifications', 'sendAllCF'), |
| 775 | 'senderEmail' => $this->getSetting('notifications', 'senderEmail'), |
| 776 | 'sms' => [ |
| 777 | 'signedIn' => $this->getSetting('notifications', 'smsSignedIn'), |
| 778 | ], |
| 779 | 'whatsApp' => [ |
| 780 | 'active' => Licence\Licence::isFeatureEnabledWithLicense( |
| 781 | 'whatsapp', |
| 782 | $this->getSetting('featuresIntegrations', 'whatsapp') |
| 783 | ) |
| 784 | && $this->getSetting('notifications', 'whatsAppPhoneID') |
| 785 | && $this->getSetting('notifications', 'whatsAppAccessToken') |
| 786 | && $this->getSetting('notifications', 'whatsAppBusinessID'), |
| 787 | 'phoneId' => $this->getSetting('notifications', 'whatsAppPhoneID'), |
| 788 | ], |
| 789 | ], |
| 790 | 'outlookCalendar' => [ |
| 791 | 'active' => Licence\Licence::isFeatureEnabledWithLicense( |
| 792 | 'outlookCalendar', |
| 793 | $this->getSetting('featuresIntegrations', 'outlookCalendar') |
| 794 | ) && |
| 795 | (($this->getSetting('outlookCalendar', 'clientID') && |
| 796 | $this->getSetting('outlookCalendar', 'clientSecret')) || |
| 797 | $this->getSetting('outlookCalendar', 'accessToken')), |
| 798 | 'microsoftTeams' => $this->getSetting('outlookCalendar', 'enableMicrosoftTeams'), |
| 799 | 'hasAccessToken' => !empty($this->getSetting('outlookCalendar', 'accessToken')) && |
| 800 | $this->getSetting('outlookCalendar', 'accessToken') !== 'null', |
| 801 | |
| 802 | ], |
| 803 | 'pageColumnSettings' => $this->getCategorySettings('pageColumnSettings'), |
| 804 | 'payments' => [ |
| 805 | 'barion' => [ |
| 806 | 'active' => |
| 807 | Licence\Licence::isFeatureEnabledWithLicense( |
| 808 | 'barion', |
| 809 | $this->getSetting('featuresIntegrations', 'barion') |
| 810 | ) && |
| 811 | $this->getSetting('payments', 'barion')['enabled'] && |
| 812 | (($this->getSetting('payments', 'barion')['sandboxMode'] && $this->getSetting( |
| 813 | 'payments', |
| 814 | 'barion' |
| 815 | )['sandboxPOSKey'] && $this->getSetting('payments', 'barion')['payeeEmail']) || |
| 816 | (! $this->getSetting('payments', 'barion')['sandboxMode'] && $this->getSetting( |
| 817 | 'payments', |
| 818 | 'barion' |
| 819 | )['livePOSKey'] && $this->getSetting('payments', 'barion')['payeeEmail'])) |
| 820 | ], |
| 821 | 'currency' => $this->getSetting('payments', 'symbol'), |
| 822 | 'defaultPaymentMethod' => $this->getSetting('payments', 'defaultPaymentMethod'), |
| 823 | 'mollie' => [ |
| 824 | 'active' => |
| 825 | Licence\Licence::isFeatureEnabledWithLicense( |
| 826 | 'mollie', |
| 827 | $this->getSetting('featuresIntegrations', 'mollie') |
| 828 | ) && |
| 829 | $this->getSetting('payments', 'mollie')['enabled'] && |
| 830 | (($this->getSetting('payments', 'mollie')['testMode'] && $this->getSetting( |
| 831 | 'payments', |
| 832 | 'mollie' |
| 833 | )['testApiKey']) || |
| 834 | (! $this->getSetting('payments', 'mollie')['testMode'] && $this->getSetting( |
| 835 | 'payments', |
| 836 | 'mollie' |
| 837 | )['liveApiKey'])) |
| 838 | ], |
| 839 | 'onSite' => $this->getSetting('payments', 'onSite'), |
| 840 | 'taxes' => array_merge( |
| 841 | $this->getSetting('payments', 'taxes'), |
| 842 | [ |
| 843 | 'enabled' => Licence\Licence::isFeatureEnabledWithLicense( |
| 844 | 'tax', |
| 845 | $this->getSetting('featuresIntegrations', 'tax') |
| 846 | ) |
| 847 | ] |
| 848 | ), |
| 849 | 'paymentLinks' => [ |
| 850 | 'enabled' => $this->getSetting('payments', 'paymentLinks')['enabled'], |
| 851 | 'changeBookingStatus' => $this->getSetting('payments', 'paymentLinks')['changeBookingStatus'], |
| 852 | 'redirectUrl' => $this->getSetting('payments', 'paymentLinks')['redirectUrl'] |
| 853 | ], |
| 854 | 'payPal' => [ |
| 855 | 'active' => |
| 856 | Licence\Licence::isFeatureEnabledWithLicense( |
| 857 | 'payPal', |
| 858 | $this->getSetting('featuresIntegrations', 'payPal') |
| 859 | ) && |
| 860 | $this->getSetting('payments', 'payPal')['enabled'] && |
| 861 | (($this->getSetting('payments', 'payPal')['sandboxMode'] && $this->getSetting( |
| 862 | 'payments', |
| 863 | 'payPal' |
| 864 | )['testApiClientId'] && $this->getSetting('payments', 'payPal')['testApiSecret']) || |
| 865 | (! $this->getSetting('payments', 'payPal')['sandboxMode'] && $this->getSetting( |
| 866 | 'payments', |
| 867 | 'payPal' |
| 868 | )['liveApiClientId'] && $this->getSetting('payments', 'payPal')['liveApiSecret'])) |
| 869 | ], |
| 870 | 'priceNumberOfDecimals' => $this->getSetting('payments', 'priceNumberOfDecimals'), |
| 871 | 'priceSeparator' => $this->getSetting('payments', 'priceSeparator'), |
| 872 | 'priceSymbolPosition' => $this->getSetting('payments', 'priceSymbolPosition'), |
| 873 | 'razorpay' => [ |
| 874 | 'active' => |
| 875 | Licence\Licence::isFeatureEnabledWithLicense( |
| 876 | 'razorpay', |
| 877 | $this->getSetting('featuresIntegrations', 'razorpay') |
| 878 | ) && |
| 879 | $this->getSetting('payments', 'razorpay')['enabled'] && |
| 880 | (($this->getSetting('payments', 'razorpay')['testMode'] && $this->getSetting( |
| 881 | 'payments', |
| 882 | 'razorpay' |
| 883 | )['testKeyId'] && $this->getSetting('payments', 'razorpay')['testKeySecret']) || |
| 884 | (! $this->getSetting('payments', 'razorpay')['testMode'] && $this->getSetting( |
| 885 | 'payments', |
| 886 | 'razorpay' |
| 887 | )['liveKeyId'] && $this->getSetting('payments', 'razorpay')['liveKeySecret'])) |
| 888 | ], |
| 889 | 'stripe' => [ |
| 890 | 'active' => |
| 891 | Licence\Licence::isFeatureEnabledWithLicense( |
| 892 | 'stripe', |
| 893 | $this->getSetting('featuresIntegrations', 'stripe') |
| 894 | ) && |
| 895 | $this->getSetting('payments', 'stripe')['enabled'] && |
| 896 | (($this->getSetting('payments', 'stripe')['testMode'] && $this->getSetting( |
| 897 | 'payments', |
| 898 | 'stripe' |
| 899 | )['testPublishableKey'] && $this->getSetting('payments', 'stripe')['testSecretKey']) || |
| 900 | (! $this->getSetting('payments', 'stripe')['testMode'] && $this->getSetting( |
| 901 | 'payments', |
| 902 | 'stripe' |
| 903 | )['livePublishableKey'] && $this->getSetting('payments', 'stripe')['liveSecretKey'])), |
| 904 | 'connect' => $this->getSetting('payments', 'stripe')['connect'], |
| 905 | ], |
| 906 | 'square' => [ |
| 907 | 'active' => |
| 908 | Licence\Licence::isFeatureEnabledWithLicense( |
| 909 | 'square', |
| 910 | $this->getSetting('featuresIntegrations', 'square') |
| 911 | ) && |
| 912 | $this->getSetting('payments', 'square')['enabled'] && |
| 913 | $this->getSetting('payments', 'square')['accessToken'] && |
| 914 | $this->getSetting('payments', 'square')['locationId'] |
| 915 | ], |
| 916 | 'wc' => [ |
| 917 | 'active' => Licence\Licence::isFeatureEnabledWithLicense( |
| 918 | 'wc', |
| 919 | $this->getSetting('featuresIntegrations', 'wc') |
| 920 | ) && |
| 921 | $this->getSetting('payments', 'wc')['enabled'], |
| 922 | 'productId' => $this->getSetting('payments', 'wc')['productId'], |
| 923 | ] |
| 924 | ], |
| 925 | |
| 926 | 'role' => $userType, |
| 927 | 'roles' => [ |
| 928 | 'providerBadges' => Licence\Licence::isFeatureEnabledWithLicense( |
| 929 | 'employeeBadge', |
| 930 | $this->getSetting('featuresIntegrations', 'employeeBadge') |
| 931 | ) ? $this->getSetting('roles', 'providerBadges') : [], |
| 932 | 'allowCustomerReschedule' => $this->getSetting('roles', 'allowCustomerReschedule'), |
| 933 | 'allowConfigureSchedule' => $this->getSetting('roles', 'allowConfigureSchedule'), |
| 934 | 'allowConfigureDaysOff' => $this->getSetting('roles', 'allowConfigureDaysOff'), |
| 935 | 'allowConfigureSpecialDays' => $this->getSetting('roles', 'allowConfigureSpecialDays'), |
| 936 | 'allowConfigureServices' => $this->getSetting('roles', 'allowConfigureServices'), |
| 937 | 'allowWriteAppointments' => $this->getSetting('roles', 'allowWriteAppointments'), |
| 938 | 'allowWriteEvents' => $this->getSetting('roles', 'allowWriteEvents'), |
| 939 | ], |
| 940 | 'weekSchedule' => $this->getCategorySettings('weekSchedule'), |
| 941 | 'wordpress' => [ |
| 942 | 'dateFormat' => $this->getSetting('wordpress', 'dateFormat'), |
| 943 | 'locale' => AMELIA_LOCALE, |
| 944 | 'startOfWeek' => (int)$this->getSetting('wordpress', 'startOfWeek'), |
| 945 | 'timeFormat' => $this->getSetting('wordpress', 'timeFormat'), |
| 946 | 'timezone' => $this->getSetting('wordpress', 'timeZoneString'), |
| 947 | 'gmtOffset' => $this->getSetting('wordpress', 'gmtOffset'), |
| 948 | ], |
| 949 | 'zoom' => [ |
| 950 | 'active' => ( |
| 951 | Licence\Licence::isFeatureEnabledWithLicense( |
| 952 | 'zoom', |
| 953 | $this->getSetting('featuresIntegrations', 'zoom') |
| 954 | ) && |
| 955 | $this->getSetting('zoom', 'accountId') && |
| 956 | $this->getSetting('zoom', 'clientId') && |
| 957 | $this->getSetting('zoom', 'clientSecret') |
| 958 | ) |
| 959 | ], |
| 960 | 'ivy' => [ |
| 961 | 'installed' => PluginInstaller::isPluginInstalled('ivyforms'), |
| 962 | 'active' => PluginInstaller::isPluginActive('ivyforms'), |
| 963 | ], |
| 964 | ]; |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * @param $settingCategoryKey |
| 969 | * @param $settingKey |
| 970 | * @param $settingValue |
| 971 | * |
| 972 | * @return mixed|void |
| 973 | */ |
| 974 | public function setSetting($settingCategoryKey, $settingKey, $settingValue) |
| 975 | { |
| 976 | $this->settingsCache[$settingCategoryKey][$settingKey] = $settingValue; |
| 977 | $settingsCopy = $this->settingsCache; |
| 978 | |
| 979 | unset($settingsCopy['wordpress']); |
| 980 | update_option('amelia_settings', json_encode($settingsCopy)); |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * @param $settingCategoryKey |
| 985 | * @param $settingValues |
| 986 | * |
| 987 | * @return mixed|void |
| 988 | */ |
| 989 | public function setCategorySettings($settingCategoryKey, $settingValues) |
| 990 | { |
| 991 | $this->settingsCache[$settingCategoryKey] = $settingValues; |
| 992 | $settingsCopy = $this->settingsCache; |
| 993 | |
| 994 | unset($settingsCopy['wordpress']); |
| 995 | update_option('amelia_settings', json_encode($settingsCopy)); |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * @param array $settings |
| 1000 | * |
| 1001 | * @return mixed|void |
| 1002 | */ |
| 1003 | public function setAllSettings($settings) |
| 1004 | { |
| 1005 | foreach ($settings as $settingCategoryKey => $settingValues) { |
| 1006 | $this->settingsCache[$settingCategoryKey] = $settingValues; |
| 1007 | } |
| 1008 | $settingsCopy = $this->settingsCache; |
| 1009 | |
| 1010 | Licence\DataModifier::restoreSettings($settingsCopy, self::getSavedSettings()); |
| 1011 | |
| 1012 | if (get_option('amelia_show_wpdt_promo') === false) { |
| 1013 | update_option('amelia_show_wpdt_promo', 'yes'); |
| 1014 | } |
| 1015 | |
| 1016 | unset($settingsCopy['wordpress']); |
| 1017 | update_option('amelia_settings', json_encode($settingsCopy)); |
| 1018 | } |
| 1019 | } |
| 1020 |