PluginProbe
seQura / 4.1.0
seQura v4.1.0
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
← All changes | src/Controllers/Hooks/Asset/class-assets-controller.php +161 -132 3.0.24.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 */
@@ -23,8 +23,9 @@
23 23
24 24 private const HANDLE_SETTINGS_PAGE = 'sequra-settings';
25 25 private const HANDLE_CHECKOUT = 'sequra-checkout';
26 26 private const HANDLE_WIDGET = 'sequra-widget';
27 + private const HANDLE_CONFIG_PARAMS = 'sequra-config-params';
27 28 private const HANDLE_CORE = 'sequra-core';
28 29 private const INTEGRATION_CORE_VERSION = '1.0.0';
29 30 private const STRATEGY_DEFER = 'defer';
30 31
@@ -49,8 +50,15 @@
49 50 */
50 51 private $assets_version;
51 52
52 53 /**
54 + * WP Version
55 + *
56 + * @var string
57 + */
58 + private $wp_version;
59 +
60 + /**
53 61 * I18n service
54 62 *
55 63 * @var Interface_I18n
56 64 */
@@ -58,20 +66,13 @@
58 66
59 67 /**
60 68 * Settings service
61 69 *
62 - * @var Configuration
70 + * @var Interface_Settings_Service
63 71 */
64 - private $configuration;
72 + private $settings_service;
65 73
66 74 /**
67 - * Assets service
68 - *
69 - * @var Interface_Assets
70 - */
71 - private $assets;
72 -
73 - /**
74 75 * Payment method service
75 76 *
76 77 * @var Interface_Payment_Method_Service
77 78 */
@@ -79,13 +80,20 @@
79 80
80 81 /**
81 82 * Regex service
82 83 *
83 - * @var Interface_Regex
84 + * @var RegexProvider
84 85 */
85 86 private $regex;
86 87
87 88 /**
89 + * Widgets service
90 + *
91 + * @var Interface_Widgets_Service
92 + */
93 + private $widgets_service;
94 +
95 + /**
88 96 * Constructor
89 97 */
90 98 public function __construct(
91 99 string $assets_dir_url,
@@ -90,15 +98,16 @@
90 98 public function __construct(
91 99 string $assets_dir_url,
92 100 string $assets_dir_path,
93 101 string $assets_version,
102 + string $wp_version,
94 103 Interface_I18n $i18n,
95 104 Interface_Logger_Service $logger,
96 105 string $templates_path,
97 - Configuration $configuration,
98 - Interface_Assets $assets,
106 + Interface_Settings_Service $settings_service,
99 107 Interface_Payment_Method_Service $payment_method_service,
100 - Interface_Regex $regex
108 + RegexProvider $regex,
109 + Interface_Widgets_Service $widgets_service
101 110 ) {
102 111 parent::__construct( $logger, $templates_path );
103 112 $this->assets_dir_url = $assets_dir_url;
104 113 $this->assets_dir_path = $assets_dir_path;
@@ -104,29 +113,32 @@
104 113 $this->assets_dir_path = $assets_dir_path;
105 114 $this->assets_version = $assets_version;
106 115 $this->i18n = $i18n;
107 116 $this->logger = $logger;
108 - $this->configuration = $configuration;
109 - $this->assets = $assets;
117 + $this->settings_service = $settings_service;
110 118 $this->payment_method_service = $payment_method_service;
111 119 $this->regex = $regex;
120 + $this->wp_version = $wp_version;
121 + $this->widgets_service = $widgets_service;
112 122 }
113 123
114 124 /**
115 125 * Enqueue styles and scripts in WP-Admin
126 + *
127 + * @return void
116 128 */
117 - public function enqueue_admin(): void {
118 - $this->logger->log_info( 'Hook executed', __FUNCTION__, __CLASS__ );
119 - if ( ! $this->configuration->is_settings_page() ) {
129 + public function enqueue_admin() {
130 + $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
131 + if ( ! $this->settings_service->is_settings_page() ) {
120 132 return;
121 133 }
122 134 // Styles.
123 - 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 );
124 136
125 137 // Scripts.
126 - wp_register_script( self::HANDLE_SETTINGS_PAGE, "{$this->assets_dir_url}/js/dist/page/settings.min.js", array(), $this->assets_version, true );
127 - wp_localize_script( self::HANDLE_SETTINGS_PAGE, 'SequraFE', $this->get_sequra_fe_l10n() );
128 - wp_enqueue_script( self::HANDLE_SETTINGS_PAGE );
138 + \wp_register_script( self::HANDLE_SETTINGS_PAGE, "{$this->assets_dir_url}/js/dist/page/settings.min.js", array(), $this->assets_version, true );
139 + \wp_localize_script( self::HANDLE_SETTINGS_PAGE, 'SequraFE', $this->get_sequra_fe_l10n() );
140 + \wp_enqueue_script( self::HANDLE_SETTINGS_PAGE );
129 141 }
130 142
131 143 /**
132 144 * Get the SequraFE object
@@ -134,88 +146,82 @@
134 146 * @return mixed[]
135 147 */
136 148 private function get_sequra_fe_l10n(): array {
137 149 $connection_config = array(
138 - '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}' ),
139 153 );
140 154 $payment_page_config = array_merge(
141 155 $connection_config,
142 156 array(
143 - 'getPaymentMethodsUrl' => get_rest_url( null, 'sequra/v1/payment/methods/{storeId}/{merchantId}' ),
144 - 'getAllPaymentMethodsUrl' => get_rest_url( null, 'sequra/v1/payment/methods/{storeId}' ),
145 - 'getSellingCountriesUrl' => get_rest_url( null, 'sequra/v1/onboarding/countries/selling/{storeId}' ),
146 - 'getCountrySettingsUrl' => get_rest_url( null, 'sequra/v1/onboarding/countries/{storeId}' ),
147 - '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}' ),
148 162 )
149 163 );
150 164 $onboarding_page_config = array_merge(
151 165 $payment_page_config,
152 166 array(
153 - 'saveConnectionDataUrl' => get_rest_url( null, 'sequra/v1/onboarding/data/{storeId}' ),
154 - 'saveCountrySettingsUrl' => get_rest_url( null, 'sequra/v1/onboarding/countries/{storeId}' ),
155 - 'getWidgetSettingsUrl' => get_rest_url( null, 'sequra/v1/onboarding/widgets/{storeId}' ),
156 - 'saveWidgetSettingsUrl' => get_rest_url( null, 'sequra/v1/onboarding/widgets/{storeId}' ),
167 + 'saveCountrySettingsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/countries/{storeId}' ),
168 + 'getWidgetSettingsUrl' => \get_rest_url( null, 'sequra/v1/onboarding/widgets/{storeId}' ),
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}' ),
157 172 )
158 173 );
159 174 $page_config = array(
160 - 'onboarding' => $onboarding_page_config,
161 - 'settings' => array_merge(
175 + 'onboarding' => $onboarding_page_config,
176 + 'settings' => array_merge(
162 177 $onboarding_page_config,
163 178 array(
164 - 'getShopPaymentMethodsUrl' => '', // Not used in this implementation.
165 - 'getShopCategoriesUrl' => get_rest_url( null, 'sequra/v1/settings/shop-categories/{storeId}' ),
166 - 'getGeneralSettingsUrl' => get_rest_url( null, 'sequra/v1/settings/general/{storeId}' ),
167 - 'saveGeneralSettingsUrl' => get_rest_url( null, 'sequra/v1/settings/general/{storeId}' ),
168 - 'getShopOrderStatusesUrl' => get_rest_url( null, 'sequra/v1/settings/order-status/list/{storeId}' ),
169 - 'getOrderStatusMappingSettingsUrl' => get_rest_url( null, 'sequra/v1/settings/order-status/{storeId}' ),
170 - 'saveOrderStatusMappingSettingsUrl' => get_rest_url( null, 'sequra/v1/settings/order-status/{storeId}' ),
171 - 'disconnectUrl' => get_rest_url( null, 'sequra/v1/onboarding/data/disconnect/{storeId}' ),
179 + 'getShopCategoriesUrl' => \get_rest_url( null, 'sequra/v1/settings/shop-categories/{storeId}' ),
180 + 'getGeneralSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/general/{storeId}' ),
181 + 'saveGeneralSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/general/{storeId}' ),
182 + 'getShopOrderStatusesUrl' => \get_rest_url( null, 'sequra/v1/settings/order-status/list/{storeId}' ),
183 + 'getOrderStatusMappingSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/order-status/{storeId}' ),
184 + 'saveOrderStatusMappingSettingsUrl' => \get_rest_url( null, 'sequra/v1/settings/order-status/{storeId}' ),
172 185 )
173 186 ),
174 - 'payment' => $payment_page_config,
175 - 'transactions' => array_merge(
187 + 'payment' => $payment_page_config,
188 + 'advanced' => array_merge(
176 189 $connection_config,
177 190 array(
178 - 'getTransactionLogsUrl' => get_rest_url( null, 'sequra/v1/log/{storeId}' ),
191 + 'getLogsUrl' => \get_rest_url( null, 'sequra/v1/log/{storeId}' ),
192 + 'removeLogsUrl' => \get_rest_url( null, 'sequra/v1/log/{storeId}' ),
193 + 'getLogsSettingsUrl' => \get_rest_url( null, 'sequra/v1/log/settings/{storeId}' ),
194 + 'saveLogsSettingsUrl' => \get_rest_url( null, 'sequra/v1/log/settings/{storeId}' ),
179 195 )
180 196 ),
181 - 'advanced' => array_merge(
182 - $connection_config,
183 - array(
184 - 'getLogsUrl' => get_rest_url( null, 'sequra/v1/log/{storeId}' ),
185 - 'removeLogsUrl' => get_rest_url( null, 'sequra/v1/log/{storeId}' ),
186 - 'getLogsSettingsUrl' => get_rest_url( null, 'sequra/v1/log/settings/{storeId}' ),
187 - 'saveLogsSettingsUrl' => get_rest_url( null, 'sequra/v1/log/settings/{storeId}' ),
188 - )
189 - ),
190 197 );
191 198
192 199 $state_controller = array(
193 - 'storesUrl' => get_rest_url( null, 'sequra/v1/settings/stores/{storeId}' ),
194 - 'currentStoreUrl' => get_rest_url( null, 'sequra/v1/settings/current-store' ),
195 - 'stateUrl' => get_rest_url( null, 'sequra/v1/settings/state/{storeId}' ),
196 - 'versionUrl' => get_rest_url( null, 'sequra/v1/settings/version/{storeId}' ),
197 - 'shopNameUrl' => get_rest_url( null, 'sequra/v1/settings/shop-name/{storeId}' ),
200 + 'storesUrl' => \get_rest_url( null, 'sequra/v1/settings/stores/{storeId}' ),
201 + 'currentStoreUrl' => \get_rest_url( null, 'sequra/v1/settings/current-store' ),
202 + 'stateUrl' => \get_rest_url( null, 'sequra/v1/settings/state/{storeId}' ),
203 + 'versionUrl' => \get_rest_url( null, 'sequra/v1/settings/version/{storeId}' ),
204 + 'shopNameUrl' => \get_rest_url( null, 'sequra/v1/settings/shop-name/{storeId}' ),
198 205 'pageConfiguration' => $page_config,
199 206 );
200 207
201 - $pages_payment = array( 'methods' );
202 - $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 + ),
203 214 'translations' => array(
204 215 'default' => $this->load_translation(),
205 216 'current' => $this->load_translation( $this->i18n->get_lang() ),
206 217 ),
207 218 'pages' => array(
208 - 'onboarding' => array( 'connect', 'countries', 'widgets' ),
219 + 'onboarding' => array( 'deployments', 'connect', 'countries', 'widgets' ),
209 220 'settings' => array( 'general', 'connection', 'order_status', 'widget' ),
210 - 'payment' => $pages_payment,
221 + 'payment' => array( 'methods' ),
211 222 'advanced' => array( 'debug' ),
212 223 ),
213 - 'integration' => array(
214 - 'authToken' => '', // Not used in this implementation.
215 - 'isMultistore' => count( $this->configuration->get_stores() ) > 1,
216 - 'hasVersion' => version_compare( $this->configuration->get_marketplace_version(), $this->configuration->get_module_version(), '>' ),
217 - ),
218 224 'generalSettings' => array(
219 225 'useHostedPage' => false,
220 226 'useReplacementPaymentMethod' => false,
221 227 'useAllowedIPAddresses' => true,
@@ -222,18 +228,10 @@
222 228 'useOrderReporting' => false,
223 229 ),
224 230 'isPromotional' => false,
225 231 '_state_controller' => $state_controller,
226 - 'customHeader' => array( 'X-WP-Nonce' => wp_create_nonce( 'wp_rest' ) ),
227 -
228 - 'regex' => array(
229 - 'ip' => $this->regex->ip( false ),
230 - 'dateOrDuration' => $this->regex->date_or_duration( false ),
231 - ),
232 - 'miniWidgetLabels' => array(
233 - 'messages' => $this->configuration->get_mini_widget_default_messages(),
234 - 'messagesBelowLimit' => $this->configuration->get_mini_widget_default_messages_below_limit(),
235 - ),
232 + 'customHeader' => array( 'X-WP-Nonce' => \wp_create_nonce( 'wp_rest' ) ),
233 + 'regex' => $this->regex->toArray(),
236 234 );
237 235
238 236 return $sequra_fe;
239 237 }
@@ -243,31 +241,39 @@
243 241 *
244 242 * @return array<string, mixed>
245 243 */
246 244 private function get_sequra_widget_facade_l10n(): array {
247 - $merchant = $this->configuration->get_merchant_ref( $this->i18n->get_current_country() );
248 - $methods = $this->payment_method_service->get_all_widget_compatible_payment_methods( $this->configuration->get_store_id(), $merchant );
249 245 return array(
250 - 'scriptUri' => $this->assets->get_cdn_resource_uri( $this->configuration->get_env(), 'sequra-checkout.min.js' ),
251 - 'thousandSeparator' => wc_get_price_thousand_separator(),
252 - 'decimalSeparator' => wc_get_price_decimal_separator(),
253 - 'locale' => $this->i18n->get_locale(),
254 - 'merchant' => $merchant,
255 - 'assetKey' => $this->configuration->get_assets_key(),
256 - 'products' => array_column( $methods, 'product' ),
257 - 'widgets' => array(),
258 - 'miniWidgets' => array(),
246 + 'widgets' => array(),
247 + 'miniWidgets' => array(),
259 248 );
260 249 }
261 250
262 251 /**
252 + * Get the SequraConfigParams object
253 + *
254 + * @return array<string, mixed>
255 + */
256 + private function get_sequra_config_params_l10n(): array {
257 + $data = $this->widgets_service->get_widget_config_params() ?? array();
258 + return array(
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(),
266 + );
267 + }
268 +
269 + /**
263 270 * Get the script arguments to enqueue based on the WP version
264 271 *
265 272 * @return array|bool
266 273 */
267 274 private function get_script_args( string $strategy, bool $in_footer ) {
268 - $wp_version = get_bloginfo( 'version' );
269 - if ( version_compare( $wp_version, '6.3', '>=' ) ) {
275 + if ( version_compare( $this->wp_version, '6.3', '>=' ) ) {
270 276 return array(
271 277 'strategy' => $strategy,
272 278 'in_footer' => $in_footer,
273 279 );
@@ -278,13 +284,13 @@
278 284 /**
279 285 * Enqueue styles and scripts in Front-End for the checkout page
280 286 */
281 287 private function enqueue_front_checkout(): void {
282 - wp_enqueue_style( self::HANDLE_CHECKOUT, "{$this->assets_dir_url}/css/checkout.css", array(), $this->assets_version );
283 - wp_register_script(
288 + \wp_enqueue_style( self::HANDLE_CHECKOUT, "{$this->assets_dir_url}/css/checkout.css", array(), $this->assets_version );
289 + \wp_register_script(
284 290 self::HANDLE_CHECKOUT,
285 291 "{$this->assets_dir_url}/js/dist/page/checkout.min.js",
286 - array(),
292 + array( self::HANDLE_CONFIG_PARAMS ),
287 293 $this->assets_version,
288 294 $this->get_script_args( self::STRATEGY_DEFER, true )
289 295 );
290 296
@@ -291,26 +297,45 @@
291 297 /**
292 298 * Check if the checkout is a Gutenberg block based version
293 299 *
294 300 * @since 3.0.0
295 - * TODO: Document the hook
296 301 */
297 302 $is_block = apply_filters(
298 303 'sequra_is_block_checkout',
299 - ! $this->is_order_pay_page() // TODO: Remove this condition once the block checkout is implemented in the order pay page.
304 + ! $this->payment_method_service->is_order_pay_page() // TODO: Remove this condition once the block checkout is implemented in the order pay page.
300 305 && class_exists( 'Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils' )
301 306 && method_exists( 'Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils', 'is_checkout_block_default' )
302 307 && \Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils::is_checkout_block_default()
303 308 );
304 309
305 - wp_localize_script(
310 + /**
311 + * Set the flag to delay the updated checkout event listener
312 + *
313 + * @since 3.2.0
314 + * @param bool $is_updated_checkout_listener_delayed
315 + * @return bool
316 + */
317 + $is_updated_checkout_listener_delayed = (bool) apply_filters( 'sequra_is_updated_checkout_listener_delayed', false );
318 +
319 + /**
320 + * Set the delay for the updated checkout event listener in milliseconds
321 + *
322 + * @since 3.2.0
323 + * @param int $updated_checkout_listener_delay
324 + * @return int
325 + */
326 + $updated_checkout_listener_delay = (int) apply_filters( 'sequra_updated_checkout_listener_delay', 0 );
327 +
328 + \wp_localize_script(
306 329 self::HANDLE_CHECKOUT,
307 330 'SeQuraCheckout',
308 331 array(
309 - 'isBlockCheckout' => $is_block,
332 + 'isBlockCheckout' => $is_block,
333 + 'isUpdatedCheckoutListenerDelayed' => $is_updated_checkout_listener_delayed,
334 + 'updatedCheckoutListenerDelay' => $updated_checkout_listener_delay,
310 335 )
311 336 );
312 - wp_enqueue_script( self::HANDLE_CHECKOUT );
337 + \wp_enqueue_script( self::HANDLE_CHECKOUT );
313 338 }
314 339
315 340 /**
316 341 * Enqueue styles and scripts in Front-End for the widgets
@@ -315,19 +340,18 @@
315 340 /**
316 341 * Enqueue styles and scripts in Front-End for the widgets
317 342 */
318 343 private function enqueue_front_widgets(): void {
319 -
320 - wp_enqueue_style( self::HANDLE_WIDGET, "{$this->assets_dir_url}/css/widget.css", array(), $this->assets_version );
321 - wp_register_script(
344 + \wp_enqueue_style( self::HANDLE_WIDGET, "{$this->assets_dir_url}/css/widget.css", array(), $this->assets_version );
345 + \wp_register_script(
322 346 self::HANDLE_WIDGET,
323 347 "{$this->assets_dir_url}/js/dist/page/widget-facade.min.js",
324 - array(),
348 + array( self::HANDLE_CONFIG_PARAMS ),
325 349 $this->assets_version,
326 350 $this->get_script_args( self::STRATEGY_DEFER, false )
327 351 );
328 - wp_localize_script( self::HANDLE_WIDGET, 'SequraWidgetFacade', $this->get_sequra_widget_facade_l10n() );
329 - wp_enqueue_script( self::HANDLE_WIDGET );
352 + \wp_localize_script( self::HANDLE_WIDGET, 'SequraWidgetFacade', $this->get_sequra_widget_facade_l10n() );
353 + \wp_enqueue_script( self::HANDLE_WIDGET );
330 354 }
331 355
332 356 /**
333 357 * Check if the current post has the widget shortcode in its content
@@ -332,13 +356,13 @@
332 356 /**
333 357 * Check if the current post has the widget shortcode in its content
334 358 */
335 359 private function has_widget_shortcode(): bool {
336 - if ( is_checkout() || is_cart() || ! is_singular() ) {
360 + if ( \is_checkout() || \is_cart() || ! \is_singular() ) {
337 361 return false;
338 362 }
339 363 global $post;
340 - return has_shortcode( $post->post_content, 'sequra_widget' );
364 + return \has_shortcode( $post->post_content, 'sequra_widget' );
341 365 }
342 366
343 367 /**
344 368 * Check if the current post has the cart widget shortcode in its content
@@ -343,13 +367,13 @@
343 367 /**
344 368 * Check if the current post has the cart widget shortcode in its content
345 369 */
346 370 private function has_cart_widget_shortcode(): bool {
347 - if ( is_checkout() || is_product() || ! is_page() ) {
371 + if ( \is_checkout() || \is_product() || ! \is_page() ) {
348 372 return false;
349 373 }
350 374 global $post;
351 - return has_shortcode( $post->post_content, 'sequra_cart_widget' );
375 + return \has_shortcode( $post->post_content, 'sequra_cart_widget' );
352 376 }
353 377
354 378 /**
355 379 * Check if the current post has the cart widget shortcode in its content
@@ -354,38 +378,43 @@
354 378 /**
355 379 * Check if the current post has the cart widget shortcode in its content
356 380 */
357 381 private function has_product_listing_widget_shortcode(): bool {
358 - if ( is_checkout() || is_product() || is_cart() || ! is_page() ) {
382 + if ( \is_checkout() || \is_product() || \is_cart() || ! \is_page() ) {
359 383 return false;
360 384 }
361 385 global $post;
362 - return has_shortcode( $post->post_content, 'sequra_product_listing_widget' );
386 + return \has_shortcode( $post->post_content, 'sequra_product_listing_widget' );
363 387 }
364 -
388 +
365 389 /**
366 - * Check if the current page is the order pay page
390 + * Enqueue styles and scripts in Front-End
391 + *
392 + * @return void
367 393 */
368 - private function is_order_pay_page(): bool {
369 - return ( (int) strval( get_query_var( 'order-pay' ) ) ) > 0;
370 - }
394 + public function enqueue_front() {
395 + $this->logger->log_debug( 'Hook executed', __FUNCTION__, __CLASS__ );
371 396
372 - /**
373 - * Enqueue styles and scripts in Front-End
374 - */
375 - public function enqueue_front(): void {
376 - $this->logger->log_info( 'Hook executed', __FUNCTION__, __CLASS__ );
377 - if ( is_checkout() || $this->is_order_pay_page() ) {
397 + \wp_register_script(
398 + self::HANDLE_CONFIG_PARAMS,
399 + "{$this->assets_dir_url}/js/dist/page/sequra-config-params.min.js",
400 + array(),
401 + $this->assets_version,
402 + $this->get_script_args( self::STRATEGY_DEFER, false )
403 + );
404 + \wp_localize_script( self::HANDLE_CONFIG_PARAMS, 'SequraConfigParams', $this->get_sequra_config_params_l10n() );
405 +
406 + if ( $this->payment_method_service->is_checkout() ) {
378 407 $this->enqueue_front_checkout();
379 408 }
380 409
381 - if ( is_product()
410 + if ( \is_product()
382 411 || $this->has_widget_shortcode()
383 - || is_cart()
412 + || \is_cart()
384 413 || $this->has_cart_widget_shortcode()
385 - || is_product_category()
386 - || is_product_tag()
387 - || is_shop()
414 + || \is_product_category()
415 + || \is_product_tag()
416 + || \is_shop()
388 417 || $this->has_product_listing_widget_shortcode() ) {
389 418 $this->enqueue_front_widgets();
390 419 }
391 420 }
@@ -396,9 +425,9 @@
396 425 * @param string $lang Language code.
397 426 * @return mixed[]
398 427 */
399 428 private function load_translation( $lang = 'en' ): array {
400 - $path = "{$this->assets_dir_path}/lang/{$lang}.json";
429 + $path = "{$this->assets_dir_path}/integration-core-ui/lang/{$lang}.json";
401 430 $translations = array();
402 431
403 432 global $wp_filesystem;
404 433 require_once ABSPATH . '/wp-admin/includes/file.php';