From e430565d9431298364d1acc694cf412019491828 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 09:54:06 -0300 Subject: [PATCH 01/70] docs: fix url for badges --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1fc0f94e..939cb5b8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/transbankdevelopers/transbank-plugin-woocommerce-webpay)](https://github.com/TransbankDevelopers/transbank-plugin-woocommerce-webpay/releases/latest) -[![GitHub](https://img.shields.io/github/license/transbankdevelopers/transbank-plugin-woocommerce-webpay)](LICENSE) -[![GitHub contributors](https://img.shields.io/github/contributors/transbankdevelopers/transbank-plugin-woocommerce-webpay)](https://github.com/TransbankDevelopers/transbank-plugin-woocommerce-webpay/graphs/contributors) -[![Build Status](https://travis-ci.org/TransbankDevelopers/transbank-plugin-woocommerce-webpay.svg?branch=master)](https://travis-ci.org/TransbankDevelopers/transbank-plugin-woocommerce-webpay) +[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/transbankdevelopers/transbank-plugin-woocommerce-webpay-rest)](https://github.com/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest/releases/latest) +[![GitHub](https://img.shields.io/github/license/transbankdevelopers/transbank-plugin-woocommerce-webpay-rest)](LICENSE) +[![GitHub contributors](https://img.shields.io/github/contributors/transbankdevelopers/transbank-plugin-woocommerce-webpay-rest)](https://github.com/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest/graphs/contributors) +[![Build Status](https://travis-ci.org/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest.svg?branch=master)](https://travis-ci.org/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest) # Transbank Woocommerce Webpay Plugin Plugin oficial de Webpay para WooCommerce From f3e9718609da693a2c70d98adcfbc388c80744be Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 10:00:39 -0300 Subject: [PATCH 02/70] docs: replace release badge from travis to github --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 939cb5b8..76781706 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/transbankdevelopers/transbank-plugin-woocommerce-webpay-rest)](https://github.com/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest/releases/latest) [![GitHub](https://img.shields.io/github/license/transbankdevelopers/transbank-plugin-woocommerce-webpay-rest)](LICENSE) [![GitHub contributors](https://img.shields.io/github/contributors/transbankdevelopers/transbank-plugin-woocommerce-webpay-rest)](https://github.com/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest/graphs/contributors) -[![Build Status](https://travis-ci.org/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest.svg?branch=master)](https://travis-ci.org/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest) +[![Release](https://github.com/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest/actions/workflows/release.yml/badge.svg)](https://github.com/TransbankDevelopers/transbank-plugin-woocommerce-webpay-rest/actions/workflows/release.yml) # Transbank Woocommerce Webpay Plugin Plugin oficial de Webpay para WooCommerce From e1e4ead405929e13ba4b068e45463e80dda6ca51 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 13:33:33 -0300 Subject: [PATCH 03/70] docs: update docker links --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 76781706..ebf56374 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,12 @@ Para cumplir estas dependencias, debes instalar [Composer](https://getcomposer.o Para apoyar el levantamiento rápido de un ambiente de desarrollo, hemos creado la especificación de contenedores a través de Docker Compose. Para testear los ejemplos estos estan disponibles en: -- [WooCommerce 3.4.0 con php 7.1](./docker-woocommerce-php7.1) -- [WooCommerce 3.6.3 con php 7.2](./docker-woocommerce-php7.2) -- [WooCommerce 3.9.1 con php 7.3](./docker-woocommerce-php7.3) -- [WooCommerce 3.9.1 con php 7.4](./docker-woocommerce-php7.4) +- [WooCommerce 6.0 con php 7.4](./docker-woocommerce-php7.4-wp6.0.0-wc2.6.0-woo6.0.0) +- [WooCommerce 6.5 con php 7.4](./docker-woocommerce-php7.4-wp6.0.0-wc2.6.0-woo6.5.0) +- [WooCommerce 8.1 con php 8.2](./docker-woocommerce-php8.2-wp6.4.1-wc2.9.0-woo8.1.0) +- [WooCommerce 8.2 con php 8.2](./docker-woocommerce-php8.2-wp6.4.1-wc2.9.0-woo8.2.0) +- [WooCommerce 8.3 con php 8.2](./docker-woocommerce-php8.2-wp6.4.1-wc2.9.0-woo8.3.0) +- [WooCommerce 8.5 con php 8.2](./docker-woocommerce-php8.2-wp6.4.1-wc2.9.0-woo8.5.0) Si necesitas subir el plugin a Woocommerce y obtienes un error por que no se puede mover el archivo a `wp-contentent` entonces ejecuta From b929d304a66163f58750b2ac1e80f83a9594b42d Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 13:34:55 -0300 Subject: [PATCH 04/70] docs: fix typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ebf56374..2178810c 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Para cumplir estas dependencias, debes instalar [Composer](https://getcomposer.o Para apoyar el levantamiento rápido de un ambiente de desarrollo, hemos creado la especificación de contenedores a través de Docker Compose. -Para testear los ejemplos estos estan disponibles en: +Para testear los ejemplos estos están disponibles en: - [WooCommerce 6.0 con php 7.4](./docker-woocommerce-php7.4-wp6.0.0-wc2.6.0-woo6.0.0) - [WooCommerce 6.5 con php 7.4](./docker-woocommerce-php7.4-wp6.0.0-wc2.6.0-woo6.5.0) - [WooCommerce 8.1 con php 8.2](./docker-woocommerce-php8.2-wp6.4.1-wc2.9.0-woo8.1.0) @@ -118,7 +118,7 @@ Con eso Travis CI generará automáticamente una nueva versión del plugin y act 2️⃣ - El pr debe tener 2 o mas aprobaciones para hacer el merge -3️⃣ - si un commit revierte un commit anterior debera comenzar con "revert:" seguido con texto del commit anterior +3️⃣ - si un commit revierte un commit anterior deberá comenzar con "revert:" seguido con texto del commit anterior ## Pull Request From 1fcf77ec6ae6cc67a355e303af52d0b2fa718aab Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 13:39:53 -0300 Subject: [PATCH 05/70] docs: improve docker list description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2178810c..3f374290 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Para cumplir estas dependencias, debes instalar [Composer](https://getcomposer.o Para apoyar el levantamiento rápido de un ambiente de desarrollo, hemos creado la especificación de contenedores a través de Docker Compose. -Para testear los ejemplos estos están disponibles en: +Para probar el plugin, ponemos a disposición los siguientes contenedores: - [WooCommerce 6.0 con php 7.4](./docker-woocommerce-php7.4-wp6.0.0-wc2.6.0-woo6.0.0) - [WooCommerce 6.5 con php 7.4](./docker-woocommerce-php7.4-wp6.0.0-wc2.6.0-woo6.5.0) - [WooCommerce 8.1 con php 8.2](./docker-woocommerce-php8.2-wp6.4.1-wc2.9.0-woo8.1.0) From 672cc8092d7c9b4e7ecc6eeaf403628afa2dac32 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 15:56:05 -0300 Subject: [PATCH 06/70] refactor: implement log controller --- plugin/src/Controllers/LogController.php | 32 +++++++++++++++++++ .../logs.php => templates/admin/log.php} | 9 +----- plugin/views/admin/options-tabs.php | 3 +- 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 plugin/src/Controllers/LogController.php rename plugin/{views/admin/logs.php => templates/admin/log.php} (96%) diff --git a/plugin/src/Controllers/LogController.php b/plugin/src/Controllers/LogController.php new file mode 100644 index 00000000..af8c710e --- /dev/null +++ b/plugin/src/Controllers/LogController.php @@ -0,0 +1,32 @@ +template = new Template(); + $this->log = TbkFactory::createLogger(); + } + public function show() + { + $summary = $this->log->getInfo(); + $lastLog = $this->log->getLogDetail(basename($summary['last'])); + $folderHasLogs = $summary['length'] > 0; + + $this->template->render('admin/log.php', [ + 'resume' => $summary, + 'lastLog' => $lastLog, + 'folderHasLogs' => $folderHasLogs + ]); + } +} diff --git a/plugin/views/admin/logs.php b/plugin/templates/admin/log.php similarity index 96% rename from plugin/views/admin/logs.php rename to plugin/templates/admin/log.php index 62fc7c15..1fa71c03 100644 --- a/plugin/views/admin/logs.php +++ b/plugin/templates/admin/log.php @@ -1,16 +1,9 @@ getInfo(); -$lastLog = $log->getLogDetail(basename($resume['last'])); -$folderHasLogs = $resume['length'] > 0; ?> +

Información de Registros

diff --git a/plugin/views/admin/options-tabs.php b/plugin/views/admin/options-tabs.php index 2a4687cf..1491f04a 100644 --- a/plugin/views/admin/options-tabs.php +++ b/plugin/views/admin/options-tabs.php @@ -4,6 +4,7 @@ return; } +use Transbank\WooCommerce\WebpayRest\Controllers\LogController; function tbk_is_nav_active($tab, $val) { if ($tab === $val) { @@ -45,7 +46,7 @@ function tbk_is_nav_active($tab, $val) } elseif ($tab === 'options_oneclick') { include_once __DIR__.'/oneclick-admin-options.php'; } elseif ($tab === 'logs') { - include_once __DIR__.'/logs.php'; + (new LogController)->show(); } elseif ($tab === 'transactions') { include_once __DIR__.'/transactions.php'; } else { From 3b221152edcff34e78f1d99ab897cab605550d7c Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 15:59:25 -0300 Subject: [PATCH 07/70] style: format file --- plugin/templates/admin/log.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 1fa71c03..f47d0b60 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -10,8 +10,7 @@
-
?
+
?
Estado de Registros: @@ -36,8 +35,7 @@ class="label label-info">?
-
?
+
?
Cantidad de Registros en Directorio: @@ -51,8 +49,7 @@ class="label label-info">?
-
?
+
?
Listado de Registros Disponibles: @@ -104,8 +101,7 @@ class="label label-info">?
-
?
+
?
Cantidad de Líneas: From 874a9b9d79a34e06874effed176a13146fba392d Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 16:35:22 -0300 Subject: [PATCH 08/70] feat: add log file selector --- plugin/src/Controllers/LogController.php | 22 ++++++++++++++++++++-- plugin/templates/admin/log.php | 15 +++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/plugin/src/Controllers/LogController.php b/plugin/src/Controllers/LogController.php index af8c710e..9265a7a6 100644 --- a/plugin/src/Controllers/LogController.php +++ b/plugin/src/Controllers/LogController.php @@ -20,13 +20,31 @@ public function __construct() public function show() { $summary = $this->log->getInfo(); - $lastLog = $this->log->getLogDetail(basename($summary['last'])); + $logFile = basename($summary['last']); + + if (isset($_GET['log_file']) && !is_null($_GET['log_file'])) { + if ($this->validateLogFileName($_GET['log_file'], $summary['logs'])) { + $logFile = $_GET['log_file']; + } + } + + $logDetail = $this->log->getLogDetail($logFile); $folderHasLogs = $summary['length'] > 0; $this->template->render('admin/log.php', [ 'resume' => $summary, - 'lastLog' => $lastLog, + 'lastLog' => $logDetail, 'folderHasLogs' => $folderHasLogs ]); } + + private function validateLogFileName(String $logFileName, array $logFiles): bool + { + foreach ($logFiles as $logData) { + if (in_array($logFileName, $logData)) { + return true; + } + } + return false; + } } diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index f47d0b60..7d9a37e5 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -114,6 +114,21 @@
+
+ + + + + +
+ '; From ced5d10e8eb1ba0a042e211eaba5a7e285067006 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 16:37:07 -0300 Subject: [PATCH 09/70] refactor: remove unnecessary div --- plugin/templates/admin/log.php | 230 ++++++++++++++++----------------- 1 file changed, 114 insertions(+), 116 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 7d9a37e5..90284ea0 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -5,153 +5,151 @@ ?>
-
-

Información de Registros

-
-
-
-
?
-
-
- Estado de Registros: -
-
- Registro activado +

Información de Registros

+
+
+
+
?
+
+
+ Estado de Registros: +
+
+ Registro activado +
+
+
+
+
?
-
+
+ Directorio de registros: +
+
+ + + +
+
+
+
+
?
+
+
+ Cantidad de Registros en Directorio: +
+
+ + + +
+
+ +
-
? -
+
?
- Directorio de registros: + Listado de Registros Disponibles:
- + ' . $index['filename'] . ''; + echo $str; + } + ?>
-
+ +
+ + +

Últimos Registros

+
+
-
?
+
? +
-
- Cantidad de Registros en Directorio: +
+ Último Documento:
-
+
- +
- -
-
-
?
-
-
- Listado de Registros Disponibles: -
-
- - ' . $index['filename'] . ''; - echo $str; - } - ?> - +
+
+
?
- -
- - -

Últimos Registros

-
-
-
-
? -
-
-
- Último Documento: -
-
- - - -
+
+ Peso del Documento:
-
-
-
? -
-
-
- Peso del Documento: -
-
- - - -
+
+ + +
-
-
-
?
-
-
- Cantidad de Líneas: -
-
- - - -
+
+
+
+
?
+
+
+ Cantidad de Líneas: +
+
+ + +
+
-
- - + + + - - -
+ + + - '; + '; - $logLines = explode("\n", $lastLog['content']); + $logLines = explode("\n", $lastLog['content']); - foreach ($logLines as $line) { - $chunks = explode(' > ', $line); + foreach ($logLines as $line) { + $chunks = explode(' > ', $line); - $date = $chunks[0]; - $level = $chunks[1] ?? null; - $message = $chunks[2] ?? null; + $date = $chunks[0]; + $level = $chunks[1] ?? null; + $message = $chunks[2] ?? null; - if (!is_null($date) && !is_null($level) && !is_null($message)) { - $logContent .= '
' . $date . ' > ' .
-                            '' . $level . ' > ' . $message .
-                            '
'; - } + if (!is_null($date) && !is_null($level) && !is_null($message)) { + $logContent .= '
' . $date . ' > ' .
+                        '' . $level . ' > ' . $message .
+                        '
'; } - $logContent .= '
'; - echo $logContent; } - ?> - -
+ $logContent .= '
'; + echo $logContent; + } + ?> +
From a97b2b3e4f089a59d885d27e66556afa67411a68 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 16:42:46 -0300 Subject: [PATCH 10/70] feat: remove log state --- plugin/templates/admin/log.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 90284ea0..04c8ae13 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -7,26 +7,15 @@

Información de Registros

-
-
-
?
-
-
- Estado de Registros: -
-
- Registro activado -
-
?
-
+
Directorio de registros:
-
+
From b6ff9511ff79afb39feee2637ec82435baf0482b Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 16:43:33 -0300 Subject: [PATCH 11/70] feat: remove log count --- plugin/templates/admin/log.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 04c8ae13..62ac2cb9 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -21,19 +21,6 @@
-
-
-
?
-
-
- Cantidad de Registros en Directorio: -
-
- - - -
-
From e9030d5e269214f908181ab2b8e7b287d8cd4c08 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 16:44:13 -0300 Subject: [PATCH 12/70] feat: remove log list --- plugin/templates/admin/log.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 62ac2cb9..e14e5d54 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -21,26 +21,6 @@
- -
-
-
?
-
-
- Listado de Registros Disponibles: -
-
- - ' . $index['filename'] . ''; - echo $str; - } - ?> - -
-
-
From ddebe2ffda7c4ddb50a0c55a142a321b0ebac8df Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 16:46:59 -0300 Subject: [PATCH 13/70] feat: remove last document name --- plugin/templates/admin/log.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index e14e5d54..e95b8139 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -26,20 +26,6 @@

Últimos Registros

-
-
-
? -
-
-
- Último Documento: -
-
- - - -
-
? From 7758deee9057b6ad49da59474cd26bc1f9b6af55 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 16:49:39 -0300 Subject: [PATCH 14/70] refactor: remove div --- plugin/templates/admin/log.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index e95b8139..17d88aef 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -6,21 +6,19 @@

Información de Registros

-
-
-
-
? -
-
-
- Directorio de registros: -
-
- - - +
+
+
?
+
+ Directorio de registros: +
+
+ + + +
From 567c668366c36c0a2cfe88d47542880225869b9c Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 16:53:46 -0300 Subject: [PATCH 15/70] refactor: remove if when folder has logs --- plugin/templates/admin/log.php | 114 ++++++++++++++++----------------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 17d88aef..ed52474b 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -21,75 +21,73 @@
- -

Últimos Registros

-
-
-
-
? -
-
-
- Peso del Documento: -
-
- - - +

Últimos Registros

+
+
+
+
?
-
-
-
?
-
-
- Cantidad de Líneas: -
-
- - - -
+
+ Peso del Documento: +
+
+ + +
+
+
+
?
+
+
+ Cantidad de Líneas: +
+
+ + + +
+
+
-
- - + + + - - -
+ + + - '; + '; - $logLines = explode("\n", $lastLog['content']); + $logLines = explode("\n", $lastLog['content']); - foreach ($logLines as $line) { - $chunks = explode(' > ', $line); + foreach ($logLines as $line) { + $chunks = explode(' > ', $line); - $date = $chunks[0]; - $level = $chunks[1] ?? null; - $message = $chunks[2] ?? null; + $date = $chunks[0]; + $level = $chunks[1] ?? null; + $message = $chunks[2] ?? null; - if (!is_null($date) && !is_null($level) && !is_null($message)) { - $logContent .= '
' . $date . ' > ' .
-                        '' . $level . ' > ' . $message .
-                        '
'; - } + if (!is_null($date) && !is_null($level) && !is_null($message)) { + $logContent .= '
' . $date . ' > ' .
+                    '' . $level . ' > ' . $message .
+                    '
'; } - $logContent .= '
'; - echo $logContent; } - ?> - + $logContent .= '
'; + echo $logContent; + } + ?>
From da8d6b6d63e2d0407b2530d053ea21ea949ff641 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 17:06:07 -0300 Subject: [PATCH 16/70] feat: move log selector to log info section --- plugin/css/tbk.css | 2 +- plugin/templates/admin/log.php | 40 +++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/plugin/css/tbk.css b/plugin/css/tbk.css index 51e4d490..e15ed8ce 100644 --- a/plugin/css/tbk.css +++ b/plugin/css/tbk.css @@ -282,7 +282,7 @@ display: grid; grid-template-columns: 20px 200px 1fr; grid-gap: 5px; - align-items: flex-start; + align-items: center; overflow: hidden; } diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index ed52474b..11384a7b 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -20,6 +20,31 @@
+
+
+
? +
+
+
+ Lista de logs: +
+
+
+ + + + + +
+
+

Últimos Registros

@@ -52,21 +77,6 @@
-
- - - - - -
- '; From 60f4486dfe842948b350a0626e447c07306e2aa0 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 17:12:33 -0300 Subject: [PATCH 17/70] feat: add protection when there are no log files --- plugin/templates/admin/log.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 11384a7b..df1e3d02 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -35,6 +35,9 @@ - No hay archivos log"; @@ -51,7 +51,7 @@

Información del archivo

-
+
?
@@ -65,7 +65,7 @@
-
+
?
From e8e8c36af79df864bbeb27679dca1facdd661a15 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 17:28:06 -0300 Subject: [PATCH 20/70] style: split long lines --- plugin/templates/admin/log.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 0d634051..fa587485 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -8,8 +8,10 @@

Información de Registros

-
? -
+
?
Directorio de registros: @@ -67,7 +69,10 @@
-
?
+
?
Cantidad de Líneas: From 2c19f1f6f4814e3fdd9cf6f62b642181bb295e2f Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 19 Mar 2024 17:39:43 -0300 Subject: [PATCH 21/70] fix: sonar issues --- plugin/src/Controllers/LogController.php | 4 +++- plugin/templates/admin/log.php | 15 ++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugin/src/Controllers/LogController.php b/plugin/src/Controllers/LogController.php index 9265a7a6..4d01effb 100644 --- a/plugin/src/Controllers/LogController.php +++ b/plugin/src/Controllers/LogController.php @@ -23,7 +23,9 @@ public function show() $logFile = basename($summary['last']); if (isset($_GET['log_file']) && !is_null($_GET['log_file'])) { - if ($this->validateLogFileName($_GET['log_file'], $summary['logs'])) { + $isLogFileNameValid = $this->validateLogFileName($_GET['log_file'], $summary['logs']); + + if ($isLogFileNameValid) { $logFile = $_GET['log_file']; } } diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index fa587485..2a25e89c 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -2,16 +2,16 @@ if (!defined('ABSPATH')) { return; } +$logDirectoryTitle = "Carpeta en el servidor en donde se guardan los archivos" . + " con la información de cada compra mediante Webpay"; +$lineCountTitle = "Cantidad de líneas que posee el último archivo de registro creado"; ?>

Información de Registros

-
?
+
?
Directorio de registros: @@ -37,7 +37,7 @@ class="label label-info" - > No hay archivos log"; + if (!$folderHasLogs) { + echo ""; } foreach ($resume['logs'] as $index) { $str = ""; @@ -46,7 +46,9 @@ } ?> - + + value="Ver">
From 5e130b5484e286664929caf770668bf7196220e1 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 20 Mar 2024 14:15:17 -0300 Subject: [PATCH 23/70] refactor: remove redundant null check --- plugin/src/Controllers/LogController.php | 2 +- plugin/templates/admin/log.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/Controllers/LogController.php b/plugin/src/Controllers/LogController.php index 4d01effb..e2db45e8 100644 --- a/plugin/src/Controllers/LogController.php +++ b/plugin/src/Controllers/LogController.php @@ -22,7 +22,7 @@ public function show() $summary = $this->log->getInfo(); $logFile = basename($summary['last']); - if (isset($_GET['log_file']) && !is_null($_GET['log_file'])) { + if (isset($_GET['log_file'])) { $isLogFileNameValid = $this->validateLogFileName($_GET['log_file'], $summary['logs']); if ($isLogFileNameValid) { diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 10242d29..23722c47 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -85,7 +85,7 @@
'; $logLines = explode("\n", $lastLog['content']); From c8de4b1395c2dde2065452523ac43c58e1a548d4 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 20 Mar 2024 14:22:36 -0300 Subject: [PATCH 24/70] feat: add select property --- plugin/templates/admin/log.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 23722c47..34b87c8a 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -42,6 +42,10 @@ } foreach ($resume['logs'] as $index) { $str = ""; + + if($index['filename'] == basename($lastLog['filename'])) { + $str = ""; + } echo $str; } ?> From 5c16ad84936bf9200ecab128b438d042d3e90935 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Thu, 23 May 2024 12:44:43 -0400 Subject: [PATCH 25/70] feat: add suffix when card added in integration --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index a483cb36..5ef676cd 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -252,7 +252,10 @@ public function methods_list_item_oneclick($item, $payment_token) if ('oneclick' !== strtolower($payment_token->get_type())) { return $item; } - $item['method']['last4'] = $payment_token->get_last4(); + $cardEnvironment = $payment_token->get_environment(); + $environmentSuffix = $cardEnvironment === Options::ENVIRONMENT_INTEGRATION ? ' [Test]' : ''; + + $item['method']['last4'] = $payment_token->get_last4().$environmentSuffix; $item['method']['brand'] = $payment_token->get_card_type(); return $item; From 1aa0c91cd87b9edbf528b878af0aaeca588f5093 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Fri, 24 May 2024 11:10:27 -0400 Subject: [PATCH 26/70] feat: show cards based on the environment --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 5ef676cd..bf6f8537 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -103,6 +103,7 @@ public function __construct() add_filter('woocommerce_payment_methods_list_item', [$this, 'methods_list_item_oneclick'], null, 2); add_filter('woocommerce_payment_token_class', [$this, 'set_payment_token_class']); add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']); + add_filter('woocommerce_saved_payment_methods_list', [$this, 'get_saved_payment_methods_list'], 10, 2); } public function payment_fields() @@ -247,16 +248,37 @@ public static function subscription_payment_method_updated() // Todo: check if we need something here. } + public function get_saved_payment_methods_list($saved_methods, $customer_id) + { + $pluginEnvironment = $this->get_option('environment'); + $oneclickCards = $saved_methods['oneclick'] ?? []; + $filteredCards = []; + + foreach ($oneclickCards as $card) { + if ($card['method']['environment'] === $pluginEnvironment) { + $filteredCards[] = $card; + } + } + + if (count($oneclickCards) > 0) { + $saved_methods['oneclick'] = $filteredCards; + } + + return $saved_methods; + } + public function methods_list_item_oneclick($item, $payment_token) { if ('oneclick' !== strtolower($payment_token->get_type())) { return $item; } + $cardEnvironment = $payment_token->get_environment(); $environmentSuffix = $cardEnvironment === Options::ENVIRONMENT_INTEGRATION ? ' [Test]' : ''; - $item['method']['last4'] = $payment_token->get_last4().$environmentSuffix; + $item['method']['last4'] = $payment_token->get_last4() . $environmentSuffix; $item['method']['brand'] = $payment_token->get_card_type(); + $item['method']['environment'] = $cardEnvironment; return $item; } From 8fba09e54114706c5a4e268edbef244666a08d0e Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Fri, 24 May 2024 11:43:03 -0400 Subject: [PATCH 27/70] refactor: remove unused parameter --- .../PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index bf6f8537..d51e81fb 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -248,7 +248,7 @@ public static function subscription_payment_method_updated() // Todo: check if we need something here. } - public function get_saved_payment_methods_list($saved_methods, $customer_id) + public function get_saved_payment_methods_list($saved_methods) { $pluginEnvironment = $this->get_option('environment'); $oneclickCards = $saved_methods['oneclick'] ?? []; From 33148b23fadd12f939f647a84cf8e52d791e02bc Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Fri, 24 May 2024 11:55:22 -0400 Subject: [PATCH 28/70] feat: update webpay gateway description --- .../PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php index 43b3692a..3fdbe9d2 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Webpay_Plus_REST.php @@ -46,7 +46,7 @@ public function __construct() $this->id = self::ID; $this->icon = plugin_dir_url(dirname(dirname(__FILE__))) . 'images/webpay.png'; $this->method_title = __('Transbank Webpay Plus', 'transbank_webpay_plus_rest'); - $this->title = 'Transbank Webpay Plus'; + $this->title = 'Webpay Plus'; $this->description = $this->get_option('webpay_rest_payment_gateway_description', self::PAYMENT_GW_DESCRIPTION); $this->method_description = $this->get_option('webpay_rest_payment_gateway_description', self::PAYMENT_GW_DESCRIPTION); From 8ca7848294ea28d7023a50937cf3f36de0b5f4f1 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Fri, 24 May 2024 17:15:05 -0400 Subject: [PATCH 29/70] fix: add try catch in scheduled_subscription_payment method --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index d51e81fb..d5553890 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -226,21 +226,25 @@ public function form() */ public function scheduled_subscription_payment($amount_to_charge, WC_Order $renewalOrder) { - $this->logger->logInfo('New scheduled_subscription_payment for Order #' . $renewalOrder->get_id()); - $customerId = $renewalOrder->get_customer_id(); - if (!$customerId) { - $this->logger->logError('There is no costumer id on the renewal order'); + try { + $this->logger->logInfo('New scheduled_subscription_payment for Order #' . $renewalOrder->get_id()); + $customerId = $renewalOrder->get_customer_id(); + if (!$customerId) { + $this->logger->logError('There is no costumer id on the renewal order'); - throw new EcommerceException('There is no costumer id on the renewal order'); - } + throw new EcommerceException('There is no costumer id on the renewal order'); + } - /** @var WC_Payment_Token_Oneclick $paymentToken */ - $paymentToken = WC_Payment_Tokens::get_customer_default_token($customerId); - $response = $this->authorizeTransaction($renewalOrder, $paymentToken, $amount_to_charge); - if ($response['result'] == 'error') { - throw new EcommerceException('Se produjo un error en la autorización'); + /** @var WC_Payment_Token_Oneclick $paymentToken */ + $paymentToken = WC_Payment_Tokens::get_customer_default_token($customerId); + $response = $this->authorizeTransaction($renewalOrder, $paymentToken, $amount_to_charge); + if ($response['result'] == 'error') { + throw new EcommerceException('Se produjo un error en la autorización'); + } + $this->setAfterPaymentOrderStatus($renewalOrder); + } catch (Exception $ex) { + $this->logger->logError("Error al procesar suscripción: " . $ex->getMessage()); } - $this->setAfterPaymentOrderStatus($renewalOrder); } public static function subscription_payment_method_updated() From a704c591a50c25019bd0a897b287ad03a904b0eb Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Fri, 24 May 2024 17:15:59 -0400 Subject: [PATCH 30/70] refactor: remove dead code --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index d5553890..db969c62 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -237,10 +237,8 @@ public function scheduled_subscription_payment($amount_to_charge, WC_Order $rene /** @var WC_Payment_Token_Oneclick $paymentToken */ $paymentToken = WC_Payment_Tokens::get_customer_default_token($customerId); - $response = $this->authorizeTransaction($renewalOrder, $paymentToken, $amount_to_charge); - if ($response['result'] == 'error') { - throw new EcommerceException('Se produjo un error en la autorización'); - } + $this->authorizeTransaction($renewalOrder, $paymentToken, $amount_to_charge); + $this->setAfterPaymentOrderStatus($renewalOrder); } catch (Exception $ex) { $this->logger->logError("Error al procesar suscripción: " . $ex->getMessage()); From bc2872ae6c5e71bcd031a2f82d748336dc8e8c1e Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 00:19:59 -0400 Subject: [PATCH 31/70] fix: remove deprecated hook --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 5 ----- plugin/webpay-rest.php | 2 -- 2 files changed, 7 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index db969c62..306702b4 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -245,11 +245,6 @@ public function scheduled_subscription_payment($amount_to_charge, WC_Order $rene } } - public static function subscription_payment_method_updated() - { - // Todo: check if we need something here. - } - public function get_saved_payment_methods_list($saved_methods) { $pluginEnvironment = $this->get_option('environment'); diff --git a/plugin/webpay-rest.php b/plugin/webpay-rest.php index ca085628..7be80be8 100644 --- a/plugin/webpay-rest.php +++ b/plugin/webpay-rest.php @@ -45,8 +45,6 @@ add_action('wp_ajax_get_transaction_status', TransactionStatusController::class.'::getStatus'); add_action('woocommerce_before_cart', 'transbank_rest_before_cart'); -add_action('woocommerce_subscription_failing_payment_method_updated_transbank_oneclick_mall_rest', [WC_Gateway_Transbank_Oneclick_Mall_REST::class, 'subscription_payment_method_updated'], 10, 3); - add_action('woocommerce_before_checkout_form', 'transbank_rest_check_cancelled_checkout'); add_action('admin_enqueue_scripts', function () { wp_enqueue_style('tbk-styles', plugins_url('/css/tbk.css', __FILE__), [], '1.1'); From cc2e1f9dacce97addd4e818c5abf315f2f5626e6 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 00:39:35 -0400 Subject: [PATCH 32/70] chore: add woocommerce as a dependency --- plugin/webpay-rest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/webpay-rest.php b/plugin/webpay-rest.php index ca085628..59740813 100644 --- a/plugin/webpay-rest.php +++ b/plugin/webpay-rest.php @@ -28,6 +28,7 @@ * Plugin URI: https://www.transbankdevelopers.cl/plugin/woocommerce/webpay * Description: Recibe pagos en línea con Tarjetas de Crédito y Redcompra en tu WooCommerce a través de Webpay Plus y Webpay Oneclick. * Version: VERSION_REPLACE_HERE + * Requires Plugins: woocommerce * Author: TransbankDevelopers * Author URI: https://www.transbank.cl * WC requires at least: 7.0 From 6e6507022f93198f9991636f632ed64d15a6572f Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 12:43:38 -0400 Subject: [PATCH 33/70] refactor: reorder methods positions --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 383 +++++++++--------- 1 file changed, 192 insertions(+), 191 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 306702b4..1f704564 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -106,22 +106,109 @@ public function __construct() add_filter('woocommerce_saved_payment_methods_list', [$this, 'get_saved_payment_methods_list'], 10, 2); } - public function payment_fields() + /** + * Procesar pago y retornar resultado. + ** + * + * @throws MallTransactionAuthorizeException + */ + public function process_payment($order_id) { - $description = $this->get_description(); - if ($description) { - echo wpautop(wptexturize($description)); // @codingStandardsIgnoreLine. + $errorHookName = 'wc_gateway_transbank_process_payment_error_' . $this->id; + $shouldThrowException = false; + + try { + $order = new WC_Order($order_id); + + if (!$order->needs_payment() && !wcs_is_subscription($order_id)) { + $this->logger->logError('This order was already paid or does not need payment'); + $errorMessage = __( + 'Esta transacción puede ya estar pagada o encontrarse en un estado que no permite un nuevo pago. ', + 'transbank_wc_plugin' + ); + + throw new EcommerceException($errorMessage); + } + + $paymentMethodOption = $_POST["wc-{$this->id}-payment-token"] ?? null; + $addNewCard = 'new' === $paymentMethodOption || $paymentMethodOption === null; + $payWithSavedToken = $paymentMethodOption !== null && !$addNewCard; + + if (!get_current_user_id()) { + $order->add_order_note( + 'El usuario intentó pagar con oneclick pero no tiene (y no creó durante el checkout)' . + ' cuenta de usuario' + ); + $this->logger->logInfo('Checkout: The user should have an account to add a new card. '); + + $errorMessage = __( + 'Webpay Oneclick: Debes crear o tener una cuenta en el sitio para poder inscribir ' . + 'tu tarjeta y usar este método de pago.', + 'transbank_wc_plugin' + ); + + throw new EcommerceException($errorMessage); + } + + if ($addNewCard) { + $this->logger->logInfo('[Oneclick] Checkout: start inscription'); + + $response = $this->start($order_id); + + $this->logger->logInfo('[Oneclick] Checkout: inscription response: '); + $this->logger->logInfo(json_encode($response)); + $order->add_order_note('El usuario inició inscripción de nueva tarjeta. Redirigiendo a ' . + 'formulario OneClick...'); + + do_action('transbank_oneclick_adding_card_from_order', $order); + + return [ + 'result' => 'success', + 'redirect' => $response->getRedirectUrl(), + ]; + } + + if ($payWithSavedToken) { + + $shouldThrowException = true; + return $this->authorizeTransaction($order); + } + $errorMessage = __('Error interno: no se pudo procesar el pago', 'transbank_wc_plugin'); + throw new EcommerceException($errorMessage); + } catch (\Throwable $exception) { + $errorMessage = ErrorHelper::getErrorMessageBasedOnTransbankSdkException($exception); + do_action($errorHookName, $exception, $shouldThrowException); + BlocksHelper::addLegacyNotices($errorMessage, 'error'); + + return [ + 'result' => 'error', + 'redirect' => '' + ]; } - parent::payment_fields(); } - public function is_valid_for_use() + /** + * @throws MallTransactionAuthorizeException + */ + public function scheduled_subscription_payment($amount_to_charge, WC_Order $renewalOrder) { - return in_array( - get_woocommerce_currency(), - apply_filters('woocommerce_transbank_webpay_oneclick_supported_currencies', ['CLP']), - true - ); + try { + $this->logger->logInfo('New scheduled_subscription_payment for Order #' . $renewalOrder->get_id()); + $customerId = $renewalOrder->get_customer_id(); + if (!$customerId) { + $this->logger->logError('There is no costumer id on the renewal order'); + + throw new EcommerceException('There is no costumer id on the renewal order'); + } + + /** @var WC_Payment_Token_Oneclick $paymentToken */ + $paymentToken = WC_Payment_Tokens::get_customer_default_token($customerId); + $this->authorizeTransaction($renewalOrder, $paymentToken, $amount_to_charge); + + $this->setAfterPaymentOrderStatus($renewalOrder); + } catch (Exception $ex) { + $this->logger->logError("Error al procesar suscripción: " . $ex->getMessage()); + } } public function process_refund($order_id, $amount = null, $reason = '') @@ -181,6 +268,15 @@ public function process_refund($order_id, $amount = null, $reason = '') } } + public function payment_fields() + { + $description = $this->get_description(); + if ($description) { + echo wpautop(wptexturize($description)); // @codingStandardsIgnoreLine. + } + parent::payment_fields(); + } + public function admin_options() { if ($this->is_valid_for_use()) { @@ -207,6 +303,31 @@ public function admin_options() } } + /** + * @throws \GuzzleHttp\Exception\GuzzleException + * @throws InscriptionStartException + */ + public function add_payment_method() + { + $response = $this->start(null, 'my_account'); + $redirectUrl = $response->getRedirectUrl(); + + return wp_redirect($redirectUrl); + } + + /** + * Outputs a checkbox for saving a new payment method to the database. + * + * @since 2.6.0 + */ + public function save_payment_method_checkbox() + { + $html = '

+ Esta tarjeta se guardará en tu cuenta para que puedas volver a usarla. +

'; + echo $html; + } + public function is_available() { if (!$this->is_valid_for_use()) { @@ -222,27 +343,61 @@ public function form() } /** - * @throws MallTransactionAuthorizeException + * @param WC_Order $order + * + * @throws Transbank\Webpay\Oneclick\Exceptions\MallTransactionAuthorizeException + * + * @return array */ - public function scheduled_subscription_payment($amount_to_charge, WC_Order $renewalOrder) - { + public function authorizeTransaction( + WC_Order $order, + WC_Payment_Token_Oneclick $paymentToken = null, + $amount = null + ): array { + try { - $this->logger->logInfo('New scheduled_subscription_payment for Order #' . $renewalOrder->get_id()); - $customerId = $renewalOrder->get_customer_id(); - if (!$customerId) { - $this->logger->logError('There is no costumer id on the renewal order'); - throw new EcommerceException('There is no costumer id on the renewal order'); - } + $token = $this->getWcPaymentToken($paymentToken); + $this->logger->logInfo('[Oneclick] Checkout: paying with token ID #' . $token->get_id()); - /** @var WC_Payment_Token_Oneclick $paymentToken */ - $paymentToken = WC_Payment_Tokens::get_customer_default_token($customerId); - $this->authorizeTransaction($renewalOrder, $paymentToken, $amount_to_charge); + $amount = $this->getAmountForAuthorize($amount, $order); + $authorizeResponse = + $this->oneclickTransbankSdk->authorize( + $order->get_id(), + $amount, + $token->get_username(), + $token->get_token() + ); - $this->setAfterPaymentOrderStatus($renewalOrder); - } catch (Exception $ex) { - $this->logger->logError("Error al procesar suscripción: " . $ex->getMessage()); + $order->add_payment_token($token); + $this->setAfterPaymentOrderStatus($order); + if (wc()->cart) { + wc()->cart->empty_cart(); + } + $this->add_order_notes($order, $authorizeResponse, 'Oneclick: Pago exitoso'); + do_action('wc_transbank_oneclick_transaction_approved', ['order' => $order->get_data()]); + return [ + 'result' => 'success', + 'redirect' => $this->get_return_url($order), + ]; + } catch (CreateTransactionOneclickException $e) { + $order->update_status('failed'); + $order->add_order_note('Problemas al crear el registro de Transacción'); + } catch (AuthorizeOneclickException $e) { + $order->update_status('failed'); + $order->add_order_note('Transacción con problemas de autorización'); + } catch (RejectedAuthorizeOneclickException $e) { + $order->update_status('failed'); + $this->add_order_notes($order, $e->getAuthorizeResponse(), 'Oneclick: Pago rechazado'); + $order->add_order_note('Transacción rechazada'); + } catch (ConstraintsViolatedAuthorizeOneclickException $e) { + $order->update_status('failed'); + $this->add_order_notes($order, $e->getAuthorizeResponse(), 'Oneclick: Pago rechazado'); + $order->add_order_note('CONSTRAINTS_VIOLATED: ' . $e->getMessage()); } + + do_action('wc_transbank_oneclick_transaction_failed', ['order' => $order->get_data()]); + throw $e; } public function get_saved_payment_methods_list($saved_methods) @@ -280,117 +435,6 @@ public function methods_list_item_oneclick($item, $payment_token) return $item; } - public function set_payment_token_class() - { - return WC_Payment_Token_Oneclick::class; - } - - /** - * Procesar pago y retornar resultado. - ** - * - * @throws MallTransactionAuthorizeException - */ - public function process_payment($order_id) - { - $errorHookName = 'wc_gateway_transbank_process_payment_error_' . $this->id; - $shouldThrowException = false; - - try { - $order = new WC_Order($order_id); - - if (!$order->needs_payment() && !wcs_is_subscription($order_id)) { - $this->logger->logError('This order was already paid or does not need payment'); - $errorMessage = __( - 'Esta transacción puede ya estar pagada o encontrarse en un estado que no permite un nuevo pago. ', - 'transbank_wc_plugin' - ); - - throw new EcommerceException($errorMessage); - } - - $paymentMethodOption = $_POST["wc-{$this->id}-payment-token"] ?? null; - $addNewCard = 'new' === $paymentMethodOption || $paymentMethodOption === null; - $payWithSavedToken = $paymentMethodOption !== null && !$addNewCard; - - if (!get_current_user_id()) { - $order->add_order_note( - 'El usuario intentó pagar con oneclick pero no tiene (y no creó durante el checkout)' . - ' cuenta de usuario' - ); - $this->logger->logInfo('Checkout: The user should have an account to add a new card. '); - - $errorMessage = __( - 'Webpay Oneclick: Debes crear o tener una cuenta en el sitio para poder inscribir ' . - 'tu tarjeta y usar este método de pago.', - 'transbank_wc_plugin' - ); - - throw new EcommerceException($errorMessage); - } - - if ($addNewCard) { - $this->logger->logInfo('[Oneclick] Checkout: start inscription'); - - $response = $this->start($order_id); - - $this->logger->logInfo('[Oneclick] Checkout: inscription response: '); - $this->logger->logInfo(json_encode($response)); - $order->add_order_note('El usuario inició inscripción de nueva tarjeta. Redirigiendo a ' . - 'formulario OneClick...'); - - do_action('transbank_oneclick_adding_card_from_order', $order); - - return [ - 'result' => 'success', - 'redirect' => $response->getRedirectUrl(), - ]; - } - - if ($payWithSavedToken) { - - $shouldThrowException = true; - return $this->authorizeTransaction($order); - } - $errorMessage = __('Error interno: no se pudo procesar el pago', 'transbank_wc_plugin'); - throw new EcommerceException($errorMessage); - } catch (\Throwable $exception) { - $errorMessage = ErrorHelper::getErrorMessageBasedOnTransbankSdkException($exception); - do_action($errorHookName, $exception, $shouldThrowException); - BlocksHelper::addLegacyNotices($errorMessage, 'error'); - - return [ - 'result' => 'error', - 'redirect' => '' - ]; - } - } - - /** - * @throws \GuzzleHttp\Exception\GuzzleException - * @throws InscriptionStartException - */ - public function add_payment_method() - { - $response = $this->start(null, 'my_account'); - $redirectUrl = $response->getRedirectUrl(); - - return wp_redirect($redirectUrl); - } - - /** - * Outputs a checkbox for saving a new payment method to the database. - * - * @since 2.6.0 - */ - public function save_payment_method_checkbox() - { - $html = '

- Esta tarjeta se guardará en tu cuenta para que puedas volver a usarla. -

'; - echo $html; - } - /** * Inicializar campos de formulario. **/ @@ -565,61 +609,18 @@ private function getAmountForAuthorize($amount, $order) return $amount; } - /** - * @param WC_Order $order - * - * @throws Transbank\Webpay\Oneclick\Exceptions\MallTransactionAuthorizeException - * - * @return array - */ - public function authorizeTransaction( - WC_Order $order, - WC_Payment_Token_Oneclick $paymentToken = null, - $amount = null - ): array { - - try { - - $token = $this->getWcPaymentToken($paymentToken); - $this->logger->logInfo('[Oneclick] Checkout: paying with token ID #' . $token->get_id()); - - $amount = $this->getAmountForAuthorize($amount, $order); - $authorizeResponse = - $this->oneclickTransbankSdk->authorize( - $order->get_id(), - $amount, $token->get_username(), - $token->get_token() - ); - - $order->add_payment_token($token); - $this->setAfterPaymentOrderStatus($order); - if (wc()->cart) { - wc()->cart->empty_cart(); - } - $this->add_order_notes($order, $authorizeResponse, 'Oneclick: Pago exitoso'); - do_action('wc_transbank_oneclick_transaction_approved', ['order' => $order->get_data()]); - return [ - 'result' => 'success', - 'redirect' => $this->get_return_url($order), - ]; - } catch (CreateTransactionOneclickException $e) { - $order->update_status('failed'); - $order->add_order_note('Problemas al crear el registro de Transacción'); - } catch (AuthorizeOneclickException $e) { - $order->update_status('failed'); - $order->add_order_note('Transacción con problemas de autorización'); - } catch (RejectedAuthorizeOneclickException $e) { - $order->update_status('failed'); - $this->add_order_notes($order, $e->getAuthorizeResponse(), 'Oneclick: Pago rechazado'); - $order->add_order_note('Transacción rechazada'); - } catch (ConstraintsViolatedAuthorizeOneclickException $e) { - $order->update_status('failed'); - $this->add_order_notes($order, $e->getAuthorizeResponse(), 'Oneclick: Pago rechazado'); - $order->add_order_note('CONSTRAINTS_VIOLATED: ' . $e->getMessage()); - } + public function set_payment_token_class() + { + return WC_Payment_Token_Oneclick::class; + } - do_action('wc_transbank_oneclick_transaction_failed', ['order' => $order->get_data()]); - throw $e; + public function is_valid_for_use() + { + return in_array( + get_woocommerce_currency(), + apply_filters('woocommerce_transbank_webpay_oneclick_supported_currencies', ['CLP']), + true + ); } /** From c46ab65d172f29f9acab4760bf1af65391695b54 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 16:03:47 -0400 Subject: [PATCH 34/70] refactor: add method checkOrderCanBePaid --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 1f704564..da021328 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -120,15 +120,7 @@ public function process_payment($order_id) try { $order = new WC_Order($order_id); - if (!$order->needs_payment() && !wcs_is_subscription($order_id)) { - $this->logger->logError('This order was already paid or does not need payment'); - $errorMessage = __( - 'Esta transacción puede ya estar pagada o encontrarse en un estado que no permite un nuevo pago. ', - 'transbank_wc_plugin' - ); - - throw new EcommerceException($errorMessage); - } + $this->checkOrderCanBePaid($order); $paymentMethodOption = $_POST["wc-{$this->id}-payment-token"] ?? null; $addNewCard = 'new' === $paymentMethodOption || $paymentMethodOption === null; @@ -585,6 +577,28 @@ public function start( return $this->oneclickTransbankSdk->startInscription($orderId, $userInfo->ID, $email, $returnUrl, $from); } + /** + * Checks if the order can be paid. + * + * This method verifies whether an order requires payment or if it's already paid. + * It logs an error and throws an EcommerceException if the order does not need payment or if it cannot be paid again. + * + * @param int $order_id The ID of the order to check. + * @throws EcommerceException If the order does not need payment or is in a state that does not allow a new payment. + */ + private function checkOrderCanBePaid(WC_Order $order) + { + if (!$order->needs_payment() && !wcs_is_subscription($order->get_id())) { + $this->logger->logError('This order was already paid or does not need payment'); + $errorMessage = __( + 'Esta transacción puede ya estar pagada o encontrarse en un estado que no permite un nuevo pago. ', + 'transbank_wc_plugin' + ); + + throw new EcommerceException($errorMessage); + } + } + /** * @param WC_Payment_Token_Oneclick $paymentToken * From 5a8b4fb1f4a195f98455a6aa2a1fc851b3c0d75d Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 16:06:04 -0400 Subject: [PATCH 35/70] refactor: add method checkUserIsLoggedIn --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index da021328..e6a663ea 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -121,6 +121,7 @@ public function process_payment($order_id) $order = new WC_Order($order_id); $this->checkOrderCanBePaid($order); + $this->checkUserIsLoggedIn(); $paymentMethodOption = $_POST["wc-{$this->id}-payment-token"] ?? null; $addNewCard = 'new' === $paymentMethodOption || $paymentMethodOption === null; @@ -599,6 +600,29 @@ private function checkOrderCanBePaid(WC_Order $order) } } + /** + * Checks if the user is logged in before allowing card registration. + * + * This method verifies whether the user is logged in before allowing them to add a new card. + * It logs an informational message and throws an EcommerceException if the user is not logged in. + * + * @throws EcommerceException If the user is not logged in. + */ + private function checkUserIsLoggedIn() + { + // Check if the user is logged in + if (!is_user_logged_in()) { + $this->logger->logInfo('Checkout: The user should have an account to add a new card. '); + $errorMessage = __( + 'Webpay Oneclick: Debes crear o tener una cuenta en el sitio para poder inscribir ' . + 'tu tarjeta y usar este método de pago.', + 'transbank_wc_plugin' + ); + + throw new EcommerceException($errorMessage); + } + } + /** * @param WC_Payment_Token_Oneclick $paymentToken * From 3ee9ba8b3d8cdaf0513f8df30bab653fbc81d93c Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 22:42:14 -0400 Subject: [PATCH 36/70] feat: update getWcPaymentToken to accept payment token id --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index e6a663ea..a42c9361 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -624,19 +624,16 @@ private function checkUserIsLoggedIn() } /** - * @param WC_Payment_Token_Oneclick $paymentToken + * Retrieves a WC_Payment_Token_Oneclick object by its token ID. * - * @return WC_Payment_Token_Oneclick + * This method retrieves a payment token of type WC_Payment_Token_Oneclick using its ID. + * + * @param string $paymentTokenId The ID of the payment token to retrieve. + * @return WC_Payment_Token_Oneclick Returns the payment token object. */ - private function getWcPaymentToken(WC_Payment_Token_Oneclick $paymentToken = null) + private function getWcPaymentToken(string $paymentTokenId): WC_Payment_Token_Oneclick { - if ($paymentToken) { - return $paymentToken; - } else { - $tokenId = wc_clean($_POST["wc-{$this->id}-payment-token"]); - /** @var WC_Payment_Token_Oneclick $token */ - return \WC_Payment_Tokens::get($tokenId); - } + return WC_Payment_Tokens::get($paymentTokenId); } private function getAmountForAuthorize($amount, $order) From ed870c5db0bfd34d68ae409ecb187503bc051ed9 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 22:54:24 -0400 Subject: [PATCH 37/70] refactor: change method getAmountForAuthorize to getTotalAmountFromOrder --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index a42c9361..6c166d31 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -636,12 +636,9 @@ private function getWcPaymentToken(string $paymentTokenId): WC_Payment_Token_One return WC_Payment_Tokens::get($paymentTokenId); } - private function getAmountForAuthorize($amount, $order) + private function getTotalAmountFromOrder($order) { - if ($amount == null) { - $amount = (int) number_format($order->get_total(), 0, ',', ''); - } - return $amount; + return (int) number_format($order->get_total(), 0, ',', ''); } public function set_payment_token_class() From 0bf20d7cf6781f8017759238dd3a090fb427de77 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:01:50 -0400 Subject: [PATCH 38/70] refactor: change method setAfterPaymentOrderStatus to setOrderAsComplete --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 6c166d31..5a25354d 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -669,12 +669,18 @@ protected function failedRefund(WC_Order $order, string $message) } /** - * @param WC_Order $order + * Marks the given order as complete and updates its status if specified. + * + * This method sets the order's payment status to complete and then updates + * the order status based on the configured option 'oneclick_after_payment_order_status'. + * If no status is specified, the order is marked as complete without changing the status. + * + * @param WC_Order $order The order object to update. */ - private function setAfterPaymentOrderStatus(WC_Order $order) + private function setOrderAsComplete(WC_Order $order) { $status = $this->get_option('oneclick_after_payment_order_status'); - if ($status == '') { + if (empty($status)) { $order->payment_complete(); } else { $order->payment_complete(); From 206b12e53d7ab7cb99122f79de756182ff409164 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:03:26 -0400 Subject: [PATCH 39/70] docs: add doc to getTotalAmountFromOrder method --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 5a25354d..83c26532 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -636,7 +636,16 @@ private function getWcPaymentToken(string $paymentTokenId): WC_Payment_Token_One return WC_Payment_Tokens::get($paymentTokenId); } - private function getTotalAmountFromOrder($order) + /** + * Retrieves the total amount from an order as an integer. + * + * This method takes a WC_Order object, gets its total amount, formats it to remove any decimal places, + * and then converts it to an integer. + * + * @param WC_Order $order The order object from which to retrieve the total amount. + * @return int The total amount of the order as an integer. + */ + private function getTotalAmountFromOrder(WC_Order $order): int { return (int) number_format($order->get_total(), 0, ',', ''); } From d13c5a1f35edb23a80ae98d810989fbe9cc5761f Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:07:37 -0400 Subject: [PATCH 40/70] feat: add method emptyCart --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 83c26532..84ff1bee 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -696,4 +696,17 @@ private function setOrderAsComplete(WC_Order $order) $order->update_status($status); } } + + /** + * Empties the WooCommerce cart. + * + * This method checks if the WooCommerce cart exists and then empties it. + * If the cart exists, all items in the cart are removed. + */ + private function emptyCart() + { + if (wc()->cart) { + wc()->cart->empty_cart(); + } + } } From ead6945e6943be633040c9fbf37b62ffcd03e5fe Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:50:59 -0400 Subject: [PATCH 41/70] feat: add method setOrderAsFailed --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 84ff1bee..440b7679 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -697,6 +697,20 @@ private function setOrderAsComplete(WC_Order $order) } } + /** + * Sets the given order as failed and adds a note to the order. + * + * This method updates the status of the provided WC_Order object to 'failed' and adds a custom note to the order. + * + * @param WC_Order $order The order object to update. + * @param string $orderNotes The custom note to add to the order. + */ + private function setOrderAsFailed(WC_Order $order, string $orderNotes) + { + $order->update_status('failed'); + $order->add_order_note($orderNotes); + } + /** * Empties the WooCommerce cart. * From 57d048a2beced35fc0e11355e618283308bcf18f Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:51:59 -0400 Subject: [PATCH 42/70] refactor: change method add_order_notes to getOrderNotesFromAuthorizeResponse --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 440b7679..f5f7412e 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -24,6 +24,7 @@ use Transbank\Webpay\Oneclick\Exceptions\MallTransactionAuthorizeException; use Transbank\Webpay\Oneclick\Exceptions\InscriptionStartException; use Transbank\Webpay\Oneclick\Responses\InscriptionStartResponse; +use Transbank\Webpay\Oneclick\Responses\MallTransactionAuthorizeResponse; use WC_Order; use WC_Payment_Gateway_CC; use WC_Payment_Tokens; @@ -523,7 +524,7 @@ public function init_form_fields() ]; } - protected function add_order_notes(WC_Order $wooCommerceOrder, $response, $message) + protected function getOrderNotesFromAuthorizeResponse(MallTransactionAuthorizeResponse $response, string $orderNotesTitle) { $firstDetail = $response->getDetails()[0]; $formattedAmount = TbkResponseUtil::getAmountFormatted($firstDetail->getAmount()); @@ -535,9 +536,9 @@ protected function add_order_notes(WC_Order $wooCommerceOrder, $response, $messa $installmentAmount = $firstDetail->getInstallmentsAmount() ?? 0; $formattedInstallmentAmount = TbkResponseUtil::getAmountFormatted($installmentAmount); - $transactionDetails = " + return "
-

{$message}

+

{$orderNotesTitle}

Estado: {$status}
Orden de compra mall: {$response->getBuyOrder()}
@@ -554,8 +555,6 @@ protected function add_order_notes(WC_Order $wooCommerceOrder, $response, $messa Fecha contable: {$formattedAccountingDate}
"; - $wooCommerceOrder->add_order_note($transactionDetails); - $wooCommerceOrder->add_meta_data('transbank_response', json_encode($response)); } /** From 0ac170f108ea6b686f03197bd569e92e53a9dc9f Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:53:41 -0400 Subject: [PATCH 43/70] feat: add method handleInscription --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index f5f7412e..5b359467 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -335,6 +335,23 @@ public function form() { // No render payment form. } + private function handleInscription(WC_Order $order) + { + $this->logger->logInfo('[Oneclick] Checkout: start inscription'); + + $response = $this->start($order->get_id()); + + $this->logger->logInfo('[Oneclick] Checkout: inscription response: '); + $this->logger->logInfo(json_encode($response)); + $order->add_order_note('El usuario inició inscripción de nueva tarjeta. Redirigiendo a formulario OneClick.'); + + do_action('transbank_oneclick_adding_card_from_order', $order); + + return [ + 'result' => 'success', + 'redirect' => $response->getRedirectUrl(), + ]; + } /** * @param WC_Order $order From 763d4fb1b245eabf5951d2287559b5fec2de7a57 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:56:03 -0400 Subject: [PATCH 44/70] feat: add property shouldThrowException --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 5b359467..1fe20d36 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -52,6 +52,13 @@ class WC_Gateway_Transbank_Oneclick_Mall_REST extends WC_Payment_Gateway_CC */ protected $oneclickTransbankSdk; + /** + * Indicates if the exception message should be displayed in the notice when checkout block is enabled. + * + * @var bool + */ + private $shouldThrowException; + /** * WC_Gateway_Transbank_Oneclick_Mall_REST constructor. */ @@ -81,6 +88,7 @@ public function __construct() $this->get_option('oneclick_payment_gateway_description', self::PAYMENT_GW_DESCRIPTION); $this->icon = plugin_dir_url(dirname(dirname(__FILE__))) . 'images/oneclick.png'; + $this->shouldThrowException = false; $this->init_form_fields(); $this->init_settings(); From 8827d7fe6052f73fd80af3295a31eea8f730da69 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:56:26 -0400 Subject: [PATCH 45/70] feat: add method handleAuthorization --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 1fe20d36..fa699d93 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -361,6 +361,60 @@ private function handleInscription(WC_Order $order) ]; } + private function handleAuthorization(WC_Order $order, string $paymentTokenId) + { + try { + $orderNotes = ''; + $this->logger->logInfo('[Oneclick] Checkout: pagando con el token ID #' . $paymentTokenId); + $paymentToken = $this->getWcPaymentToken($paymentTokenId); + $amount = $this->getTotalAmountFromOrder($order); + + $authorizeResponse = $this->oneclickTransbankSdk->authorize( + $order->get_id(), + $amount, + $paymentToken->get_username(), + $paymentToken->get_token() + ); + + $order->add_payment_token($paymentToken); + $this->setOrderAsComplete($order); + $this->emptyCart(); + + $orderNotes = $this->getOrderNotesFromAuthorizeResponse($authorizeResponse, 'Oneclick: Pago exitoso'); + $order->add_order_note($orderNotes); + + do_action('wc_transbank_oneclick_transaction_approved', ['order' => $order->get_data()]); + return [ + 'result' => 'success', + 'redirect' => $this->get_return_url($order), + ]; + } catch (CreateTransactionOneclickException $e) { + $orderNotes = 'Transacción con problemas de autorización'; + } catch (AuthorizeOneclickException $e) { + $orderNotes = 'Problemas al crear el registro de Transacción'; + } catch (RejectedAuthorizeOneclickException $e) { + $response = $e->getAuthorizeResponse(); + $orderNotes = $this->getOrderNotesFromAuthorizeResponse( + $response, + 'Oneclick: Pago rechazado' + ); + $order->add_meta_data('transbank_response', json_encode($response)); + } catch (ConstraintsViolatedAuthorizeOneclickException $e) { + $response = $e->getAuthorizeResponse(); + $orderNotes = $this->getOrderNotesFromAuthorizeResponse( + $response, + 'Oneclick: Pago rechazado' + ); + $order->add_order_note($e->getMessage()); + $order->add_meta_data('transbank_response', json_encode($response)); + } finally { + $this->shouldThrowException = true; + $this->setOrderAsFailed($order, $orderNotes); + do_action('wc_transbank_oneclick_transaction_failed', ['order' => $order->get_data()]); + throw $e; + } + } + /** * @param WC_Order $order * From cc8aa8a93516d404c11377a4f40e2c3d158f8d65 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:56:57 -0400 Subject: [PATCH 46/70] feat: add method handleRequest --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index fa699d93..595dbdb7 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -343,6 +343,18 @@ public function form() { // No render payment form. } + + private function handleRequest(array $request, WC_Order $order) + { + $paymentTokenId = $request["wc-{$this->id}-payment-token"] ?? null; + + if ($paymentTokenId === 'new' || is_null($paymentTokenId)) { + return $this->handleInscription($order); + } + + return $this->handleAuthorization($order, $paymentTokenId); + } + private function handleInscription(WC_Order $order) { $this->logger->logInfo('[Oneclick] Checkout: start inscription'); From 147a001f7070270adb5e3e7819a1c76579d776ea Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:57:46 -0400 Subject: [PATCH 47/70] refactor: implement method handleRequest --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 52 ++----------------- 1 file changed, 3 insertions(+), 49 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 595dbdb7..146a0a0b 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -123,63 +123,17 @@ public function __construct() */ public function process_payment($order_id) { - $errorHookName = 'wc_gateway_transbank_process_payment_error_' . $this->id; - $shouldThrowException = false; - try { $order = new WC_Order($order_id); $this->checkOrderCanBePaid($order); $this->checkUserIsLoggedIn(); - $paymentMethodOption = $_POST["wc-{$this->id}-payment-token"] ?? null; - $addNewCard = 'new' === $paymentMethodOption || $paymentMethodOption === null; - $payWithSavedToken = $paymentMethodOption !== null && !$addNewCard; - - if (!get_current_user_id()) { - $order->add_order_note( - 'El usuario intentó pagar con oneclick pero no tiene (y no creó durante el checkout)' . - ' cuenta de usuario' - ); - $this->logger->logInfo('Checkout: The user should have an account to add a new card. '); - - $errorMessage = __( - 'Webpay Oneclick: Debes crear o tener una cuenta en el sitio para poder inscribir ' . - 'tu tarjeta y usar este método de pago.', - 'transbank_wc_plugin' - ); - - throw new EcommerceException($errorMessage); - } - - if ($addNewCard) { - $this->logger->logInfo('[Oneclick] Checkout: start inscription'); - - $response = $this->start($order_id); - - $this->logger->logInfo('[Oneclick] Checkout: inscription response: '); - $this->logger->logInfo(json_encode($response)); - $order->add_order_note('El usuario inició inscripción de nueva tarjeta. Redirigiendo a ' . - 'formulario OneClick...'); - - do_action('transbank_oneclick_adding_card_from_order', $order); - - return [ - 'result' => 'success', - 'redirect' => $response->getRedirectUrl(), - ]; - } - - if ($payWithSavedToken) { - - $shouldThrowException = true; - return $this->authorizeTransaction($order); - } - $errorMessage = __('Error interno: no se pudo procesar el pago', 'transbank_wc_plugin'); - throw new EcommerceException($errorMessage); + return $this->handleRequest($_POST, $order); } catch (\Throwable $exception) { + $errorHookName = 'wc_gateway_transbank_process_payment_error_' . $this->id; $errorMessage = ErrorHelper::getErrorMessageBasedOnTransbankSdkException($exception); - do_action($errorHookName, $exception, $shouldThrowException); + do_action($errorHookName, $exception, true); BlocksHelper::addLegacyNotices($errorMessage, 'error'); return [ From 79293d24a68c4a892653a77ce228794dc5f4e70b Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 23:59:45 -0400 Subject: [PATCH 48/70] docs: add docs for method handleAuthorization --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 146a0a0b..56a4d7bf 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -327,6 +327,21 @@ private function handleInscription(WC_Order $order) ]; } + /** + * Handles the authorization process for a OneClick payment. + * + * This method performs the authorization process for a OneClick payment. + * + * @param WC_Order $order The WooCommerce order object. + * @param string $paymentTokenId The ID of the payment token associated with the order. + * + * @return array The result of the authorization process, including a success message and redirect URL. + * + * @throws CreateTransactionOneclickException If there are issues creating the transaction. + * @throws AuthorizeOneclickException If there are problems with authorization. + * @throws RejectedAuthorizeOneclickException If the authorization is rejected. + * @throws ConstraintsViolatedAuthorizeOneclickException If constraints are violated during authorization. + */ private function handleAuthorization(WC_Order $order, string $paymentTokenId) { try { From d34ae0e79809a2a8c4b3820d004831273fd2fe52 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 00:02:02 -0400 Subject: [PATCH 49/70] docs: add docs for method handleInscription --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 56a4d7bf..e0ed5fb4 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -309,6 +309,15 @@ private function handleRequest(array $request, WC_Order $order) return $this->handleAuthorization($order, $paymentTokenId); } + /** + * Handles the inscription process for adding a new card. + * + * This method initiates the inscription process for adding a new card to the OneClick payment method. + * + * @param WC_Order $order The WooCommerce order object. + * + * @return array The result of the inscription process, including a success message and redirect URL. + */ private function handleInscription(WC_Order $order) { $this->logger->logInfo('[Oneclick] Checkout: start inscription'); From b09edc88a5b18702461ae94d2090451820ee424a Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 00:03:26 -0400 Subject: [PATCH 50/70] docs: add docs for method handleRequest --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index e0ed5fb4..da9d2286 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -298,6 +298,19 @@ public function form() // No render payment form. } + /** + * Handles the request for processing a payment or initiating a new card inscription. + * + * This method determines whether to process a payment authorization or initiate a new card inscription + * based on the provided request data. If a new payment token ID is provided or if no token ID is provided, + * it initiates the inscription process. Otherwise, it handles the authorization process for the provided + * payment token ID. + * + * @param array $request The request data containing payment token information. + * @param WC_Order $order The WooCommerce order object associated with the request. + * + * @return array The result of the processing, including a success message and redirect URL. + */ private function handleRequest(array $request, WC_Order $order) { $paymentTokenId = $request["wc-{$this->id}-payment-token"] ?? null; From 3a5e10e818832d45c746bd19481fd5255fe6677c Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 00:24:50 -0400 Subject: [PATCH 51/70] refactor: implement new flow for subscription authorizations --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index da9d2286..45b5fe7a 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -130,7 +130,7 @@ public function process_payment($order_id) $this->checkUserIsLoggedIn(); return $this->handleRequest($_POST, $order); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $errorHookName = 'wc_gateway_transbank_process_payment_error_' . $this->id; $errorMessage = ErrorHelper::getErrorMessageBasedOnTransbankSdkException($exception); do_action($errorHookName, $exception, true); @@ -144,26 +144,48 @@ public function process_payment($order_id) } /** - * @throws MallTransactionAuthorizeException + * Processes a scheduled subscription payment. + * + * This method authorizes a scheduled subscription payment for the given renewal order. It retrieves the customer ID + * from the renewal order, obtains the customer's default payment token and authorizes the payment with Oneclick. + * + * @param float $amount_to_charge The amount to charge for the subscription payment. + * @param WC_Order $renewalOrder The renewal order object for the subscription. + * + * @throws EcommerceException If there is no customer ID on the renewal order. */ public function scheduled_subscription_payment($amount_to_charge, WC_Order $renewalOrder) { try { - $this->logger->logInfo('New scheduled_subscription_payment for Order #' . $renewalOrder->get_id()); + $this->logger->logInfo('Autorizando suscripción para la orden #' . $renewalOrder->get_id()); $customerId = $renewalOrder->get_customer_id(); - if (!$customerId) { - $this->logger->logError('There is no costumer id on the renewal order'); + if (!$customerId) { + $this->logger->logError('No existe el ID de usuario en la suscripción.'); throw new EcommerceException('There is no costumer id on the renewal order'); } /** @var WC_Payment_Token_Oneclick $paymentToken */ $paymentToken = WC_Payment_Tokens::get_customer_default_token($customerId); - $this->authorizeTransaction($renewalOrder, $paymentToken, $amount_to_charge); + + $authorizeResponse = $this->oneclickTransbankSdk->authorize( + $renewalOrder->get_id(), + $amount_to_charge, + $paymentToken->get_username(), + $paymentToken + ); + + $renewalOrder->add_payment_token($paymentToken); + + $orderNotes = $this->getOrderNotesFromAuthorizeResponse($authorizeResponse, 'Oneclick: Pago de suscripción exitoso'); + $renewalOrder->add_order_note($orderNotes); + + do_action('wc_transbank_oneclick_transaction_approved', ['order' => $renewalOrder->get_data()]); - $this->setAfterPaymentOrderStatus($renewalOrder); - } catch (Exception $ex) { + $this->setOrderAsComplete($renewalOrder); + } catch (Throwable $ex) { $this->logger->logError("Error al procesar suscripción: " . $ex->getMessage()); + $renewalOrder->add_order_note('Error al procesar suscripción, para más detalles revisar el archivo log.'); } } From 86b877b715a231cc787cdb0af2c63343202ff043 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 00:25:40 -0400 Subject: [PATCH 52/70] refactor: remove authorizeTransaction method --- ...C_Gateway_Transbank_Oneclick_Mall_REST.php | 60 +------------------ 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 45b5fe7a..35c6390f 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -167,7 +167,7 @@ public function scheduled_subscription_payment($amount_to_charge, WC_Order $rene /** @var WC_Payment_Token_Oneclick $paymentToken */ $paymentToken = WC_Payment_Tokens::get_customer_default_token($customerId); - + $authorizeResponse = $this->oneclickTransbankSdk->authorize( $renewalOrder->get_id(), $amount_to_charge, @@ -440,64 +440,6 @@ private function handleAuthorization(WC_Order $order, string $paymentTokenId) } } - /** - * @param WC_Order $order - * - * @throws Transbank\Webpay\Oneclick\Exceptions\MallTransactionAuthorizeException - * - * @return array - */ - public function authorizeTransaction( - WC_Order $order, - WC_Payment_Token_Oneclick $paymentToken = null, - $amount = null - ): array { - - try { - - $token = $this->getWcPaymentToken($paymentToken); - $this->logger->logInfo('[Oneclick] Checkout: paying with token ID #' . $token->get_id()); - - $amount = $this->getAmountForAuthorize($amount, $order); - $authorizeResponse = - $this->oneclickTransbankSdk->authorize( - $order->get_id(), - $amount, - $token->get_username(), - $token->get_token() - ); - - $order->add_payment_token($token); - $this->setAfterPaymentOrderStatus($order); - if (wc()->cart) { - wc()->cart->empty_cart(); - } - $this->add_order_notes($order, $authorizeResponse, 'Oneclick: Pago exitoso'); - do_action('wc_transbank_oneclick_transaction_approved', ['order' => $order->get_data()]); - return [ - 'result' => 'success', - 'redirect' => $this->get_return_url($order), - ]; - } catch (CreateTransactionOneclickException $e) { - $order->update_status('failed'); - $order->add_order_note('Problemas al crear el registro de Transacción'); - } catch (AuthorizeOneclickException $e) { - $order->update_status('failed'); - $order->add_order_note('Transacción con problemas de autorización'); - } catch (RejectedAuthorizeOneclickException $e) { - $order->update_status('failed'); - $this->add_order_notes($order, $e->getAuthorizeResponse(), 'Oneclick: Pago rechazado'); - $order->add_order_note('Transacción rechazada'); - } catch (ConstraintsViolatedAuthorizeOneclickException $e) { - $order->update_status('failed'); - $this->add_order_notes($order, $e->getAuthorizeResponse(), 'Oneclick: Pago rechazado'); - $order->add_order_note('CONSTRAINTS_VIOLATED: ' . $e->getMessage()); - } - - do_action('wc_transbank_oneclick_transaction_failed', ['order' => $order->get_data()]); - throw $e; - } - public function get_saved_payment_methods_list($saved_methods) { $pluginEnvironment = $this->get_option('environment'); From aaf2549d10fd7ddcdd32a7e1e8a20c37e27a6a8e Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 00:35:54 -0400 Subject: [PATCH 53/70] fix: check if exception is defined in finally block --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 35c6390f..20e00577 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -433,10 +433,12 @@ private function handleAuthorization(WC_Order $order, string $paymentTokenId) $order->add_order_note($e->getMessage()); $order->add_meta_data('transbank_response', json_encode($response)); } finally { - $this->shouldThrowException = true; - $this->setOrderAsFailed($order, $orderNotes); - do_action('wc_transbank_oneclick_transaction_failed', ['order' => $order->get_data()]); - throw $e; + if (isset($e)) { + $this->shouldThrowException = true; + $this->setOrderAsFailed($order, $orderNotes); + do_action('wc_transbank_oneclick_transaction_failed', ['order' => $order->get_data()]); + throw $e; + } } } From dec307185d4428d8391d32200fc9d494c62d2f46 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 00:45:47 -0400 Subject: [PATCH 54/70] fix: pass token to authorize in scheduled_subscription_payment --- .../PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 20e00577..628bbfe8 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -172,7 +172,7 @@ public function scheduled_subscription_payment($amount_to_charge, WC_Order $rene $renewalOrder->get_id(), $amount_to_charge, $paymentToken->get_username(), - $paymentToken + $paymentToken->get_token() ); $renewalOrder->add_payment_token($paymentToken); From d5609596dd9cd57dc277b284c6877cb3058e43d4 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 00:49:00 -0400 Subject: [PATCH 55/70] feat: add log when finish subscription authorization --- .../PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 628bbfe8..4e51e54f 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -183,6 +183,8 @@ public function scheduled_subscription_payment($amount_to_charge, WC_Order $rene do_action('wc_transbank_oneclick_transaction_approved', ['order' => $renewalOrder->get_data()]); $this->setOrderAsComplete($renewalOrder); + + $this->logger->logInfo('Suscripción autorizada correctamente para la orden #' . $renewalOrder->get_id()); } catch (Throwable $ex) { $this->logger->logError("Error al procesar suscripción: " . $ex->getMessage()); $renewalOrder->add_order_note('Error al procesar suscripción, para más detalles revisar el archivo log.'); From 5ba9c65653410f66d79e4476c052f9703eb5c245 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 00:51:06 -0400 Subject: [PATCH 56/70] feat: add log when finish oneclick payment --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 4e51e54f..9740e92b 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -411,6 +411,9 @@ private function handleAuthorization(WC_Order $order, string $paymentTokenId) $order->add_order_note($orderNotes); do_action('wc_transbank_oneclick_transaction_approved', ['order' => $order->get_data()]); + + $this->logger->logInfo('Se ha autorizado el pago correctamente para la orden #' . $order->get_id()); + return [ 'result' => 'success', 'redirect' => $this->get_return_url($order), From 51798b30e4b898e7e280afe9b20d5e9fb1f82ae6 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 10:45:03 -0400 Subject: [PATCH 57/70] feat: add log when authorization throw exception --- .../PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 9740e92b..d53be45b 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -442,6 +442,7 @@ private function handleAuthorization(WC_Order $order, string $paymentTokenId) $this->shouldThrowException = true; $this->setOrderAsFailed($order, $orderNotes); do_action('wc_transbank_oneclick_transaction_failed', ['order' => $order->get_data()]); + $this->logger->logError('Error al autorizar: ' . $e->getMessage()); throw $e; } } From a96db6cd91bfbb7f4b40cd404b2623a7ae4c2bc6 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 10:53:07 -0400 Subject: [PATCH 58/70] feat: translate logs to spanish --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index d53be45b..ce355ef9 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -357,11 +357,11 @@ private function handleRequest(array $request, WC_Order $order) */ private function handleInscription(WC_Order $order) { - $this->logger->logInfo('[Oneclick] Checkout: start inscription'); + $this->logger->logInfo('[Oneclick] Inicio de inscripción'); $response = $this->start($order->get_id()); - $this->logger->logInfo('[Oneclick] Checkout: inscription response: '); + $this->logger->logInfo('[Oneclick] Respuesta de inscripción: '); $this->logger->logInfo(json_encode($response)); $order->add_order_note('El usuario inició inscripción de nueva tarjeta. Redirigiendo a formulario OneClick.'); @@ -643,7 +643,7 @@ public function start( private function checkOrderCanBePaid(WC_Order $order) { if (!$order->needs_payment() && !wcs_is_subscription($order->get_id())) { - $this->logger->logError('This order was already paid or does not need payment'); + $this->logger->logError('La orden se encuentra en un estado en la que no puede ser pagada.'); $errorMessage = __( 'Esta transacción puede ya estar pagada o encontrarse en un estado que no permite un nuevo pago. ', 'transbank_wc_plugin' @@ -665,7 +665,7 @@ private function checkUserIsLoggedIn() { // Check if the user is logged in if (!is_user_logged_in()) { - $this->logger->logInfo('Checkout: The user should have an account to add a new card. '); + $this->logger->logInfo('El usuario debe tener una cuenta creada para poder inscribir una tarjeta.'); $errorMessage = __( 'Webpay Oneclick: Debes crear o tener una cuenta en el sitio para poder inscribir ' . 'tu tarjeta y usar este método de pago.', From 6f6a5fd8ba05abdf05d235d6bdbb47cd8ec01727 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 11:59:32 -0400 Subject: [PATCH 59/70] refactor: rename method get_saved_payment_methods_list to getOneclickPaymentTokenClass --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index ce355ef9..5ec4718d 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -112,7 +112,7 @@ public function __construct() add_filter('woocommerce_payment_methods_list_item', [$this, 'methods_list_item_oneclick'], null, 2); add_filter('woocommerce_payment_token_class', [$this, 'set_payment_token_class']); add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']); - add_filter('woocommerce_saved_payment_methods_list', [$this, 'get_saved_payment_methods_list'], 10, 2); + add_filter('woocommerce_saved_payment_methods_list', [$this, 'getOneclickPaymentTokenClass'], 10, 2); } /** @@ -703,7 +703,7 @@ private function getTotalAmountFromOrder(WC_Order $order): int return (int) number_format($order->get_total(), 0, ',', ''); } - public function set_payment_token_class() + public function getOneclickPaymentTokenClass() { return WC_Payment_Token_Oneclick::class; } From ca3eec5a1bfb4e4ef14d29d065f640ef8648434b Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 11:48:57 -0400 Subject: [PATCH 60/70] refactor: replace echo for short php tag --- plugin/templates/admin/log.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index 34b87c8a..c448eb49 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -11,14 +11,14 @@

Información de Registros

-
?
+
?
Directorio de registros:
- +
@@ -35,7 +35,7 @@ - > No hay archivos log"; @@ -51,7 +51,7 @@ ?> + value="Ver">
@@ -69,20 +69,20 @@
- +
-
?
+
?
Cantidad de Líneas:
- +
From c247064435e2b58184ac1ee3a49bb4a461c89a9c Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 28 May 2024 12:27:51 -0400 Subject: [PATCH 61/70] fix: use echo to construct HTML --- plugin/templates/admin/log.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugin/templates/admin/log.php b/plugin/templates/admin/log.php index c448eb49..03d38e09 100644 --- a/plugin/templates/admin/log.php +++ b/plugin/templates/admin/log.php @@ -37,17 +37,20 @@ Date: Wed, 29 May 2024 13:09:15 -0400 Subject: [PATCH 62/70] fix: use correct method in payment token filters --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 5ec4718d..6271962f 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -110,9 +110,9 @@ public function __construct() ]); add_filter('woocommerce_payment_methods_list_item', [$this, 'methods_list_item_oneclick'], null, 2); - add_filter('woocommerce_payment_token_class', [$this, 'set_payment_token_class']); + add_filter('woocommerce_payment_token_class', [$this, 'getOneclickPaymentTokenClass']); add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']); - add_filter('woocommerce_saved_payment_methods_list', [$this, 'getOneclickPaymentTokenClass'], 10, 2); + add_filter('woocommerce_saved_payment_methods_list', [$this, 'get_saved_payment_methods_list'], 10, 2); } /** From 39e54340177eb5fa08b957c7bea42aca6be8c566 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 16:24:36 -0400 Subject: [PATCH 63/70] fix: use custom variable instead $_POST --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index 6271962f..ba01826b 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -124,12 +124,13 @@ public function __construct() public function process_payment($order_id) { try { + $request = $_POST; $order = new WC_Order($order_id); $this->checkOrderCanBePaid($order); $this->checkUserIsLoggedIn(); - return $this->handleRequest($_POST, $order); + return $this->handleRequest($request, $order); } catch (Throwable $exception) { $errorHookName = 'wc_gateway_transbank_process_payment_error_' . $this->id; $errorMessage = ErrorHelper::getErrorMessageBasedOnTransbankSdkException($exception); From 3e9cf1c3a94d1aab929d90e5ebf91e9f5a695833 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 16:26:38 -0400 Subject: [PATCH 64/70] feat: sanitize data from payment form --- .../PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index ba01826b..bafa3de4 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -338,7 +338,7 @@ public function form() */ private function handleRequest(array $request, WC_Order $order) { - $paymentTokenId = $request["wc-{$this->id}-payment-token"] ?? null; + $paymentTokenId = wc_clean($request["wc-{$this->id}-payment-token"]) ?? null; if ($paymentTokenId === 'new' || is_null($paymentTokenId)) { return $this->handleInscription($order); From b0dd55b8f24a436d1cf709c12635f798ea3833a0 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 17:02:16 -0400 Subject: [PATCH 65/70] refactor: rename method handleRequest to handleOneclickPayment --- .../WC_Gateway_Transbank_Oneclick_Mall_REST.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php index bafa3de4..1fd12433 100644 --- a/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php +++ b/plugin/src/PaymentGateways/WC_Gateway_Transbank_Oneclick_Mall_REST.php @@ -124,13 +124,12 @@ public function __construct() public function process_payment($order_id) { try { - $request = $_POST; $order = new WC_Order($order_id); $this->checkOrderCanBePaid($order); $this->checkUserIsLoggedIn(); - return $this->handleRequest($request, $order); + return $this->handleOneclickPayment($_POST, $order); } catch (Throwable $exception) { $errorHookName = 'wc_gateway_transbank_process_payment_error_' . $this->id; $errorMessage = ErrorHelper::getErrorMessageBasedOnTransbankSdkException($exception); @@ -336,7 +335,7 @@ public function form() * * @return array The result of the processing, including a success message and redirect URL. */ - private function handleRequest(array $request, WC_Order $order) + private function handleOneclickPayment(array $request, WC_Order $order) { $paymentTokenId = wc_clean($request["wc-{$this->id}-payment-token"]) ?? null; From 312a62ab1637f268c295f4182b7ee04abee85614 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 15:13:44 -0400 Subject: [PATCH 66/70] docs: update changelog --- plugin/readme.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin/readme.txt b/plugin/readme.txt index fb1ac1ac..f85bad8c 100644 --- a/plugin/readme.txt +++ b/plugin/readme.txt @@ -14,6 +14,15 @@ Recibe pagos en línea con tarjetas de crédito, débito y prepago en tu WooComm Recibe pagos en línea con tarjetas de crédito, débito y prepago en tu WooCommerce a través de Webpay Plus y Webpay Oneclick == Changelog == += 1.9.0 = +* Se agrega la opción de poder seleccionar el archivo log en la sección de registros del menú de configuración. +* Se agrega la funcionalidad para que se muestren las tarjetas registradas de Oneclick dependiendo del entorno. +* Se agrega el sufijo [Test] a las tarjetas registradas con Oneclick en entorno de integración. +* Se agrega como dependencia el plugin de WooCommerce. +* Se actualiza el título del producto Webpay pasando de Transbank Webpay Plus a Webpay Plus. +* Se arregla un problema que impedía capturar las excepciones cunado se autorizaba una suscripción. +* Se elimina un hook deprecado que provocaba errores de instalación en algunos entornos. + = 1.8.0 = * Se corrige un problema con el contenido del archivo log que provocaba que se desborde. * Se agrega la funcionalidad para cambiar la descripción de los medios de pago desde la configuración del plugin. From b389dc322331ecd01301ff095ec118c0454f150e Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Wed, 29 May 2024 15:14:29 -0400 Subject: [PATCH 67/70] chore: update woocommerce tested up version --- plugin/webpay-rest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/webpay-rest.php b/plugin/webpay-rest.php index b74e422d..4e836094 100644 --- a/plugin/webpay-rest.php +++ b/plugin/webpay-rest.php @@ -32,7 +32,7 @@ * Author: TransbankDevelopers * Author URI: https://www.transbank.cl * WC requires at least: 7.0 - * WC tested up to: 8.5.1 + * WC tested up to: 8.9.1 */ require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; From 47c62c07b45c0acf7f4f41e54282ce5973a7cc3c Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Thu, 30 May 2024 11:19:11 -0400 Subject: [PATCH 68/70] docs: add upgrade notice --- plugin/readme.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin/readme.txt b/plugin/readme.txt index f85bad8c..f873912e 100644 --- a/plugin/readme.txt +++ b/plugin/readme.txt @@ -163,6 +163,15 @@ Arreglado: * Initial release. == Upgrade Notice == += 1.9.0 = +* Se agrega la opción de poder seleccionar el archivo log en la sección de registros del menú de configuración. +* Se agrega la funcionalidad para que se muestren las tarjetas registradas de Oneclick dependiendo del entorno. +* Se agrega el sufijo [Test] a las tarjetas registradas con Oneclick en entorno de integración. +* Se agrega como dependencia el plugin de WooCommerce. +* Se actualiza el título del producto Webpay pasando de Transbank Webpay Plus a Webpay Plus. +* Se arregla un problema que impedía capturar las excepciones cunado se autorizaba una suscripción. +* Se elimina un hook deprecado que provocaba errores de instalación en algunos entornos. + = 1.8.0 = * Se corrige un problema con el contenido del archivo log que provocaba que se desborde. * Se agrega la funcionalidad para cambiar la descripción de los medios de pago desde la configuración del plugin. From d59180599429e6e5da952fbd0e79a080336b6711 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Thu, 30 May 2024 11:20:17 -0400 Subject: [PATCH 69/70] chore: update wordpress tested up version --- plugin/readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/readme.txt b/plugin/readme.txt index f873912e..61a76a92 100644 --- a/plugin/readme.txt +++ b/plugin/readme.txt @@ -2,7 +2,7 @@ Contributors: TransbankDevelopers Tags: transbank, webpay, oneclick, webpay plus, rest, chile Requires at least: 5.3 -Tested up to: 6.4 +Tested up to: 6.5.3 Requires PHP: 7.4 Stable tag: VERSION_REPLACE_HERE License: 3-Clause BSD License From 391b9c5374adffb8f869f7b53a22541e5b5b8835 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Thu, 30 May 2024 12:02:23 -0400 Subject: [PATCH 70/70] docs: fix typo --- plugin/readme.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/readme.txt b/plugin/readme.txt index 61a76a92..3d799df4 100644 --- a/plugin/readme.txt +++ b/plugin/readme.txt @@ -20,7 +20,7 @@ Recibe pagos en línea con tarjetas de crédito, débito y prepago en tu WooComm * Se agrega el sufijo [Test] a las tarjetas registradas con Oneclick en entorno de integración. * Se agrega como dependencia el plugin de WooCommerce. * Se actualiza el título del producto Webpay pasando de Transbank Webpay Plus a Webpay Plus. -* Se arregla un problema que impedía capturar las excepciones cunado se autorizaba una suscripción. +* Se arregla un problema que impedía capturar las excepciones cuando se autorizaba una suscripción. * Se elimina un hook deprecado que provocaba errores de instalación en algunos entornos. = 1.8.0 = @@ -169,7 +169,7 @@ Arreglado: * Se agrega el sufijo [Test] a las tarjetas registradas con Oneclick en entorno de integración. * Se agrega como dependencia el plugin de WooCommerce. * Se actualiza el título del producto Webpay pasando de Transbank Webpay Plus a Webpay Plus. -* Se arregla un problema que impedía capturar las excepciones cunado se autorizaba una suscripción. +* Se arregla un problema que impedía capturar las excepciones cuando se autorizaba una suscripción. * Se elimina un hook deprecado que provocaba errores de instalación en algunos entornos. = 1.8.0 =