From 67c79a41ca8b06e9a5f1a87dacf040d4a44894f9 Mon Sep 17 00:00:00 2001 From: pmsantos_meli Date: Wed, 27 Mar 2024 17:41:40 -0300 Subject: [PATCH] v1.7.0 --- .../System/Config/Tracking/Tracking.php | 64 +++++++++++++++++++ CHANGELOG.md | 8 +++ .../Source/MerchantPaymentMethods.php | 13 ++-- Model/Adminhtml/Source/PaymentMethodsOff.php | 14 ++-- .../Command/Adminstrative/FetchMerchant.php | 5 ++ Model/Ui/ConfigProviderCheckoutCredits.php | 8 +-- Model/Ui/ConfigProviderPaymentMethodsOff.php | 16 +++-- composer.json | 2 +- composer.lock | 64 +++++++++---------- etc/di.xml | 1 + etc/module.xml | 2 +- .../layout/adminhtml_system_config_edit.xml | 5 ++ view/adminhtml/requirejs-config.js | 7 ++ .../templates/melidata/tracking.phtml | 30 +++++++++ view/adminhtml/web/js/melidata_client.js | 63 ++++++++++++++++++ 15 files changed, 246 insertions(+), 56 deletions(-) create mode 100644 Block/Adminhtml/System/Config/Tracking/Tracking.php create mode 100644 view/adminhtml/requirejs-config.js create mode 100644 view/adminhtml/templates/melidata/tracking.phtml create mode 100644 view/adminhtml/web/js/melidata_client.js diff --git a/Block/Adminhtml/System/Config/Tracking/Tracking.php b/Block/Adminhtml/System/Config/Tracking/Tracking.php new file mode 100644 index 0000000..1194919 --- /dev/null +++ b/Block/Adminhtml/System/Config/Tracking/Tracking.php @@ -0,0 +1,64 @@ +session = $session; + $this->config = $config; + } + + /** + * @return String + */ + public function getConfigData() + { + + return [ + 'moduleVersion' => $this->config->getModuleVersion(), + 'platformVersion' => $this->config->getMagentoVersion(), + 'siteId' => $this->config->getMpSiteId() ? $this->config->getMpSiteId() : "Credencial não cadastrada", + ]; + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a2db82..8593b67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ 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). +## [1.7.0] - 2024-03-27 +### Added +- Added trackings in selected paths for melidata + +### Fixed +- Validation for expired credentials +- Correction for area code error in old platform versions + ## [1.6.3] - 2024-03-07 ### Changed - Adjusting Iframe creation with 3Ds. diff --git a/Model/Adminhtml/Source/MerchantPaymentMethods.php b/Model/Adminhtml/Source/MerchantPaymentMethods.php index 26844a6..bf49df6 100644 --- a/Model/Adminhtml/Source/MerchantPaymentMethods.php +++ b/Model/Adminhtml/Source/MerchantPaymentMethods.php @@ -1,4 +1,5 @@ getAllPaymentMethods(); - if ($payments['success'] === true) { + if ($payments['success'] === true && isset($payments['methods'])) { foreach ($payments['methods'] as $payment) { - $options[] = [ - 'value' => $payment['id'], - 'label' => __($payment['name']), - ]; + if (isset($payment['id']) && isset($payment['name'])) { + $options[] = [ + 'value' => $payment['id'], + 'label' => __($payment['name']), + ]; + } } } diff --git a/Model/Adminhtml/Source/PaymentMethodsOff.php b/Model/Adminhtml/Source/PaymentMethodsOff.php index 8b019b0..b0595cf 100644 --- a/Model/Adminhtml/Source/PaymentMethodsOff.php +++ b/Model/Adminhtml/Source/PaymentMethodsOff.php @@ -58,19 +58,23 @@ public function toOptionArray(): array $payments = $this->mercadopagoConfig->getMpPaymentMethods($storeId); - if ($payments['success'] === true) { + if ($payments['success'] === true && isset($payments['response'])) { $options = array_merge($options, $this->mountPaymentMethodsOff($payments['response'])); } return $options; } - public function mountPaymentMethodsOff(array $paymentMethods): ?array { + public function mountPaymentMethodsOff(array $paymentMethods): ?array + { $options = []; foreach ($paymentMethods as $payment) { - if (in_array($payment['payment_type_id'], self::PAYMENT_TYPE_ID_ALLOWED) && - $payment['status'] === self::PAYMENT_STATUS_ACTIVE) { + if ( + isset($payment['payment_type_id']) && isset($payment['status']) && + in_array($payment['payment_type_id'], self::PAYMENT_TYPE_ID_ALLOWED) && + $payment['status'] === self::PAYMENT_STATUS_ACTIVE + ) { if (empty($payment['payment_places'])) { $options[] = [ @@ -93,10 +97,8 @@ public function mountPaymentMethodsOff(array $paymentMethods): ?array { $labels = array(); foreach ($options as $key => $row) { $labels[$key] = $row['label']; - } array_multisort($labels, SORT_ASC, $options); return $options; } - } diff --git a/Model/Console/Command/Adminstrative/FetchMerchant.php b/Model/Console/Command/Adminstrative/FetchMerchant.php index b8522ac..5da3239 100644 --- a/Model/Console/Command/Adminstrative/FetchMerchant.php +++ b/Model/Console/Command/Adminstrative/FetchMerchant.php @@ -130,6 +130,11 @@ public function __construct( $this->storeManager = $storeManager; $this->json = $json; $this->messageManager = $messageManager; + try { + $this->state->getAreaCode(); + } catch (Exception $e) { + $this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML); + } } /** diff --git a/Model/Ui/ConfigProviderCheckoutCredits.php b/Model/Ui/ConfigProviderCheckoutCredits.php index 9a911da..4c1d29b 100644 --- a/Model/Ui/ConfigProviderCheckoutCredits.php +++ b/Model/Ui/ConfigProviderCheckoutCredits.php @@ -167,9 +167,9 @@ public function isActive() $storeId = $this->cart->getStoreId(); $payments = $this->mercadopagoConfig->getMpPaymentMethods($storeId); - if ($payments['success'] === true) { + if ($payments['success'] === true && isset($payments['response'])) { foreach ($payments['response'] as $payment) { - if ($payment['id'] === self::PAYMENT_METHOD_ID) { + if (isset($payment['id']) && $payment['id'] === self::PAYMENT_METHOD_ID) { return true; } } @@ -179,7 +179,7 @@ public function isActive() /** * Get images for payment method banner. - * + * * @return array */ public function getImages() @@ -197,7 +197,7 @@ public function getImages() /** * Get images for payment method banner. - * + * * @return array */ public function getImagesByName($name) diff --git a/Model/Ui/ConfigProviderPaymentMethodsOff.php b/Model/Ui/ConfigProviderPaymentMethodsOff.php index 36f9881..7cb4d66 100644 --- a/Model/Ui/ConfigProviderPaymentMethodsOff.php +++ b/Model/Ui/ConfigProviderPaymentMethodsOff.php @@ -45,7 +45,7 @@ class ConfigProviderPaymentMethodsOff implements ConfigProviderInterface */ protected $cart; - /** + /** * @var MercadoPagoConfig */ protected $mercadopagoConfig; @@ -55,7 +55,7 @@ class ConfigProviderPaymentMethodsOff implements ConfigProviderInterface */ protected $escaper; - /** + /** * @var Repository */ protected $assetRepo; @@ -140,7 +140,7 @@ public function getPaymentMethodsOffActive($storeId) $options = []; $payments = $this->mercadopagoConfig->getMpPaymentMethods($storeId); - if ($payments['success'] === true) { + if ($payments['success'] === true && isset($payments['response'])) { $options = $this->mountPaymentMethodsOff($payments['response']); } @@ -163,7 +163,7 @@ public function filterPaymentMethodsOffConfigActive(array $paymentMethods, ?stri $actives = explode(",", $methodsOffActive); foreach ($paymentMethods as $payment) { - if(isset($payment['value']) && !in_array($payment['value'], $actives)){ + if (isset($payment['value']) && !in_array($payment['value'], $actives)) { $options[] = $payment; } } @@ -180,8 +180,11 @@ public function mountPaymentMethodsOff(array $paymentMethods = []): array { $options = []; foreach ($paymentMethods as $payment) { - if (in_array($payment['payment_type_id'], self::PAYMENT_TYPE_ID_ALLOWED) && - $payment['status'] === self::PAYMENT_STATUS_ACTIVE) { + if ( + isset($payment['payment_type_id']) && isset($payment['status']) && + in_array($payment['payment_type_id'], self::PAYMENT_TYPE_ID_ALLOWED) && + $payment['status'] === self::PAYMENT_STATUS_ACTIVE + ) { if (empty($payment['payment_places'])) { $options[] = [ @@ -216,5 +219,4 @@ public function mountPaymentMethodsOff(array $paymentMethods = []): array array_multisort($labels, SORT_ASC, $options); return $options; } - } diff --git a/composer.json b/composer.json index 50523ef..3ed05ed 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mercadopago/adb-payment", "description": "MercadoPago - Payment for Adobe Commerce", - "version": "1.6.3", + "version": "1.7.0", "require": { "php": "~7.3.0||~7.4.0||~8.1.0||~8.2.0", "ext-json": "*", diff --git a/composer.lock b/composer.lock index 8607bb8..9af4b1d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d717ac615aa886662fdbd9b7a70ee750", + "content-hash": "582443677d1eeffcf2b12ba86a23f5c5", "packages": [ { "name": "mp-plugins/php-sdk", @@ -57,16 +57,16 @@ "packages-dev": [ { "name": "composer/pcre", - "version": "3.1.2", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/composer/pcre.git", - "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace" + "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/pcre/zipball/4775f35b2d70865807c89d32c8e7385b86eb0ace", - "reference": "4775f35b2d70865807c89d32c8e7385b86eb0ace", + "url": "https://api.github.com/repos/composer/pcre/zipball/5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", + "reference": "5b16e25a5355f1f3afdfc2f954a0a80aec4826a8", "shasum": "" }, "require": { @@ -108,7 +108,7 @@ ], "support": { "issues": "https://github.com/composer/pcre/issues", - "source": "https://github.com/composer/pcre/tree/3.1.2" + "source": "https://github.com/composer/pcre/tree/3.1.3" }, "funding": [ { @@ -124,20 +124,20 @@ "type": "tidelift" } ], - "time": "2024-03-07T15:38:35+00:00" + "time": "2024-03-19T10:26:25+00:00" }, { "name": "composer/xdebug-handler", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "ced299686f41dce890debac69273b47ffe98a40c" + "reference": "4f988f8fdf580d53bdb2d1278fe93d1ed5462255" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c", - "reference": "ced299686f41dce890debac69273b47ffe98a40c", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/4f988f8fdf580d53bdb2d1278fe93d1ed5462255", + "reference": "4f988f8fdf580d53bdb2d1278fe93d1ed5462255", "shasum": "" }, "require": { @@ -148,7 +148,7 @@ "require-dev": { "phpstan/phpstan": "^1.0", "phpstan/phpstan-strict-rules": "^1.1", - "symfony/phpunit-bridge": "^6.0" + "phpunit/phpunit": "^8.5 || ^9.6 || ^10.5" }, "type": "library", "autoload": { @@ -172,9 +172,9 @@ "performance" ], "support": { - "irc": "irc://irc.freenode.org/composer", + "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/xdebug-handler/issues", - "source": "https://github.com/composer/xdebug-handler/tree/3.0.3" + "source": "https://github.com/composer/xdebug-handler/tree/3.0.4" }, "funding": [ { @@ -190,7 +190,7 @@ "type": "tidelift" } ], - "time": "2022-02-25T21:32:43+00:00" + "time": "2024-03-26T18:29:49+00:00" }, { "name": "dealerdirect/phpcodesniffer-composer-installer", @@ -454,22 +454,22 @@ }, { "name": "phpcsstandards/phpcsutils", - "version": "1.0.9", + "version": "1.0.10", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", - "reference": "908247bc65010c7b7541a9551e002db12e9dae70" + "reference": "51609a5b89f928e0c463d6df80eb38eff1eaf544" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/908247bc65010c7b7541a9551e002db12e9dae70", - "reference": "908247bc65010c7b7541a9551e002db12e9dae70", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/51609a5b89f928e0c463d6df80eb38eff1eaf544", + "reference": "51609a5b89f928e0c463d6df80eb38eff1eaf544", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.8.0 || 4.0.x-dev@dev" + "squizlabs/php_codesniffer": "^3.9.0 || 4.0.x-dev@dev" }, "require-dev": { "ext-filter": "*", @@ -538,7 +538,7 @@ "type": "open_collective" } ], - "time": "2023-12-08T14:50:00+00:00" + "time": "2024-03-17T23:44:50+00:00" }, { "name": "phpmd/phpmd", @@ -669,16 +669,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.60", + "version": "1.10.65", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe" + "reference": "3c657d057a0b7ecae19cb12db446bbc99d8839c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/95dcea7d6c628a3f2f56d091d8a0219485a86bbe", - "reference": "95dcea7d6c628a3f2f56d091d8a0219485a86bbe", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3c657d057a0b7ecae19cb12db446bbc99d8839c6", + "reference": "3c657d057a0b7ecae19cb12db446bbc99d8839c6", "shasum": "" }, "require": { @@ -727,7 +727,7 @@ "type": "tidelift" } ], - "time": "2024-03-07T13:30:19+00:00" + "time": "2024-03-23T10:30:26+00:00" }, { "name": "psr/container", @@ -1570,16 +1570,16 @@ }, { "name": "webonyx/graphql-php", - "version": "v15.10.0", + "version": "v15.11.1", "source": { "type": "git", "url": "https://github.com/webonyx/graphql-php.git", - "reference": "e75935f56562f5adf9aed67f8ae21beff8b287d9" + "reference": "ab4ff2719b101dc3bfc3aaaf800edc21a98c56dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/e75935f56562f5adf9aed67f8ae21beff8b287d9", - "reference": "e75935f56562f5adf9aed67f8ae21beff8b287d9", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/ab4ff2719b101dc3bfc3aaaf800edc21a98c56dc", + "reference": "ab4ff2719b101dc3bfc3aaaf800edc21a98c56dc", "shasum": "" }, "require": { @@ -1632,7 +1632,7 @@ ], "support": { "issues": "https://github.com/webonyx/graphql-php/issues", - "source": "https://github.com/webonyx/graphql-php/tree/v15.10.0" + "source": "https://github.com/webonyx/graphql-php/tree/v15.11.1" }, "funding": [ { @@ -1640,7 +1640,7 @@ "type": "open_collective" } ], - "time": "2024-03-04T11:05:50+00:00" + "time": "2024-03-11T10:21:05+00:00" } ], "aliases": [], diff --git a/etc/di.xml b/etc/di.xml index 1a46b01..4909525 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -102,6 +102,7 @@ MercadoPago\AdbPayment\Model\Ui\ConfigProviderBase::CODE MercadoPago\AdbPayment\Block\Sales\Form\Card MercadoPago\AdbPayment\Block\Sales\Info\Card + MercadoPago\AdbPayment\Block\Adminhtml\System\Config\Tracking MercadoPagoValueHandlerPool MercadoPagoCcCommandPool diff --git a/etc/module.xml b/etc/module.xml index 1c3bd28..ba30ee6 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -8,7 +8,7 @@ */ --> - + diff --git a/view/adminhtml/layout/adminhtml_system_config_edit.xml b/view/adminhtml/layout/adminhtml_system_config_edit.xml index 1c7d8d8..a86aec5 100644 --- a/view/adminhtml/layout/adminhtml_system_config_edit.xml +++ b/view/adminhtml/layout/adminhtml_system_config_edit.xml @@ -12,4 +12,9 @@ + + + + + diff --git a/view/adminhtml/requirejs-config.js b/view/adminhtml/requirejs-config.js new file mode 100644 index 0000000..6353c24 --- /dev/null +++ b/view/adminhtml/requirejs-config.js @@ -0,0 +1,7 @@ +let config = { + map: { + '*': { + 'mp_tracking': 'MercadoPago_AdbPayment/js/melidata_client', + } + } +}; diff --git a/view/adminhtml/templates/melidata/tracking.phtml b/view/adminhtml/templates/melidata/tracking.phtml new file mode 100644 index 0000000..dad2184 --- /dev/null +++ b/view/adminhtml/templates/melidata/tracking.phtml @@ -0,0 +1,30 @@ +getConfigData(); + $siteId = $configData->siteId; + $platformVersion = $configData->platformVersion; + $moduleVersion = $configData->moduleVersion; + +?> + + diff --git a/view/adminhtml/web/js/melidata_client.js b/view/adminhtml/web/js/melidata_client.js new file mode 100644 index 0000000..b75e4e0 --- /dev/null +++ b/view/adminhtml/web/js/melidata_client.js @@ -0,0 +1,63 @@ +/** + * Copyright © MercadoPago. All rights reserved. + * + * @author Mercado Pago + * @license See LICENSE for license details. + */ + +define([], function () { + 'use strict'; + + return function (config) { + + window.melidataConfig = config; + + window.melidatalog = function ($data) { + console.log("Data: ", $data); + }; + + try { + const scriptMelidata = document.createElement('script'); + scriptMelidata.setAttribute('id', 'adbpayment'); + scriptMelidata.src = 'https://http2.mlstatic.com/storage/v1/plugins/melidata/adbpayment.min.js'; + scriptMelidata.async = true; + scriptMelidata.defer = true; + scriptMelidata.onerror = function () { + + const url = 'https://api.mercadopago.com/v1/plugins/melidata/errors'; + + const payload = { + name: 'ERR_CONNECTION_REFUSED', + message: 'Unable to load melidata script on page', + target: 'melidata_adbpayment_client', + plugin: { + version: window.melidataConfig.moduleVersion, + }, + platform: { + name: 'adbpayment', + url: `${window.location.pathname}${window.location.search}`, + version: window.melidataConfig.platformVersion, + location: '/settings', + }, + }; + + navigator.sendBeacon(url, JSON.stringify(payload)); + + }; + + scriptMelidata.onload = function () { + window.melidata = new MelidataClient({ + type: 'seller', + siteID: melidataConfig.siteId, + pluginVersion: melidataConfig.moduleVersion, + platformVersion: melidataConfig.platformVersion, + pageLocation: '/settings' + }); + }; + + document.body.appendChild(scriptMelidata); + } catch (error) { + console.warn(error); + } + } +});