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