← All changes
|
src/Controllers/Hooks/Asset/class-assets-controller.php
+53
-68
3.2.0
→
4.1.0
View file →
| @@ -8,14 +8,14 @@ | ||
| 8 | 8 | |
| 9 | 9 | namespace SeQura\WC\Controllers\Hooks\Asset; |
| 10 | 10 | |
| 11 | 11 | use SeQura\WC\Controllers\Controller; |
| 12 | -use SeQura\WC\Core\Extension\Infrastructure\Configuration\Configuration; | |
| 13 | -use SeQura\WC\Services\Assets\Interface_Assets; | |
| 14 | 12 | use SeQura\WC\Services\I18n\Interface_I18n; |
| 15 | -use SeQura\WC\Services\Interface_Logger_Service; | |
| 13 | +use SeQura\WC\Services\Log\Interface_Logger_Service; | |
| 16 | 14 | use SeQura\WC\Services\Payment\Interface_Payment_Method_Service; |
| 17 | -use SeQura\WC\Services\Regex\Interface_Regex; | |
| 15 | +use SeQura\Core\Infrastructure\Utility\RegexProvider; | |
| 16 | +use SeQura\WC\Services\Service\Interface_Settings_Service; | |
| 17 | +use SeQura\WC\Services\Widgets\Interface_Widgets_Service; | |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Define the assets related functionality |
| 21 | 21 | */ |
| @@ -66,20 +66,13 @@ | ||
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Settings service |
| 69 | 69 | * |
| 70 | - * @var Configuration | |
| 70 | + * @var Interface_Settings_Service | |
| 71 | 71 | */ |
| 72 | - private $configuration; | |
| 72 | + private $settings_service; | |
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | - * Assets service | |
| 76 | - * | |
| 77 | - * @var Interface_Assets | |
| 78 | - */ | |
| 79 | - private $assets; | |
| 80 | - | |
| 81 | - /** | |
| 82 | 75 | * Payment method service |
| 83 | 76 | * |
| 84 | 77 | * @var Interface_Payment_Method_Service |
| 85 | 78 | */ |
| @@ -87,13 +80,20 @@ | ||
| 87 | 80 | |
| 88 | 81 | /** |
| 89 | 82 | * Regex service |
| 90 | 83 | * |
| 91 | - * @var Interface_Regex | |
| 84 | + * @var RegexProvider | |
| 92 | 85 | */ |
| 93 | 86 | private $regex; |
| 94 | 87 | |
| 95 | 88 | /** |
| 89 | + * Widgets service | |
| 90 | + * | |
| 91 | + * @var Interface_Widgets_Service | |
| 92 | + */ | |
| 93 | + private $widgets_service; | |
| 94 | + | |
| 95 | + /** | |
| 96 | 96 | * Constructor |
| 97 | 97 | */ |
| 98 | 98 | public function __construct( |
| 99 | 99 | string $assets_dir_url, |
| @@ -102,12 +102,12 @@ | ||
| 102 | 102 | string $wp_version, |
| 103 | 103 | Interface_I18n $i18n, |
| 104 | 104 | Interface_Logger_Service $logger, |
| 105 | 105 | string $templates_path, |
| 106 | - Configuration $configuration, | |
| 107 | - Interface_Assets $assets, | |
| 106 | + Interface_Settings_Service $settings_service, | |
| 108 | 107 | Interface_Payment_Method_Service $payment_method_service, |
| 109 | - Interface_Regex $regex | |
| 108 | + RegexProvider $regex, | |
| 109 | + Interface_Widgets_Service $widgets_service | |
| 110 | 110 | ) { |
| 111 | 111 | parent::__construct( $logger, $templates_path ); |
| 112 | 112 | $this->assets_dir_url = $assets_dir_url; |
| 113 | 113 | $this->assets_dir_path = $assets_dir_path; |
| @@ -113,13 +113,13 @@ | ||
| 113 | 113 | $this->assets_dir_path = $assets_dir_path; |
| 114 | 114 | $this->assets_version = $assets_version; |
| 115 | 115 | $this->i18n = $i18n; |
| 116 | 116 | $this->logger = $logger; |
| 117 | - $this->configuration = $configuration; | |
| 118 | - $this->assets = $assets; | |
| 117 | + $this->settings_service = $settings_service; | |
| 119 | 118 | $this->payment_method_service = $payment_method_service; |
| 120 | 119 | $this->regex = $regex; |
| 121 | 120 | $this->wp_version = $wp_version; |
| 121 | + $this->widgets_service = $widgets_service; | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Enqueue styles and scripts in WP-Admin |
| @@ -127,13 +127,13 @@ | ||
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | 129 | public function enqueue_admin() { |
| 130 | 130 | $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ ); |
| 131 | - if ( ! $this->configuration->is_settings_page() ) { | |
| 131 | + if ( ! $this->settings_service->is_settings_page() ) { | |
| 132 | 132 | return; |
| 133 | 133 | } |
| 134 | 134 | // Styles. |
| 135 | - \wp_enqueue_style( self::HANDLE_CORE, "{$this->assets_dir_url}/css/sequra-core.css", array(), self::INTEGRATION_CORE_VERSION ); | |
| 135 | + \wp_enqueue_style( self::HANDLE_CORE, "{$this->assets_dir_url}/integration-core-ui/css/sequra-core.css", array(), self::INTEGRATION_CORE_VERSION ); | |
| 136 | 136 | |
| 137 | 137 | // Scripts. |
| 138 | 138 | \wp_register_script( self::HANDLE_SETTINGS_PAGE, "{$this->assets_dir_url}/js/dist/page/settings.min.js", array(), $this->assets_version, true ); |
| 139 | 139 | \wp_localize_script( self::HANDLE_SETTINGS_PAGE, 'SequraFE', $this->get_sequra_fe_l10n() ); |
| @@ -146,35 +146,37 @@ | ||
| 146 | 146 | * @return mixed[] |
| 147 | 147 | */ |
| 148 | 148 | private function get_sequra_fe_l10n(): array { |
| 149 | 149 | $connection_config = array( |
| 150 | - 'getConnectionDataUrl' => \get_rest_url( null, 'sequra/v1/onboarding/data/{storeId}' ), | |
| 150 | + 'getConnectionDataUrl' => \get_rest_url( null, 'sequra/v1/onboarding/data/{storeId}' ), | |
| 151 | + 'getDeploymentsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/deployments/{storeId}' ), | |
| 152 | + 'getNotConnectedDeploymentsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/deployments/not-connected/{storeId}' ), | |
| 151 | 153 | ); |
| 152 | 154 | $payment_page_config = array_merge( |
| 153 | 155 | $connection_config, |
| 154 | 156 | array( |
| 155 | - 'getPaymentMethodsUrl' => \get_rest_url( null, 'sequra/v1/payment/methods/{storeId}/{merchantId}' ), | |
| 156 | - 'getAllPaymentMethodsUrl' => \get_rest_url( null, 'sequra/v1/payment/methods/{storeId}' ), | |
| 157 | - 'getSellingCountriesUrl' => \get_rest_url( null, 'sequra/v1/onboarding/countries/selling/{storeId}' ), | |
| 158 | - 'getCountrySettingsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/countries/{storeId}' ), | |
| 159 | - 'validateConnectionDataUrl' => \get_rest_url( null, 'sequra/v1/onboarding/data/validate/{storeId}' ), | |
| 157 | + 'getPaymentMethodsUrl' => \get_rest_url( null, 'sequra/v1/payment/methods/{storeId}/{merchantId}' ), | |
| 158 | + 'getAllAvailablePaymentMethodsUrl' => \get_rest_url( null, 'sequra/v1/payment/methods/{storeId}' ), | |
| 159 | + 'getSellingCountriesUrl' => \get_rest_url( null, 'sequra/v1/onboarding/countries/selling/{storeId}' ), | |
| 160 | + 'getCountrySettingsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/countries/{storeId}' ), | |
| 161 | + 'validateConnectionDataUrl' => \get_rest_url( null, 'sequra/v1/onboarding/data/validate/{storeId}' ), | |
| 160 | 162 | ) |
| 161 | 163 | ); |
| 162 | 164 | $onboarding_page_config = array_merge( |
| 163 | 165 | $payment_page_config, |
| 164 | 166 | array( |
| 165 | - 'saveConnectionDataUrl' => \get_rest_url( null, 'sequra/v1/onboarding/data/{storeId}' ), | |
| 166 | 167 | 'saveCountrySettingsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/countries/{storeId}' ), |
| 167 | 168 | 'getWidgetSettingsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/widgets/{storeId}' ), |
| 168 | 169 | 'saveWidgetSettingsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/widgets/{storeId}' ), |
| 170 | + 'disconnectUrl' => \get_rest_url( null, 'sequra/v1/onboarding/data/disconnect/{storeId}' ), | |
| 171 | + 'connectUrl' => \get_rest_url( null, 'sequra/v1/onboarding/data/connect/{storeId}' ), | |
| 169 | 172 | ) |
| 170 | 173 | ); |
| 171 | 174 | $page_config = array( |
| 172 | - 'onboarding' => $onboarding_page_config, | |
| 173 | - 'settings' => array_merge( | |
| 175 | + 'onboarding' => $onboarding_page_config, | |
| 176 | + 'settings' => array_merge( | |
| 174 | 177 | $onboarding_page_config, |
| 175 | 178 | array( |
| 176 | - 'getShopPaymentMethodsUrl' => '', // Not used in this implementation. | |
| 177 | 179 | 'getShopCategoriesUrl' => \get_rest_url( null, 'sequra/v1/settings/shop-categories/{storeId}' ), |
| 178 | 180 | 'getGeneralSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/general/{storeId}' ), |
| 179 | 181 | 'saveGeneralSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/general/{storeId}' ), |
| 180 | 182 | 'getShopOrderStatusesUrl' => \get_rest_url( null, 'sequra/v1/settings/order-status/list/{storeId}' ), |
| @@ -179,21 +181,14 @@ | ||
| 179 | 181 | 'saveGeneralSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/general/{storeId}' ), |
| 180 | 182 | 'getShopOrderStatusesUrl' => \get_rest_url( null, 'sequra/v1/settings/order-status/list/{storeId}' ), |
| 181 | 183 | 'getOrderStatusMappingSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/order-status/{storeId}' ), |
| 182 | 184 | 'saveOrderStatusMappingSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/order-status/{storeId}' ), |
| 183 | - 'disconnectUrl' => \get_rest_url( null, 'sequra/v1/onboarding/data/disconnect/{storeId}' ), | |
| 184 | 185 | ) |
| 185 | 186 | ), |
| 186 | - 'payment' => $payment_page_config, | |
| 187 | - 'transactions' => array_merge( | |
| 187 | + 'payment' => $payment_page_config, | |
| 188 | + 'advanced' => array_merge( | |
| 188 | 189 | $connection_config, |
| 189 | 190 | array( |
| 190 | - 'getTransactionLogsUrl' => \get_rest_url( null, 'sequra/v1/log/{storeId}' ), | |
| 191 | - ) | |
| 192 | - ), | |
| 193 | - 'advanced' => array_merge( | |
| 194 | - $connection_config, | |
| 195 | - array( | |
| 196 | 191 | 'getLogsUrl' => \get_rest_url( null, 'sequra/v1/log/{storeId}' ), |
| 197 | 192 | 'removeLogsUrl' => \get_rest_url( null, 'sequra/v1/log/{storeId}' ), |
| 198 | 193 | 'getLogsSettingsUrl' => \get_rest_url( null, 'sequra/v1/log/settings/{storeId}' ), |
| 199 | 194 | 'saveLogsSettingsUrl' => \get_rest_url( null, 'sequra/v1/log/settings/{storeId}' ), |
| @@ -209,25 +204,24 @@ | ||
| 209 | 204 | 'shopNameUrl' => \get_rest_url( null, 'sequra/v1/settings/shop-name/{storeId}' ), |
| 210 | 205 | 'pageConfiguration' => $page_config, |
| 211 | 206 | ); |
| 212 | 207 | |
| 213 | - $pages_payment = array( 'methods' ); | |
| 214 | - $sequra_fe = array( | |
| 208 | + $sequra_fe = array( | |
| 209 | + 'flags' => array( | |
| 210 | + 'isShowCheckoutAsHostedPageFieldVisible' => false, // Not used in this implementation. | |
| 211 | + 'configurableSelectorsForMiniWidgets' => true, | |
| 212 | + 'isServiceSellingAllowed' => true, | |
| 213 | + ), | |
| 215 | 214 | 'translations' => array( |
| 216 | 215 | 'default' => $this->load_translation(), |
| 217 | 216 | 'current' => $this->load_translation( $this->i18n->get_lang() ), |
| 218 | 217 | ), |
| 219 | 218 | 'pages' => array( |
| 220 | - 'onboarding' => array( 'connect', 'countries', 'widgets' ), | |
| 219 | + 'onboarding' => array( 'deployments', 'connect', 'countries', 'widgets' ), | |
| 221 | 220 | 'settings' => array( 'general', 'connection', 'order_status', 'widget' ), |
| 222 | - 'payment' => $pages_payment, | |
| 221 | + 'payment' => array( 'methods' ), | |
| 223 | 222 | 'advanced' => array( 'debug' ), |
| 224 | 223 | ), |
| 225 | - 'integration' => array( | |
| 226 | - 'authToken' => '', // Not used in this implementation. | |
| 227 | - 'isMultistore' => count( $this->configuration->get_stores() ) > 1, | |
| 228 | - 'hasVersion' => version_compare( $this->configuration->get_marketplace_version(), $this->configuration->get_module_version(), '>' ), | |
| 229 | - ), | |
| 230 | 224 | 'generalSettings' => array( |
| 231 | 225 | 'useHostedPage' => false, |
| 232 | 226 | 'useReplacementPaymentMethod' => false, |
| 233 | 227 | 'useAllowedIPAddresses' => true, |
| @@ -235,17 +229,9 @@ | ||
| 235 | 229 | ), |
| 236 | 230 | 'isPromotional' => false, |
| 237 | 231 | '_state_controller' => $state_controller, |
| 238 | 232 | 'customHeader' => array( 'X-WP-Nonce' => \wp_create_nonce( 'wp_rest' ) ), |
| 239 | - | |
| 240 | - 'regex' => array( | |
| 241 | - 'ip' => $this->regex->ip( false ), | |
| 242 | - 'dateOrDuration' => $this->regex->date_or_duration( false ), | |
| 243 | - ), | |
| 244 | - 'miniWidgetLabels' => array( | |
| 245 | - 'messages' => $this->configuration->get_mini_widget_default_messages(), | |
| 246 | - 'messagesBelowLimit' => $this->configuration->get_mini_widget_default_messages_below_limit(), | |
| 247 | - ), | |
| 233 | + 'regex' => $this->regex->toArray(), | |
| 248 | 234 | ); |
| 249 | 235 | |
| 250 | 236 | return $sequra_fe; |
| 251 | 237 | } |
| @@ -267,18 +253,17 @@ | ||
| 267 | 253 | * |
| 268 | 254 | * @return array<string, mixed> |
| 269 | 255 | */ |
| 270 | 256 | private function get_sequra_config_params_l10n(): array { |
| 271 | - $merchant = $this->configuration->get_merchant_ref( $this->i18n->get_current_country() ); | |
| 272 | - $methods = $this->payment_method_service->get_all_widget_compatible_payment_methods( $this->configuration->get_store_id(), $merchant ); | |
| 257 | + $data = $this->widgets_service->get_widget_config_params() ?? array(); | |
| 273 | 258 | return array( |
| 274 | - 'scriptUri' => $this->assets->get_cdn_resource_uri( $this->configuration->get_env(), 'sequra-checkout.min.js' ), | |
| 275 | - 'thousandSeparator' => \wc_get_price_thousand_separator(), | |
| 276 | - 'decimalSeparator' => \wc_get_price_decimal_separator(), | |
| 277 | - 'locale' => $this->i18n->get_locale(), | |
| 278 | - 'merchant' => $merchant, | |
| 279 | - 'assetKey' => $this->configuration->get_assets_key(), | |
| 280 | - 'products' => array_column( $methods, 'product' ), | |
| 259 | + 'scriptUri' => $data['scriptUri'] ?? '', | |
| 260 | + 'thousandSeparator' => $data['thousandSeparator'] ?? '', | |
| 261 | + 'decimalSeparator' => $data['decimalSeparator'] ?? '', | |
| 262 | + 'locale' => $data['locale'] ?? '', | |
| 263 | + 'merchant' => $data['merchant'] ?? '', | |
| 264 | + 'assetKey' => $data['assetKey'] ?? '', | |
| 265 | + 'products' => $data['products'] ?? array(), | |
| 281 | 266 | ); |
| 282 | 267 | } |
| 283 | 268 | |
| 284 | 269 | /** |
| @@ -440,9 +425,9 @@ | ||
| 440 | 425 | * @param string $lang Language code. |
| 441 | 426 | * @return mixed[] |
| 442 | 427 | */ |
| 443 | 428 | private function load_translation( $lang = 'en' ): array { |
| 444 | - $path = "{$this->assets_dir_path}/lang/{$lang}.json"; | |
| 429 | + $path = "{$this->assets_dir_path}/integration-core-ui/lang/{$lang}.json"; | |
| 445 | 430 | $translations = array(); |
| 446 | 431 | |
| 447 | 432 | global $wp_filesystem; |
| 448 | 433 | require_once ABSPATH . '/wp-admin/includes/file.php'; |