diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eaa8d8bd9..d65c7d44e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,26 @@ repos: # Websec hook is MANDATORY, DO NOT comment it. - repo: git@github.com-emu:melisource/fury_websec-git-hooks - rev: v1.1.0 + rev: v2.0.0 hooks: - id: pre_commit_hook stages: [commit] - id: post_commit_hook stages: [post-commit] - - repo: git@github.com:melisource/fury_datasec-git-hooks.git - rev: 1.0.3 + - repo: git@github.com-emu:melisource/fury_datasec-git-hooks.git + rev: 1.2.0 hooks: - id: pre_commit_hook - stages: [ commit ] - verbose: true \ No newline at end of file + stages: [commit] + verbose: true + - id: post_commit_hook + stages: [post-commit] + + - repo: local + hooks: + - id: add-index + name: Add index.php + stages: [pre-commit] + language: script + entry: ./bin/add-index.sh \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cc12c8e1..4756ffa11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [7.8.1] - 2024-10-07 + +### Added +- **Silence is golden** directive implemented to enhance security for WordPress sites. +- **Sending new field to get the plugin version** from the stores on funnel to improve onboarding. + +### Changed +- **Modified the way asset's are loaded into the store.** + +### Fixed +- **Resolved issues with loading minified CSS and JS files** in debugging environments. +- **Refined translations for ES-all** languages. + ## [7.8.0] - 2024-09-23 ### Changed diff --git a/assets/css/admin/credits/index.php b/assets/css/admin/credits/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/assets/css/admin/credits/index.php @@ -0,0 +1,13 @@ +> $FILE <official documentation for more information on the specific fields to configure. == Changelog == -= v7.8.0 (23/09/2024) = += v7.8.1 (07/10/2024) = +* Added: +- Silence is golden directive implemented to enhance security for WordPress sites. + * Changed: -- Rebranded and revamped the CreditsGateway, improving overall user experience and aligning the visual identity with our updated brand guidelines, making it more intuitive and modern. -- Compressed several images without losing quality, which reduces the plugin bundle size and leads to faster download and installation times, improving performance without sacrificing visual fidelity. -- Removed implicit nullable parameter marking and replaced it with explicit nullable types, enhancing code clarity and reducing potential bugs related to type handling, thus improving code reliability. +- Modified the way asset's are loaded into the store. +- Sending new field to get the plugin version from the stores to improve onboarding. -* Fixed -- Corrected the support component's link URL, ensuring users are directed to the appropriate help resources. +* Fixed: +- Resolved issues with loading minified CSS and JS files in debugging environments. +- Refined translations for ES-all languages. [See changelog for all versions](https://github.com/mercadopago/cart-woocommerce/blob/main/CHANGELOG.md). diff --git a/src/Admin/Settings.php b/src/Admin/Settings.php index b61c643d4..08b9d9393 100644 --- a/src/Admin/Settings.php +++ b/src/Admin/Settings.php @@ -178,17 +178,17 @@ public function loadScriptsAndStyles(): void if ($this->canLoadScriptsAndStyles()) { $this->scripts->registerAdminStyle( 'mercadopago_settings_admin_css', - $this->url->getPluginFileUrl('assets/css/admin/mp-admin-settings', '.css') + $this->url->getCssAsset('admin/mp-admin-settings') ); $this->scripts->registerAdminStyle( 'mercadopago_admin_configs_css', - $this->url->getPluginFileUrl('assets/css/admin/mp-admin-configs', '.css') + $this->url->getCssAsset('admin/mp-admin-configs') ); $this->scripts->registerAdminScript( 'mercadopago_settings_admin_js', - $this->url->getPluginFileUrl('assets/js/admin/mp-admin-settings', '.js'), + $this->url->getJsAsset('admin/mp-admin-settings'), [ 'nonce' => $this->nonce->generateNonce(self::NONCE_ID), 'show_advanced_text' => $this->translations->storeSettings['accordion_advanced_store_show'], diff --git a/src/Admin/index.php b/src/Admin/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/src/Admin/index.php @@ -0,0 +1,13 @@ +scriptName); $scriptPath = $this->mercadopago->helpers->url->getPluginFileUrl("build/$this->scriptName.block", '.js', true); - $assetPath = $this->mercadopago->helpers->url->getPluginFilePath("build/$this->scriptName.block.asset", '.php', true); + $assetPath = $this->mercadopago->helpers->url->getPluginFileUrl("build/$this->scriptName.block.asset", '.php', true); $version = ''; $deps = []; diff --git a/src/Blocks/index.php b/src/Blocks/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/src/Blocks/index.php @@ -0,0 +1,13 @@ +options->get(self::EXECUTE_ACTIVATED_PLUGIN, '') === 'yes'; + return (bool) $this->options->get(self::EXECUTE_ACTIVATED_PLUGIN); } /** * @param string $execute */ - public function setExecuteActivate(string $execute): void + public function setExecuteActivate(bool $execute): void + { + $this->options->set(self::EXECUTE_ACTIVATED_PLUGIN, (int) $execute); + } + + public function getExecuteAfterPluginUpdate(): bool + { + return (bool) $this->options->get(self::EXECUTE_AFTER_UPDATE); + } + + public function setExecuteAfterPluginUpdate(bool $execute): void { - $this->options->set(self::EXECUTE_ACTIVATED_PLUGIN, $execute); + $this->options->set(self::EXECUTE_AFTER_UPDATE, (int) $execute); } /** diff --git a/src/Configs/index.php b/src/Configs/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/src/Configs/index.php @@ -0,0 +1,13 @@ +datadog = Datadog::getInstance(); } - public function getInstallationId(): void - { - if ($this->validateStartFunnel()) { - $this->runWithTreatment(function () { - $createSellerFunnelBase = $this->sdk->getCreateSellerFunnelBaseInstance(); - $createSellerFunnelBase->platform_id = MP_PLATFORM_ID; - $createSellerFunnelBase->shop_url = site_url(); - $createSellerFunnelBase->platform_version = $this->getWoocommerceVersion(); - $createSellerFunnelBase->plugin_version = MP_VERSION; - $response = $createSellerFunnelBase->save(); - $this->store->setInstallationId($response->id); - $this->store->setInstallationKey($response->cpp_token); - $this->store->setExecuteActivate('no'); - }); + /** + * Create seller funnel + */ + public function create(?\Closure $after = null): void + { + if (!$this->canCreate()) { + return; } + + $this->runWithTreatment(function () use ($after) { + $createSellerFunnelBase = $this->sdk->getCreateSellerFunnelBaseInstance(); + $createSellerFunnelBase->platform_id = MP_PLATFORM_ID; + $createSellerFunnelBase->shop_url = site_url(); + $createSellerFunnelBase->platform_version = $this->getWoocommerceVersion(); + $createSellerFunnelBase->plugin_version = MP_VERSION; + $response = $createSellerFunnelBase->save(); + $this->store->setInstallationId($response->id); + $this->store->setInstallationKey($response->cpp_token); + + if (isset($after)) { + $after(); + } + }); } - public function updateStepCredentials(): void - { - if ($this->isInstallationId()) { - $this->runWithTreatment(function () { - $updateSellerFunnelBase = $this->sdk->getUpdateSellerFunnelBaseInstance(); - $updateSellerFunnelBase->id = $this->store->getInstallationId(); - $updateSellerFunnelBase->cpp_token = $this->store->getInstallationKey(); - $updateSellerFunnelBase->is_added_production_credential = !empty($this->seller->getCredentialsAccessTokenProd()); - $updateSellerFunnelBase->is_added_test_credential = !empty($this->seller->getCredentialsAccessTokenTest()); - $updateSellerFunnelBase->plugin_mode = $this->getPluginMode(); - $updateSellerFunnelBase->cust_id = $this->seller->getCustIdFromAT(); - $updateSellerFunnelBase->site_id = $this->country->countryToSiteId($this->country->getPluginDefaultCountry()); - $updateSellerFunnelBase->update(); - }); - } + public function created(): bool + { + return !empty($this->store->getInstallationId()) + && !empty($this->store->getInstallationKey()); + } + + public function updateStepCredentials(?\Closure $after = null): void + { + $this->update([ + 'is_added_production_credential' => !empty($this->seller->getCredentialsAccessTokenProd()), + 'is_added_test_credential' => !empty($this->seller->getCredentialsAccessTokenTest()), + 'plugin_mode' => $this->getPluginMode(), + 'cust_id' => $this->seller->getCustIdFromAT(), + 'site_id' => $this->country->countryToSiteId($this->country->getPluginDefaultCountry()), + ], $after); } /** * @return void */ - public function updateStepPaymentMethods(): void - { - if ($this->isInstallationId()) { - $this->runWithTreatment(function () { - $updateSellerFunnelBase = $this->sdk->getUpdateSellerFunnelBaseInstance(); - $updateSellerFunnelBase->id = $this->store->getInstallationId(); - $updateSellerFunnelBase->cpp_token = $this->store->getInstallationKey(); - $updateSellerFunnelBase->accepted_payments = $this->gateways->getEnabledPaymentGateways(); - $updateSellerFunnelBase->update(); - }); - } + public function updateStepPaymentMethods(?\Closure $after = null): void + { + $this->update(['accepted_payments' => $this->gateways->getEnabledPaymentGateways()], $after); } - public function updateStepPluginMode(): void + public function updateStepPluginMode(?\Closure $after = null): void { - if ($this->isInstallationId()) { - $this->runWithTreatment(function () { - $updateSellerFunnelBase = $this->sdk->getUpdateSellerFunnelBaseInstance(); - $updateSellerFunnelBase->id = $this->store->getInstallationId(); - $updateSellerFunnelBase->cpp_token = $this->store->getInstallationKey(); - $updateSellerFunnelBase->plugin_mode = $this->getPluginMode(); - $updateSellerFunnelBase->update(); - }); - } + $this->update(['plugin_mode' => $this->getPluginMode()], $after); } - public function updateStepUninstall(): void + public function updateStepUninstall(?\Closure $after = null): void { - if ($this->isInstallationId()) { - $this->runWithTreatment(function () { - $updateSellerFunnelBase = $this->sdk->getUpdateSellerFunnelBaseInstance(); - $updateSellerFunnelBase->id = $this->store->getInstallationId(); - $updateSellerFunnelBase->cpp_token = $this->store->getInstallationKey(); - $updateSellerFunnelBase->is_deleted = true; - $updateSellerFunnelBase->update(); - }); - } + $this->update(['is_deleted' => true], $after); } - public function updateStepDisable(): void + public function updateStepDisable(?\Closure $after = null): void { - if ($this->isInstallationId()) { - $this->runWithTreatment(function () { - $updateSellerFunnelBase = $this->sdk->getUpdateSellerFunnelBaseInstance(); - $updateSellerFunnelBase->id = $this->store->getInstallationId(); - $updateSellerFunnelBase->cpp_token = $this->store->getInstallationKey(); - $updateSellerFunnelBase->is_disabled = true; - $updateSellerFunnelBase->update(); - }); - } + $this->update(['is_disabled' => true], $after); } - public function updateStepActivate(): void + public function updateStepActivate(?\Closure $after = null): void { - if ($this->isInstallationId()) { - $this->runWithTreatment(function () { - $updateSellerFunnelBase = $this->sdk->getUpdateSellerFunnelBaseInstance(); - $updateSellerFunnelBase->id = $this->store->getInstallationId(); - $updateSellerFunnelBase->cpp_token = $this->store->getInstallationKey(); - $updateSellerFunnelBase->is_disabled = false; - $updateSellerFunnelBase->update(); - $this->store->setExecuteActivate('no'); - }); - } + $this->update(['is_disabled' => false], $after); } - public function isInstallationId(): bool + public function updateStepPluginVersion(?\Closure $after = null): void { - return !empty($this->store->getInstallationId()) - && !empty($this->store->getInstallationKey()); + $this->update(['plugin_version' => MP_VERSION], $after); + } + + /** + * Update seller funnel using the given attributes + * + * @param array $attrs Funnel attribute values map + * @param \Closure $after Function to run after funnel updated, inside treatment + */ + private function update(array $attrs, ?\Closure $after = null): void + { + if (!$this->created()) { + return; + } + + $attrs = array_merge($attrs, [ + 'id' => $this->store->getInstallationId(), + 'cpp_token' => $this->store->getInstallationKey(), + ]); + + $this->runWithTreatment(function () use ($attrs, $after) { + $updateSellerFunnelBase = $this->getUpdateSellerFunnelBaseInstance(); + + foreach ($attrs as $attr => $value) { + $updateSellerFunnelBase->$attr = $value; + } + + $updateSellerFunnelBase->update(); + + if (isset($after)) { + $after(); + } + }); } - private function validateStartFunnel(): bool + private function canCreate(): bool { - return empty($this->seller->getCredentialsAccessTokenProd()) && - !$this->isInstallationId() && - empty($this->gateways->getEnabledPaymentGateways()); + return !$this->created() + && empty($this->seller->getCredentialsAccessTokenProd()) + && empty($this->gateways->getEnabledPaymentGateways()); } private function getPluginMode(): string @@ -169,23 +167,29 @@ private function getWoocommerceVersion(): string return $GLOBALS['woocommerce']->version ?? ""; } - private function runWithTreatment($callback) + private function getUpdateSellerFunnelBaseInstance(): UpdateSellerFunnelBase + { + return $this->sdk->getEntityInstance(UpdateSellerFunnelBase::class, Constants::BASEURL_MP); + } + + private function runWithTreatment(\Closure $callback): void { try { $callback(); $this->sendSuccessEvent(); } catch (Exception $ex) { + $GLOBALS['mercadopago']->logs->file->error(sprintf("Error on %s\n%s", __METHOD__, $ex), __CLASS__); $this->sendErrorEvent($ex->getMessage()); } } - private function sendSuccessEvent() + private function sendSuccessEvent(): void { $this->datadog->sendEvent('funnel', 'success'); } - private function sendErrorEvent(string $message) + private function sendErrorEvent(string $message): void { $this->datadog->sendEvent('funnel', 'error', $message); } diff --git a/src/Funnel/UpdateSellerFunnelBase.php b/src/Funnel/UpdateSellerFunnelBase.php new file mode 100644 index 000000000..a5cf078a8 --- /dev/null +++ b/src/Funnel/UpdateSellerFunnelBase.php @@ -0,0 +1,8 @@ +mercadopago->hooks->scripts->registerAdminScript( 'wc_mercadopago_admin_components', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/admin/mp-admin-configs', '.js') + $this->mercadopago->helpers->url->getJsAsset('admin/mp-admin-configs') ); $this->mercadopago->hooks->scripts->registerAdminStyle( 'wc_mercadopago_admin_components', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/css/admin/mp-admin-configs', '.css') + $this->mercadopago->helpers->url->getCssAsset('admin/mp-admin-configs') ); } @@ -226,17 +226,17 @@ public function registerCheckoutScripts(): void { $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_checkout_components', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/mp-plugins-components', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/mp-plugins-components') ); $this->mercadopago->hooks->scripts->registerCheckoutStyle( 'wc_mercadopago_checkout_components', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/css/checkouts/mp-plugins-components', '.css') + $this->mercadopago->helpers->url->getCssAsset('checkouts/mp-plugins-components') ); $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_checkout_update', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/mp-checkout-update', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/mp-checkout-update') ); } diff --git a/src/Gateways/BasicGateway.php b/src/Gateways/BasicGateway.php index b1836fa30..819de6e0a 100644 --- a/src/Gateways/BasicGateway.php +++ b/src/Gateways/BasicGateway.php @@ -302,7 +302,7 @@ public function getPaymentFieldsParams(): array 'payment_methods_methods' => wp_json_encode($paymentMethods), 'method' => $this->mercadopago->hooks->options->getGatewayOption($this, 'method', 'redirect'), 'checkout_redirect_text' => $this->storeTranslations['checkout_redirect_text'], - 'checkout_redirect_src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/cho-pro-redirect-v2', '.png', true), + 'checkout_redirect_src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/cho-pro-redirect-v2'), 'checkout_redirect_alt' => $this->storeTranslations['checkout_redirect_alt'], 'terms_and_conditions_description' => $this->storeTranslations['terms_and_conditions_description'], 'terms_and_conditions_link_text' => $this->storeTranslations['terms_and_conditions_link_text'], @@ -370,7 +370,7 @@ public function process_payment($order_id): array private function validateBackUrl($url, $default): string { if (!empty($url) && filter_var($url, FILTER_VALIDATE_URL) === false) { - $icon = $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/icons/icon-warning', '.png', true); + $icon = $this->mercadopago->helpers->url->getImageAsset('icons/icon-warning'); return " " . $this->adminTranslations['invalid_back_url']; } @@ -499,7 +499,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_phone'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_phone'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-phone', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-phone'), 'alt' => $this->storeTranslations['checkout_benefits_alt_phone'], ], ], @@ -507,7 +507,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_wallet'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_wallet'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-wallet', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-wallet'), 'alt' => $this->storeTranslations['checkout_benefits_alt_wallet'], ], ], @@ -515,7 +515,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_protection'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_protection'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-protection', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-protection'), 'alt' => $this->storeTranslations['checkout_benefits_alt_protection'], ], ] @@ -525,7 +525,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_phone'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_phone'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-phone', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-phone', '.png', true), 'alt' => $this->storeTranslations['checkout_benefits_alt_phone'], ] ], @@ -533,7 +533,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_wallet'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_wallet_2'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-wallet', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-wallet'), 'alt' => $this->storeTranslations['checkout_benefits_alt_wallet'], ] ], @@ -541,7 +541,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_protection'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_protection'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-protection', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-protection'), 'alt' => $this->storeTranslations['checkout_benefits_alt_protection'], ] ] @@ -551,7 +551,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_wallet'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_wallet_3'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-wallet', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-wallet'), 'alt' => $this->storeTranslations['checkout_benefits_alt_wallet'], ] ], @@ -559,7 +559,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_phone_installments'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_phone_installments'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-phone-installments', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-phone-installments'), 'alt' => $this->storeTranslations['checkout_benefits_alt_phone_installments'], ] ], @@ -567,7 +567,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_protection_2'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_protection_2'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-protection', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-protection'), 'alt' => $this->storeTranslations['checkout_benefits_alt_protection'], ] ] @@ -577,7 +577,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_phone'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_phone'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-phone', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-phone'), 'alt' => $this->storeTranslations['checkout_benefits_alt_phone'], ] ], @@ -585,7 +585,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_wallet'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_wallet_3'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-wallet', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-wallet'), 'alt' => $this->storeTranslations['checkout_benefits_alt_wallet'], ] ], @@ -593,7 +593,7 @@ private function getBenefits(): array 'title' => $this->storeTranslations['checkout_benefits_title_phone_installments'], 'subtitle' => $this->storeTranslations['checkout_benefits_subtitle_phone_installments_2'], 'image' => [ - 'src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/basic/blue-phone-installments', '.png', true), + 'src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/basic/blue-phone-installments'), 'alt' => $this->storeTranslations['checkout_benefits_alt_phone_installments'], ] ] diff --git a/src/Gateways/CreditsGateway.php b/src/Gateways/CreditsGateway.php index 2544a59d5..3f5a04dba 100644 --- a/src/Gateways/CreditsGateway.php +++ b/src/Gateways/CreditsGateway.php @@ -226,16 +226,8 @@ public function payment_fields(): void */ public function getPaymentFieldsParams(): array { - $checkoutRedirectSrc = $this->mercadopago->helpers->url->getPluginFileUrl( - 'assets/images/icons/icon-mp-nobg', - '.png', - true - ); - $blocksRowIconSrc = $this->mercadopago->helpers->url->getPluginFileUrl( - 'assets/images/icons/icon-mp-admin', - '.png', - true - ); + $checkoutRedirectSrc = $this->mercadopago->helpers->url->getImageAsset('icons/icon-mp-nobg'); + $blocksRowIconSrc = $this->mercadopago->helpers->url->getImageAsset('icons/icon-mp-admin'); $amountAndCurrencyRatio = $this->getAmountAndCurrency(); return [ @@ -369,12 +361,7 @@ private function getCreditsPreviewImage($siteId): string ]; $prefix = $siteIds[$siteId] ?? ''; - - return $this->mercadopago->helpers->url->getPluginFileUrl( - 'assets/images/checkouts/credits/' . $prefix . 'checkout_preview', - '.png', - true - ); + return $this->mercadopago->helpers->url->getImageAsset('checkouts/credits/' . $prefix . 'checkout_preview'); } /** @@ -388,17 +375,17 @@ private function getCreditsInfoTemplate(): string $this->mercadopago->hooks->scripts->registerCreditsAdminStyle( 'mp_info_admin_credits_style', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/css/admin/credits/example-info', '.css') + $this->mercadopago->helpers->url->getCssAsset('admin/credits/example-info') ); $this->mercadopago->hooks->scripts->registerCreditsAdminScript( 'mp_info_admin_credits_script', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/admin/credits/example-info', '.js'), + $this->mercadopago->helpers->url->getJsAsset('admin/credits/example-info'), [ - 'computerBlueIcon' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/credits/desktop-blue-icon', '.png', true), - 'computerGrayIcon' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/credits/desktop-gray-icon', '.png', true), - 'cellphoneBlueIcon' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/credits/cellphone-blue-icon', '.png', true), - 'cellphoneGrayIcon' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/credits/cellphone-gray-icon', '.png', true), + 'computerBlueIcon' => $this->mercadopago->helpers->url->getImageAsset('checkouts/credits/desktop-blue-icon'), + 'computerGrayIcon' => $this->mercadopago->helpers->url->getImageAsset('checkouts/credits/desktop-gray-icon'), + 'cellphoneBlueIcon' => $this->mercadopago->helpers->url->getImageAsset('checkouts/credits/cellphone-blue-icon'), + 'cellphoneGrayIcon' => $this->mercadopago->helpers->url->getImageAsset('checkouts/credits/cellphone-gray-icon'), 'viewMobile' => $this->getCreditsGifPath($siteId, 'mobile'), 'viewDesktop' => $this->getCreditsGifPath($siteId, 'desktop'), 'footerDesktop' => $this->adminTranslations['credits_banner_desktop'], @@ -436,10 +423,9 @@ private function getCreditsGifPath(string $siteId, string $view): string $prefix = $siteIds[$siteId] ?? ''; - return $this->mercadopago->helpers->url->getPluginFileUrl( - 'assets/images/checkouts/credits/' . $prefix . 'view_' . $view, + return $this->mercadopago->helpers->url->getImageAsset( + 'checkouts/credits/' . $prefix . 'view_' . $view, '.gif', - true ); } @@ -455,12 +441,12 @@ public function renderCreditsBanner(): void if ($gatewayAvailable && $gatewayEnabled && $bannerEnabled) { $this->mercadopago->hooks->scripts->registerStoreStyle( 'mp-credits-modal-style', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/css/products/credits-modal', '.css') + $this->mercadopago->helpers->url->getCssAsset('products/credits-modal') ); $this->mercadopago->hooks->scripts->registerStoreScript( 'mp-credits-modal-js', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/products/credits-modal', '.js') + $this->mercadopago->helpers->url->getJsAsset('products/credits-modal') ); $this->mercadopago->hooks->scripts->registerMelidataStoreScript('/products'); diff --git a/src/Gateways/CustomGateway.php b/src/Gateways/CustomGateway.php index 2cf3b857d..acc2a3047 100644 --- a/src/Gateways/CustomGateway.php +++ b/src/Gateways/CustomGateway.php @@ -239,7 +239,7 @@ public function registerCheckoutScripts(): void $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_security_session', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/custom/session', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/custom/session') ); $this->mercadopago->hooks->scripts->registerCheckoutScript( @@ -249,17 +249,17 @@ public function registerCheckoutScripts(): void $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_custom_page', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/custom/mp-custom-page', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/custom/mp-custom-page') ); $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_custom_elements', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/custom/mp-custom-elements', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/custom/mp-custom-elements') ); $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_custom_checkout', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/custom/mp-custom-checkout', '.js'), + $this->mercadopago->helpers->url->getJsAsset('checkouts/custom/mp-custom-checkout'), [ 'public_key' => $this->mercadopago->sellerConfig->getCredentialsPublicKey(), 'intl' => $this->countryConfigs['intl'], @@ -343,15 +343,15 @@ public function getPaymentFieldsParams(): array 'test_mode_link_text' => $this->storeTranslations['test_mode_link_text'], 'test_mode_link_src' => $this->links['docs_integration_test'], 'wallet_button' => $this->mercadopago->hooks->options->getGatewayOption($this, 'wallet_button', 'yes'), - 'wallet_button_image' => $this->mercadopago->helpers->url->getPluginFileUrl("assets/images/icons/icon-logos", '.png', true), + 'wallet_button_image' => $this->mercadopago->helpers->url->getImageAsset('icons/icon-logos'), 'wallet_button_title' => $this->storeTranslations['wallet_button_title'], 'wallet_button_description' => $this->storeTranslations['wallet_button_description'], 'wallet_button_button_text' => $this->storeTranslations['wallet_button_button_text'], - 'available_payments_title_icon' => $this->mercadopago->helpers->url->getPluginFileUrl("assets/images/icons/icon-purple-card", '.png', true), + 'available_payments_title_icon' => $this->mercadopago->helpers->url->getImageAsset('icons/icon-purple-card'), 'available_payments_title' => $this->storeTranslations['available_payments_title'], - 'available_payments_image' => $this->mercadopago->helpers->url->getPluginFileUrl("assets/images/checkouts/custom/chevron-down", '.png', true), - 'available_payments_chevron_up' => $this->mercadopago->helpers->url->getPluginFileUrl("assets/images/checkouts/custom/chevron-up", '.png', true), - 'available_payments_chevron_down' => $this->mercadopago->helpers->url->getPluginFileUrl("assets/images/checkouts/custom/chevron-down", '.png', true), + 'available_payments_image' => $this->mercadopago->helpers->url->getImageAsset('checkouts/custom/chevron-down'), + 'available_payments_chevron_up' => $this->mercadopago->helpers->url->getImageAsset('checkouts/custom/chevron-up'), + 'available_payments_chevron_down' => $this->mercadopago->helpers->url->getImageAsset('checkouts/custom/chevron-down'), 'payment_methods_items' => wp_json_encode($this->getPaymentMethodsContent()), 'payment_methods_promotion_link' => $this->links['mercadopago_debts'], 'payment_methods_promotion_text' => $this->storeTranslations['payment_methods_promotion_text'], @@ -489,10 +489,8 @@ private function getWalletButtonPreviewUrl(): string $locale = 'en'; } - return $this->mercadopago->helpers->url->getPluginFileUrl( - "assets/images/gateways/wallet-button/preview-$locale", - '.png', - true + return $this->mercadopago->helpers->url->getImageAsset( + 'gateways/wallet-button/preview-' . $locale, ); } diff --git a/src/Gateways/PixGateway.php b/src/Gateways/PixGateway.php index bf4f7b98d..8f0f7fd0f 100644 --- a/src/Gateways/PixGateway.php +++ b/src/Gateways/PixGateway.php @@ -177,7 +177,7 @@ public function getPaymentFieldsParams(): array 'pix_template_title' => $this->storeTranslations['pix_template_title'], 'pix_template_subtitle' => $this->storeTranslations['pix_template_subtitle'], 'pix_template_alt' => $this->storeTranslations['pix_template_alt'], - 'pix_template_src' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/pix/pix', '.png', true), + 'pix_template_src' => $this->mercadopago->helpers->url->getImageAsset('checkouts/pix/pix'), 'terms_and_conditions_description' => $this->storeTranslations['terms_and_conditions_description'], 'terms_and_conditions_link_text' => $this->storeTranslations['terms_and_conditions_link_text'], 'terms_and_conditions_link_src' => $this->links['mercadopago_terms_and_conditions'], @@ -515,7 +515,7 @@ public function renderOrderReceivedTemplate($order): void $this->mercadopago->hooks->scripts->registerStoreStyle( 'mp_pix_image', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/css/public/mp-pix-image', '.css') + $this->mercadopago->helpers->url->getCssAsset('public/mp-pix-image') ); $this->mercadopago->hooks->template->getWoocommerceTemplate( @@ -554,13 +554,13 @@ public function renderThankYouPage($order_id): void $this->mercadopago->hooks->scripts->registerStoreStyle( 'mp_pix_thankyou', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/css/public/mp-pix-thankyou', '.css') + $this->mercadopago->helpers->url->getCssAsset('public/mp-pix-thankyou') ); $this->mercadopago->hooks->template->getWoocommerceTemplate( 'public/order/pix-order-received.php', [ - 'img_pix' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/pix/pix', '.png', true), + 'img_pix' => $this->mercadopago->helpers->url->getImageAsset('checkouts/pix/pix'), 'amount' => Numbers::formatWithCurrencySymbol($this->countryConfigs['currency_symbol'], $transactionAmount), 'qr_base64' => $qrCodeBase64, 'title_purchase_pix' => $this->storeTranslations['title_purchase_pix'], diff --git a/src/Gateways/PseGateway.php b/src/Gateways/PseGateway.php index 33d2b19ef..16f968665 100644 --- a/src/Gateways/PseGateway.php +++ b/src/Gateways/PseGateway.php @@ -203,17 +203,17 @@ public function registerCheckoutScripts(): void $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_pse_page', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/pse/mp-pse-page', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/pse/mp-pse-page') ); $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_pse_elements', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/pse/mp-pse-elements', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/pse/mp-pse-elements') ); $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_pse_checkout', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/pse/mp-pse-checkout', '.js'), + $this->mercadopago->helpers->url->getJsAsset('checkouts/pse/mp-pse-checkout'), [ 'financial_placeholder' => $this->storeTranslations ['financial_placeholder'], ] diff --git a/src/Gateways/TicketGateway.php b/src/Gateways/TicketGateway.php index 44c92c8a6..6d69c73b4 100644 --- a/src/Gateways/TicketGateway.php +++ b/src/Gateways/TicketGateway.php @@ -215,17 +215,17 @@ public function registerCheckoutScripts(): void $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_ticket_page', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/ticket/mp-ticket-page', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/ticket/mp-ticket-page') ); $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_ticket_elements', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/ticket/mp-ticket-elements', '.js') + $this->mercadopago->helpers->url->getJsAsset('checkouts/ticket/mp-ticket-elements') ); $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_ticket_checkout', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/ticket/mp-ticket-checkout', '.js'), + $this->mercadopago->helpers->url->getJsAsset('checkouts/ticket/mp-ticket-checkout'), [ 'site_id' => $this->countryConfigs['site_id'], ] diff --git a/src/Gateways/YapeGateway.php b/src/Gateways/YapeGateway.php index 6cf42abe7..dc4b9339e 100644 --- a/src/Gateways/YapeGateway.php +++ b/src/Gateways/YapeGateway.php @@ -192,7 +192,7 @@ public function registerCheckoutScripts(): void $this->mercadopago->hooks->scripts->registerCheckoutScript( 'wc_mercadopago_yape_checkout', - $this->mercadopago->helpers->url->getPluginFileUrl('assets/js/checkouts/yape/mp-yape-checkout', '.js'), + $this->mercadopago->helpers->url->getJsAsset('checkouts/yape/mp-yape-checkout'), [ 'public_key' => $this->mercadopago->sellerConfig->getCredentialsPublicKey(), ] @@ -234,9 +234,9 @@ public function getPaymentFieldsParams(): array 'footer_text' => $this->storeTranslations['footer_text'], 'test_mode_link_src' => $this->links['docs_integration_test'], 'terms_and_conditions_link_src' => $this->links['mercadopago_terms_and_conditions'], - 'input_code_icon' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/yape/yape-tooltip-icon', '.svg', true), - 'checkout_notice_icon_one' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/yape/checkout-notice-icon', '.png', true), - 'checkout_notice_icon_two' => $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/checkouts/yape/mp-transparent-icon', '.svg', true), + 'input_code_icon' => $this->mercadopago->helpers->url->getImageAsset('checkouts/yape/yape-tooltip-icon', '.svg'), + 'checkout_notice_icon_one' => $this->mercadopago->helpers->url->getImageAsset('checkouts/yape/checkout-notice-icon'), + 'checkout_notice_icon_two' => $this->mercadopago->helpers->url->getImageAsset('checkouts/yape/mp-transparent-icon', '.svg'), 'yape_tooltip_text' => $this->storeTranslations['yape_tooltip_text'], 'yape_input_code_error_message1' => $this->storeTranslations['yape_input_code_error_message1'], 'yape_input_code_error_message2' => $this->storeTranslations['yape_input_code_error_message2'], diff --git a/src/Gateways/index.php b/src/Gateways/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/src/Gateways/index.php @@ -0,0 +1,13 @@ +scripts->registerAdminStyle( 'woocommerce-mercadopago-admin-notice-css', - $this->url->getPluginFileUrl('assets/css/admin/mp-admin-notices', '.css') + $this->url->getCssAsset('admin/mp-admin-notices') ); } } @@ -105,7 +105,7 @@ public function loadAdminNoticesJs(): void if (is_admin()) { $this->scripts->registerAdminScript( 'woocommerce_mercadopago_admin_notice_js', - $this->url->getPluginFileUrl('assets/js/admin/mp-admin-notices', '.js'), + $this->url->getJsAsset('admin/mp-admin-notices'), [ 'nonce' => $this->nonce->generateNonce(self::NONCE_ID) ] @@ -146,7 +146,7 @@ function () { add_action( 'admin_notices', function () { - $cardIcon = $this->url->getPluginFileUrl('assets/images/icons/icon-mp-card', '.png', true); + $cardIcon = $this->url->getImageAsset('icons/icon-mp-card'); $title = $this->translations->notices['saved_cards_title']; $subtitle = $this->translations->notices['saved_cards_subtitle']; $buttonText = $this->translations->notices['saved_cards_button']; @@ -247,7 +247,7 @@ public function adminNoticeMissPix(): void add_action( 'admin_notices', function () { - $miniLogo = $this->url->getPluginFileUrl('assets/images/minilogo', '.png', true); + $miniLogo = $this->url->getImageAsset('minilogo'); $message = $this->translations->notices['miss_pix_text']; $textLink = $this->translations->notices['miss_pix_link']; $urlLink = $this->links['mercadopago_pix_config']; @@ -271,7 +271,7 @@ private function adminNotice(string $message, string $type, bool $dismiss): void add_action( 'admin_notices', function () use ($message, $type, $dismiss) { - $minilogo = $this->url->getPluginFileUrl('assets/images/minilogo', '.png', true); + $minilogo = $this->url->getImageAsset('minilogo'); $isDismissible = $dismiss ? 'is-dismissible' : ''; include dirname(__FILE__) . '/../../templates/admin/notices/generic-notice.php'; @@ -398,7 +398,7 @@ public function instructionalNotice(): void add_action( 'admin_notices', function () { - $minilogo = $this->url->getPluginFileUrl('assets/images/icons/icon-feedback-info', '.png', true); + $minilogo = $this->url->getImageAsset('icons/icon-feedback-info'); $title = $this->translations->notices['action_feedback_title']; $subtitle = $this->translations->notices['action_feedback_subtitle']; diff --git a/src/Helpers/PaymentMethods.php b/src/Helpers/PaymentMethods.php index fa98284dd..8149af72c 100644 --- a/src/Helpers/PaymentMethods.php +++ b/src/Helpers/PaymentMethods.php @@ -126,7 +126,7 @@ public function treatBasicPaymentMethods(array $paymentMethods): array { if (CreditsGateway::isAvailable()) { $paymentMethods[] = [ - 'src' => $this->url->getPluginFileUrl('assets/images/icons/icon-credits', '.png', true), + 'src' => $this->url->getImageAsset('icons/icon-credits'), 'alt' => 'Credits image' ]; } diff --git a/src/Helpers/Url.php b/src/Helpers/Url.php index cf3c95f64..9daea0edc 100644 --- a/src/Helpers/Url.php +++ b/src/Helpers/Url.php @@ -20,16 +20,6 @@ public function __construct(Strings $strings) $this->strings = $strings; } - /** - * Get suffix - * - * @return string - */ - public function getSuffix(): string - { - return defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; - } - /** * Get plugin file url * @@ -45,29 +35,46 @@ public function getPluginFileUrl(string $path, string $extension, bool $ignoreSu '%s%s%s%s', trailingslashit(rtrim(plugin_dir_url(plugin_dir_path(__FILE__)), '/src')), $path, - $ignoreSuffix ? '' : $this->getSuffix(), + $ignoreSuffix ? '' : '.min', $extension ); } /** - * Get plugin file path + * Get plugin css asset file url * - * @param string $path + * @param string $fileName + * + * @return string + */ + public function getCssAsset(string $fileName): string + { + return $this->getPluginFileUrl('assets/css/' . $fileName, '.css'); + } + + /** + * Get plugin js asset file url + * + * @param string $fileName + * + * @return string + */ + public function getJsAsset(string $fileName): string + { + return $this->getPluginFileUrl('assets/js/' . $fileName, '.js'); + } + + /** + * Get plugin image asset file url + * + * @param string $fileName * @param string $extension - * @param bool $ignoreSuffix * * @return string */ - public function getPluginFilePath(string $path, string $extension, bool $ignoreSuffix = false): string + public function getImageAsset(string $fileName, string $extension = '.png'): string { - return sprintf( - '%s%s%s%s', - untrailingslashit(plugin_dir_path(__FILE__)), - "/../../$path", - $ignoreSuffix ? '' : $this->getSuffix(), - $extension - ); + return $this->getPluginFileUrl('assets/images/' . $fileName, $extension, true); } /** diff --git a/src/Helpers/index.php b/src/Helpers/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/src/Helpers/index.php @@ -0,0 +1,13 @@ +url->getPluginFileUrl("assets/images/icons/$iconName", $fileExtension, true); + $path = $this->url->getImageAsset('icons/' . $iconName, $fileExtension); return apply_filters(self::GATEWAY_ICON_FILTER, $path); } diff --git a/src/Hooks/Order.php b/src/Hooks/Order.php index cd99abfa2..e395a57d3 100644 --- a/src/Hooks/Order.php +++ b/src/Hooks/Order.php @@ -167,7 +167,7 @@ private function loadScripts(WC_Order $order): void { $this->scripts->registerStoreScript( 'mp_payment_status_sync', - $this->url->getPluginFileUrl('assets/js/admin/order/payment-status-sync', '.js'), + $this->url->getJsAsset('admin/order/payment-status-sync'), [ 'order_id' => $order->get_id(), 'nonce' => $this->nonce->generateNonce(self::NONCE_ID), @@ -176,7 +176,7 @@ private function loadScripts(WC_Order $order): void $this->scripts->registerStoreStyle( 'mp_payment_status_sync', - $this->url->getPluginFileUrl('assets/css/admin/order/payment-status-sync', '.css') + $this->url->getCssAsset('admin/order/payment-status-sync') ); } @@ -204,7 +204,7 @@ private function getMetaboxData(WC_Order $order): array case 'success': return [ 'card_title' => $this->adminTranslations->statusSync['card_title'], - 'img_src' => $this->url->getPluginFileUrl('assets/images/icons/icon-success', '.png', true), + 'img_src' => $this->url->getImageAsset('icons/icon-success'), 'alert_title' => $cardContent['alert_title'], 'alert_description' => $cardContent['description'], 'link' => 'https://www.mercadopago.com', @@ -216,7 +216,7 @@ private function getMetaboxData(WC_Order $order): array case 'pending': return [ 'card_title' => $this->adminTranslations->statusSync['card_title'], - 'img_src' => $this->url->getPluginFileUrl('assets/images/icons/icon-alert', '.png', true), + 'img_src' => $this->url->getImageAsset('icons/icon-alert'), 'alert_title' => $cardContent['alert_title'], 'alert_description' => $cardContent['description'], 'link' => 'https://www.mercadopago.com', @@ -230,7 +230,7 @@ private function getMetaboxData(WC_Order $order): array case 'charged_back': return [ 'card_title' => $this->adminTranslations->statusSync['card_title'], - 'img_src' => $this->url->getPluginFileUrl('assets/images/icons/icon-warning', '.png', true), + 'img_src' => $this->url->getImageAsset('icons/icon-warning'), 'alert_title' => $cardContent['alert_title'], 'alert_description' => $cardContent['description'], 'link' => $this->adminTranslations->links['reasons_refusals'], diff --git a/src/Hooks/Scripts.php b/src/Hooks/Scripts.php index 167a52207..a3aebf5af 100644 --- a/src/Hooks/Scripts.php +++ b/src/Hooks/Scripts.php @@ -136,7 +136,7 @@ public function registerNoticesAdminScript(): void { global $woocommerce; - $file = $this->url->getPluginFileUrl('assets/js/notices/notices-client', '.js'); + $file = $this->url->getJsAsset('notices/notices-client'); $variables = [ 'site_id' => $this->seller->getSiteId() ?: Country::SITE_ID_MLA, 'container' => '#wpbody-content', @@ -189,7 +189,7 @@ public function registerCaronteAdminScript(): void { global $woocommerce; - $file = $this->url->getPluginFileUrl('assets/js/caronte/caronte-client', '.js'); + $file = $this->url->getJsAsset('caronte/caronte-client'); $variables = [ 'locale' => get_locale(), 'site_id' => $this->seller->getSiteId() ?: Country::SITE_ID_MLA, @@ -239,7 +239,7 @@ private function registerMelidataScript(string $type, string $location, string $ { global $woocommerce; - $file = $this->url->getPluginFileUrl('assets/js/melidata/melidata-client', '.js'); + $file = $this->url->getJsAsset('melidata/melidata-client'); $variables = [ 'type' => $type, 'site_id' => $this->seller->getSiteId() ?: Country::SITE_ID_MLA, diff --git a/src/Hooks/index.php b/src/Hooks/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/src/Hooks/index.php @@ -0,0 +1,13 @@ +get_image_id()) - : $this->mercadopago->helpers->url->getPluginFileUrl('assets/images/gateways/all/blue-cart', '.png', true); + : $this->mercadopago->helpers->url->getImageAsset('gateways/all/blue-cart'); } /** diff --git a/src/Transactions/index.php b/src/Transactions/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/src/Transactions/index.php @@ -0,0 +1,13 @@ +storeConfig->getExecuteActivate()) { $this->hooks->plugin->executeActivatePluginAction(); } + if ($this->storeConfig->getExecuteAfterPluginUpdate()) { + $this->afterPluginUpdate(); + } } /** @@ -230,12 +233,20 @@ public function disablePlugin() /** * Function hook active plugin - * - * @return void */ - public function activatePlugin() + public function activatePlugin(): void + { + $after = fn() => $this->storeConfig->setExecuteActivate(false); + + self::$funnel->created() ? self::$funnel->updateStepActivate($after) : self::$funnel->create($after); + } + + /** + * Function hook after plugin update + */ + public function afterPluginUpdate(): void { - self::$funnel->isInstallationId() ? self::$funnel->updateStepActivate() : self::$funnel->getInstallationId(); + self::$funnel->updateStepPluginVersion(fn() => $this->storeConfig->setExecuteAfterPluginUpdate(false)); } /** diff --git a/src/index.php b/src/index.php new file mode 100644 index 000000000..da8f1da45 --- /dev/null +++ b/src/index.php @@ -0,0 +1,13 @@ +