From 5c933525db4be8f64a17591c6c306775bfc017d2 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 11:40:15 -0400 Subject: [PATCH 01/18] style: format file --- Controller/Transaction/AuthorizeOneclick.php | 23 ++++++++------------ 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index 0148e70..5f61320 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -117,8 +117,8 @@ public function execute() $this->log->logError($orderId); $this->log->logError($grandTotal); - $buyOrder = "100000".$orderId; - $childBuyOrder = "200000".$orderId; + $buyOrder = "100000" . $orderId; + $childBuyOrder = "200000" . $orderId; $details = [ [ @@ -152,7 +152,7 @@ public function execute() $this->checkoutSession->getQuote()->setIsActive(true)->save(); $this->cart->getQuote()->setIsActive(true)->save(); - $orderLogs = '

Pago autorizado exitosamente con '.$oneclickTitle.'


'.json_encode($dataLog); + $orderLogs = '

Pago autorizado exitosamente con ' . $oneclickTitle . '


' . json_encode($dataLog); $payment = $order->getPayment(); $payment->setLastTransId($response->details[0]->authorizationCode); @@ -172,9 +172,7 @@ public function execute() 'message' => $message ] ); - return $resultJson->setData(['status' => 'success', 'response' => $response, '$webpayOrderData' => $webpayOrderData]); - } else { $webpayOrderData = $this->saveWebpayData( $config['CHILD_COMMERCE_CODE'], @@ -185,7 +183,7 @@ public function execute() ); $order->setStatus($orderStatusCanceled); - $message = '

Error en Inscripción con Oneclick


'.json_encode($response); + $message = '

Error en Inscripción con Oneclick


' . json_encode($response); $order->addStatusToHistory($order->getStatus(), $message); $order->cancel(); @@ -199,9 +197,8 @@ public function execute() // return $this->resultRedirectFactory->create()->setPath('checkout/cart'); return $resultJson->setData(['status' => 'error', 'response' => $response, 'flag' => 1]); } - } catch (\Exception $e) { - $message = 'Error al crear transacción: '.$e->getMessage(); + $message = 'Error al crear transacción: ' . $e->getMessage(); $this->log->logError($message); $response = ['error' => $message]; @@ -216,7 +213,6 @@ public function execute() $this->messageManager->addErrorMessage($e->getMessage()); return $resultJson->setData(['status' => 'error', 'response' => $response, 'flag' => 2]); } - } /** @@ -233,7 +229,6 @@ private function getOrder() $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); return $objectManager->create('\Magento\Sales\Model\Order')->load($orderId); - } catch (\Exception $e) { return null; } @@ -327,10 +322,10 @@ protected function getSuccessMessage($transactionResult, $oneclickTitle) • Order de Compra: {$transactionResult->details[0]->buyOrder}
- • Fecha de la Transacción: ".date('d-m-Y', strtotime($transactionResult->transactionDate)).' + • Fecha de la Transacción: " . date('d-m-Y', strtotime($transactionResult->transactionDate)) . '
- • Hora de la Transacción: '.date('H:i:s', strtotime($transactionResult->transactionDate))." + • Hora de la Transacción: ' . date('H:i:s', strtotime($transactionResult->transactionDate)) . "
• Tarjeta: **** **** **** {$transactionResult->cardNumber} @@ -355,8 +350,8 @@ protected function getRejectMessage($transactionResult, $oneclickTitle) Respuesta de la Transacción: {$this->responseCodeArray[$transactionResult->details[0]->responseCode]}
Monto: $ {$transactionResult->details[0]->amount}
Order de Compra: {$transactionResult->details[0]->buyOrder}
- Fecha de la Transacción: ".date('d-m-Y', strtotime($transactionResult->transactionDate)).'
- Hora de la Transacción: '.date('H:i:s', strtotime($transactionResult->transactionDate))."
+ Fecha de la Transacción: " . date('d-m-Y', strtotime($transactionResult->transactionDate)) . '
+ Hora de la Transacción: ' . date('H:i:s', strtotime($transactionResult->transactionDate)) . "
Tarjeta: **** **** **** {$transactionResult->cardNumber}

"; From 15b7a17555cbb6988cdb7f5f696fbefd457e62c8 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 12:07:06 -0400 Subject: [PATCH 02/18] refactor: order imports --- Controller/Transaction/AuthorizeOneclick.php | 63 ++++++++++++-------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index 5f61320..ee859af 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -2,16 +2,31 @@ namespace Transbank\Webpay\Controller\Transaction; +use Magento\Checkout\Model\Cart; +use Magento\Checkout\Model\Session; +use Transbank\Webpay\Model\Oneclick; +use Magento\Framework\App\Action\Action; +use Magento\Framework\App\Action\Context; +use Magento\Framework\App\ObjectManager; +use Magento\Quote\Model\QuoteManagement; use Transbank\Webpay\Helper\PluginLogger; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Json; +use Magento\Store\Model\StoreManagerInterface; +use Transbank\Webpay\Model\Config\ConfigProvider; +use Magento\Framework\Controller\ResultInterface; use Transbank\Webpay\Model\TransbankSdkWebpayRest; -use Transbank\Webpay\Model\Oneclick; +use Transbank\Webpay\Model\WebpayOrderDataFactory; +use Magento\Sales\Model\Order\Payment\Transaction; use Transbank\Webpay\Model\OneclickInscriptionData; +use Magento\Framework\Controller\Result\JsonFactory; +use Transbank\Webpay\Model\OneclickInscriptionDataFactory; /** * Controller for create Oneclick Inscription. */ -class AuthorizeOneclick extends \Magento\Framework\App\Action\Action +class AuthorizeOneclick extends Action { protected $configProvider; @@ -34,27 +49,27 @@ class AuthorizeOneclick extends \Magento\Framework\App\Action\Action /** * AuthorizeOneclick constructor. * - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Checkout\Model\Cart $cart - * @param \Magento\Checkout\Model\Session $checkoutSession - * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory - * @param \Magento\Quote\Model\QuoteManagement $quoteManagement - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Transbank\Webpay\Model\Config\ConfigProvider $configProvider - * @param \Transbank\Webpay\Model\OneclickInscriptionDataFactory $oneclickInscriptionDataFactory - * @param \Transbank\Webpay\Model\WebpayOrderDataFactory $webpayOrderDataFactory + * @param Context $context + * @param Cart $cart + * @param Session $checkoutSession + * @param JsonFactory $resultJsonFactory + * @param QuoteManagement $quoteManagement + * @param StoreManagerInterface $storeManager + * @param ConfigProvider $configProvider + * @param OneclickInscriptionDataFactory $oneclickInscriptionDataFactory + * @param WebpayOrderDataFactory $webpayOrderDataFactory */ public function __construct( - \Magento\Framework\App\Action\Context $context, - \Magento\Checkout\Model\Cart $cart, - \Magento\Checkout\Model\Session $checkoutSession, - \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, - \Magento\Quote\Model\QuoteManagement $quoteManagement, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Transbank\Webpay\Model\Config\ConfigProvider $configProvider, - \Transbank\Webpay\Model\OneclickInscriptionDataFactory $oneclickInscriptionDataFactory, - \Transbank\Webpay\Model\WebpayOrderDataFactory $webpayOrderDataFactory, - \Magento\Framework\Message\ManagerInterface $messageManager + Context $context, + Cart $cart, + Session $checkoutSession, + JsonFactory $resultJsonFactory, + QuoteManagement $quoteManagement, + StoreManagerInterface $storeManager, + ConfigProvider $configProvider, + OneclickInscriptionDataFactory $oneclickInscriptionDataFactory, + WebpayOrderDataFactory $webpayOrderDataFactory, + ManagerInterface $messageManager ) { parent::__construct($context); @@ -73,7 +88,7 @@ public function __construct( /** * @throws \Exception * - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface + * @return ResponseInterface|Json|ResultInterface */ public function execute() { @@ -157,7 +172,7 @@ public function execute() $payment->setLastTransId($response->details[0]->authorizationCode); $payment->setTransactionId($response->details[0]->authorizationCode); - $payment->setAdditionalInformation([\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS => (array) $response->details[0]]); + $payment->setAdditionalInformation([Transaction::RAW_DETAILS => (array) $response->details[0]]); $order->setState($orderStatusSuccess)->setStatus($orderStatusSuccess); $order->addStatusToHistory($order->getStatus(), $orderLogs); @@ -226,7 +241,7 @@ private function getOrder() return null; } - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $objectManager = ObjectManager::getInstance(); return $objectManager->create('\Magento\Sales\Model\Order')->load($orderId); } catch (\Exception $e) { From a3516a91b6a6632ccb79cb031fb01700bb6a6ac4 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 12:10:11 -0400 Subject: [PATCH 03/18] feat: add missing property messageManager --- Controller/Transaction/AuthorizeOneclick.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index ee859af..6f0989e 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -45,6 +45,7 @@ class AuthorizeOneclick extends Action protected $oneclickInscriptionDataFactory; protected $log; protected $webpayOrderDataFactory; + private $messageManager; /** * AuthorizeOneclick constructor. @@ -58,6 +59,7 @@ class AuthorizeOneclick extends Action * @param ConfigProvider $configProvider * @param OneclickInscriptionDataFactory $oneclickInscriptionDataFactory * @param WebpayOrderDataFactory $webpayOrderDataFactory + * @param ManagerInterface $messageManager */ public function __construct( Context $context, From be589da0fe3889b9cb2a74ef17bacdba9e51b218 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 12:15:24 -0400 Subject: [PATCH 04/18] refactor: change properties to private --- Controller/Transaction/AuthorizeOneclick.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index 6f0989e..e5f4b86 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -37,14 +37,14 @@ class AuthorizeOneclick extends Action '-99' => 'La transacción ha sido rechazada porque se superó la cantidad máxima de pagos diarios.', ]; - protected $cart; - protected $checkoutSession; - protected $resultJsonFactory; - protected $quoteManagement; - protected $storeManager; - protected $oneclickInscriptionDataFactory; - protected $log; - protected $webpayOrderDataFactory; + private $cart; + private $checkoutSession; + private $resultJsonFactory; + private $quoteManagement; + private $storeManager; + private $oneclickInscriptionDataFactory; + private $log; + private $webpayOrderDataFactory; private $messageManager; /** From 2434327753cfea0d4e47a6ff0af8ce8a4406758c Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 12:59:40 -0400 Subject: [PATCH 05/18] feat: add missing import --- Controller/Transaction/AuthorizeOneclick.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index e5f4b86..edc49a2 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -14,6 +14,7 @@ use Magento\Framework\Controller\Result\Json; use Magento\Store\Model\StoreManagerInterface; use Transbank\Webpay\Model\Config\ConfigProvider; +use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Controller\ResultInterface; use Transbank\Webpay\Model\TransbankSdkWebpayRest; use Transbank\Webpay\Model\WebpayOrderDataFactory; From 83f0333158cf3d044fbb3a55aac6a42e2bafd9d1 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 13:00:10 -0400 Subject: [PATCH 06/18] fix: change messageManager to protected --- Controller/Transaction/AuthorizeOneclick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index edc49a2..9dd1fdf 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -46,7 +46,7 @@ class AuthorizeOneclick extends Action private $oneclickInscriptionDataFactory; private $log; private $webpayOrderDataFactory; - private $messageManager; + protected $messageManager; /** * AuthorizeOneclick constructor. From 3dee2a3eb53c2b3c83d4cefcfbf696a68ce7911c Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 13:14:58 -0400 Subject: [PATCH 07/18] refactor: remove unused properties --- Controller/Transaction/AuthorizeOneclick.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index 9dd1fdf..7e5bf25 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -8,11 +8,9 @@ use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\App\ObjectManager; -use Magento\Quote\Model\QuoteManagement; use Transbank\Webpay\Helper\PluginLogger; use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\Result\Json; -use Magento\Store\Model\StoreManagerInterface; use Transbank\Webpay\Model\Config\ConfigProvider; use Magento\Framework\Message\ManagerInterface; use Magento\Framework\Controller\ResultInterface; @@ -41,8 +39,6 @@ class AuthorizeOneclick extends Action private $cart; private $checkoutSession; private $resultJsonFactory; - private $quoteManagement; - private $storeManager; private $oneclickInscriptionDataFactory; private $log; private $webpayOrderDataFactory; @@ -55,8 +51,6 @@ class AuthorizeOneclick extends Action * @param Cart $cart * @param Session $checkoutSession * @param JsonFactory $resultJsonFactory - * @param QuoteManagement $quoteManagement - * @param StoreManagerInterface $storeManager * @param ConfigProvider $configProvider * @param OneclickInscriptionDataFactory $oneclickInscriptionDataFactory * @param WebpayOrderDataFactory $webpayOrderDataFactory @@ -67,8 +61,6 @@ public function __construct( Cart $cart, Session $checkoutSession, JsonFactory $resultJsonFactory, - QuoteManagement $quoteManagement, - StoreManagerInterface $storeManager, ConfigProvider $configProvider, OneclickInscriptionDataFactory $oneclickInscriptionDataFactory, WebpayOrderDataFactory $webpayOrderDataFactory, @@ -79,8 +71,6 @@ public function __construct( $this->cart = $cart; $this->checkoutSession = $checkoutSession; $this->resultJsonFactory = $resultJsonFactory; - $this->quoteManagement = $quoteManagement; - $this->storeManager = $storeManager; $this->configProvider = $configProvider; $this->messageManager = $messageManager; $this->oneclickInscriptionDataFactory = $oneclickInscriptionDataFactory; From 759da3beda1a474a06fb6af4f56cf83c7ede64d9 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 13:17:03 -0400 Subject: [PATCH 08/18] refactor: return OneclickInscriptionData in getOneclickInscriptionData method --- Controller/Transaction/AuthorizeOneclick.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index 7e5bf25..d35d9c2 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -99,7 +99,9 @@ public function execute() return $resultJson->setData(['status' => 'error', 'message' => 'Error autorizando transacción', 'flag' => 0]); } - list($username, $tbkUser) = $this->getOneclickInscriptionData($inscriptionId); + $inscription = $this->getOneclickInscriptionData($inscriptionId); + $username = $inscription->getUsername(); + $tbkUser = $inscription->getTbkUser(); $config = $this->configProvider->getPluginConfigOneclick(); @@ -249,14 +251,10 @@ private function getOrder() * * @return OneclickInscriptionData */ - protected function getOneclickInscriptionData($inscriptionId) + protected function getOneclickInscriptionData($inscriptionId): OneclickInscriptionData { $oneclickInscriptionDataModel = $this->oneclickInscriptionDataFactory->create(); - $oneclickInscriptionData = $oneclickInscriptionDataModel->load($inscriptionId, 'id'); - $tbkUser = $oneclickInscriptionData->getTbkUser(); - $username = $oneclickInscriptionData->getUsername(); - - return [$username, $tbkUser]; + return $oneclickInscriptionDataModel->load($inscriptionId, 'id'); } /** From ebedf04a6c61f448a5b15d6cb15bac331965f019 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 15:35:23 -0400 Subject: [PATCH 09/18] feat: add property oneclickConfig --- Controller/Transaction/AuthorizeOneclick.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index d35d9c2..17fda52 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -43,6 +43,7 @@ class AuthorizeOneclick extends Action private $log; private $webpayOrderDataFactory; protected $messageManager; + private $oneclickConfig; /** * AuthorizeOneclick constructor. @@ -76,6 +77,7 @@ public function __construct( $this->oneclickInscriptionDataFactory = $oneclickInscriptionDataFactory; $this->webpayOrderDataFactory = $webpayOrderDataFactory; $this->log = new PluginLogger(); + $this->oneclickConfig = $configProvider->getPluginConfigOneclick(); } /** @@ -103,8 +105,6 @@ public function execute() $username = $inscription->getUsername(); $tbkUser = $inscription->getTbkUser(); - $config = $this->configProvider->getPluginConfigOneclick(); - $this->checkoutSession->restoreQuote(); $quote = $this->cart->getQuote(); @@ -119,11 +119,11 @@ public function execute() $quote->save(); - $transbankSdkWebpay = new TransbankSdkWebpayRest($config); + $transbankSdkWebpay = new TransbankSdkWebpayRest($this->oneclickConfig); $this->log->logError(json_encode($order)); - $this->log->logError($config['CHILD_COMMERCE_CODE']); + $this->log->logError($this->oneclickConfig['CHILD_COMMERCE_CODE']); $this->log->logError($orderId); $this->log->logError($grandTotal); @@ -132,7 +132,7 @@ public function execute() $details = [ [ - "commerce_code" => $config['CHILD_COMMERCE_CODE'], + "commerce_code" => $this->oneclickConfig['CHILD_COMMERCE_CODE'], "buy_order" => $childBuyOrder, "amount" => $grandTotal, "installments_number" => 1 @@ -185,7 +185,7 @@ public function execute() return $resultJson->setData(['status' => 'success', 'response' => $response, '$webpayOrderData' => $webpayOrderData]); } else { $webpayOrderData = $this->saveWebpayData( - $config['CHILD_COMMERCE_CODE'], + $this->oneclickConfig['CHILD_COMMERCE_CODE'], $grandTotal, OneclickInscriptionData::PAYMENT_STATUS_FAILED, $orderId, From c3975f924bbf8117c6fadb48e8ce8f4951d1b676 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 15:36:11 -0400 Subject: [PATCH 10/18] fix: save commerce code in transaction data --- Controller/Transaction/AuthorizeOneclick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index 17fda52..a15257f 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -283,7 +283,7 @@ protected function saveWebpayData($authorizeResponse, $amount, $payment_status, $webpayOrderData->setData([ 'buy_order' => $authorizeResponse->getBuyOrder(), 'child_buy_order' => $authorizeResponse->getDetails()[0]->getBuyOrder(), - 'commerce_code' => $authorizeResponse->getDetails()[0]->getCommerceCode(), + 'commerce_code' => $this->oneclickConfig['COMMERCE_CODE'], 'child_commerce_code' => $authorizeResponse->getDetails()[0]->getCommerceCode(), 'payment_status' => $payment_status, 'order_id' => $order_id, From def5861305b50cd5890c97f90cef8f938428d17a Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 15:36:36 -0400 Subject: [PATCH 11/18] feat: save environment in transaction data --- Controller/Transaction/AuthorizeOneclick.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index a15257f..79ce108 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -290,6 +290,7 @@ protected function saveWebpayData($authorizeResponse, $amount, $payment_status, 'quote_id' => $quote_id, 'amount' => $amount, 'metadata' => json_encode($authorizeResponse), + 'environment' => $this->oneclickConfig['ENVIRONMENT'], ]); $webpayOrderData->save(); From a22abdd80716fa659cc4ebbdcb7a272b51450993 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 15:36:57 -0400 Subject: [PATCH 12/18] feat: save product in transaction data --- Controller/Transaction/AuthorizeOneclick.php | 1 + Model/Oneclick.php | 1 + 2 files changed, 2 insertions(+) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index 79ce108..aad57d2 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -291,6 +291,7 @@ protected function saveWebpayData($authorizeResponse, $amount, $payment_status, 'amount' => $amount, 'metadata' => json_encode($authorizeResponse), 'environment' => $this->oneclickConfig['ENVIRONMENT'], + 'product' => Oneclick::PRODUCT_NAME ]); $webpayOrderData->save(); diff --git a/Model/Oneclick.php b/Model/Oneclick.php index 9602b37..0026f78 100755 --- a/Model/Oneclick.php +++ b/Model/Oneclick.php @@ -5,6 +5,7 @@ class Oneclick extends \Magento\Payment\Model\Method\AbstractMethod { const CODE = 'transbank_oneclick'; + const PRODUCT_NAME = 'webpay_oneclick'; /** * Payment code. From efee27642509b89ca6e4f5f001fc898cf9158c27 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Tue, 16 Apr 2024 16:44:32 -0400 Subject: [PATCH 13/18] refactor: remove unnecessary errors logs --- Controller/Transaction/AuthorizeOneclick.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Controller/Transaction/AuthorizeOneclick.php b/Controller/Transaction/AuthorizeOneclick.php index aad57d2..d71190d 100644 --- a/Controller/Transaction/AuthorizeOneclick.php +++ b/Controller/Transaction/AuthorizeOneclick.php @@ -121,12 +121,6 @@ public function execute() $transbankSdkWebpay = new TransbankSdkWebpayRest($this->oneclickConfig); - $this->log->logError(json_encode($order)); - - $this->log->logError($this->oneclickConfig['CHILD_COMMERCE_CODE']); - $this->log->logError($orderId); - $this->log->logError($grandTotal); - $buyOrder = "100000" . $orderId; $childBuyOrder = "200000" . $orderId; From 749fda6bc3937d6029ccf926846ce560871a5fb0 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Fri, 19 Apr 2024 13:35:55 -0400 Subject: [PATCH 14/18] fix: config_path error pattern --- Observer/SaveConfigObserver.php | 66 +++++++++++++++++++++++---------- etc/adminhtml/system.xml | 40 ++++++++++---------- etc/config.xml | 48 ++++++++++-------------- 3 files changed, 86 insertions(+), 68 deletions(-) diff --git a/Observer/SaveConfigObserver.php b/Observer/SaveConfigObserver.php index 68c12a3..273706f 100644 --- a/Observer/SaveConfigObserver.php +++ b/Observer/SaveConfigObserver.php @@ -14,10 +14,10 @@ class SaveConfigObserver implements ObserverInterface { - const TRANSBANK_WEBPAY_PAYMENT_SUCCESSFUL_STATUS = 'payment/transbank_webpay/general_parameters/payment_successful_status'; - const TRANSBANK_ONECLICK_PAYMENT_SUCCESSFUL_STATUS = 'payment/transbank_oneclick/general_parameters/payment_successful_status'; - const TRANSBANK_ONECLICK_INVOICE_SETTINGS = 'payment/transbank_oneclick/general_parameters/invoice_settings'; - const TRANSBANK_WEBPAY_INVOICE_SETTINGS = 'payment/transbank_webpay/general_parameters/invoice_settings'; + const TRANSBANK_WEBPAY_PAYMENT_SUCCESSFUL_STATUS = 'payment/transbank_webpay/payment_successful_status'; + const TRANSBANK_ONECLICK_PAYMENT_SUCCESSFUL_STATUS = 'payment/transbank_oneclick/payment_successful_status'; + const TRANSBANK_ONECLICK_INVOICE_SETTINGS = 'payment/transbank_oneclick/invoice_settings'; + const TRANSBANK_WEBPAY_INVOICE_SETTINGS = 'payment/transbank_webpay/invoice_settings'; protected $request; protected $configWriter; @@ -26,13 +26,13 @@ class SaveConfigObserver implements ObserverInterface protected ScopeConfigInterface $scopeConfig; protected StoreManagerInterface $storeManager; - public function __construct ( + public function __construct( LoggerInterface $logger, RequestInterface $request, WriterInterface $configWriter, ScopeConfigInterface $scopeConfig, - StoreManagerInterface $storeManager) - { + StoreManagerInterface $storeManager + ) { $this->request = $request; $this->_logger = $logger; $this->configWriter = $configWriter; @@ -46,13 +46,28 @@ public function execute(EventObserver $observer) $websiteId = $this->getWebsiteId(); $params = $this->request->getParam('groups'); - - if( isset($params['transbank_webpay']['groups']['general_parameters']['fields']['payment_successful_status']['value']) ){ - $orderStatus = $params['transbank_webpay']['groups']['general_parameters']['fields']['payment_successful_status']['value']; - } elseif (empty($this->scopeConfig->getValue(self::TRANSBANK_WEBPAY_PAYMENT_SUCCESSFUL_STATUS,ScopeInterface::SCOPE_WEBSITE, $websiteId ))) { - $orderStatus = $this->scopeConfig->getValue(self::TRANSBANK_WEBPAY_PAYMENT_SUCCESSFUL_STATUS,ScopeConfigInterface::SCOPE_TYPE_DEFAULT); + $transbankParams = $params['transbank']['groups']; + $webpayFields = $transbankParams['transbank_webpay']['fields']; + $oneclickFields = $transbankParams['transbank_oneclick']['fields']; + + if (isset($webpayFields['payment_successful_status']['value'])) { + $orderStatus = $webpayFields['payment_successful_status']['value']; + } elseif (empty($this->scopeConfig->getValue( + self::TRANSBANK_WEBPAY_PAYMENT_SUCCESSFUL_STATUS, + ScopeInterface::SCOPE_WEBSITE, + $websiteId + ))) { + $orderStatus = $this->scopeConfig->getValue( + self::TRANSBANK_WEBPAY_PAYMENT_SUCCESSFUL_STATUS, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + $websiteId + ); } else { - $orderStatus = $this->scopeConfig->getValue(self::TRANSBANK_WEBPAY_PAYMENT_SUCCESSFUL_STATUS,ScopeInterface::SCOPE_WEBSITE, $websiteId ); + $orderStatus = $this->scopeConfig->getValue( + self::TRANSBANK_WEBPAY_PAYMENT_SUCCESSFUL_STATUS, + ScopeInterface::SCOPE_WEBSITE, + $websiteId + ); } if ($orderStatus !== 'processing') { @@ -60,12 +75,24 @@ public function execute(EventObserver $observer) $this->configWriter->save(self::TRANSBANK_WEBPAY_INVOICE_SETTINGS, $value); } - if(isset($params['transbank_oneclick']['groups']['general_parameters']['fields']['payment_successful_status']['value']) ) { - $oneclickOrderStatus = $params['transbank_oneclick']['groups']['general_parameters']['fields']['payment_successful_status']['value']; - }elseif (empty($this->scopeConfig->getValue(self::TRANSBANK_ONECLICK_PAYMENT_SUCCESSFUL_STATUS,ScopeInterface::SCOPE_WEBSITE, $websiteId))) { - $oneclickOrderStatus = $this->scopeConfig->getValue(self::TRANSBANK_ONECLICK_PAYMENT_SUCCESSFUL_STATUS,ScopeConfigInterface::SCOPE_TYPE_DEFAULT); - }else { - $oneclickOrderStatus = $this->scopeConfig->getValue(self::TRANSBANK_ONECLICK_PAYMENT_SUCCESSFUL_STATUS,ScopeInterface::SCOPE_WEBSITE, $websiteId); + if (isset($oneclickFields['payment_successful_status']['value'])) { + $oneclickOrderStatus = $oneclickFields['payment_successful_status']['value']; + } elseif (empty($this->scopeConfig->getValue( + self::TRANSBANK_ONECLICK_PAYMENT_SUCCESSFUL_STATUS, + ScopeInterface::SCOPE_WEBSITE, + $websiteId + ))) { + $oneclickOrderStatus = $this->scopeConfig->getValue( + self::TRANSBANK_ONECLICK_PAYMENT_SUCCESSFUL_STATUS, + ScopeConfigInterface::SCOPE_TYPE_DEFAULT, + $websiteId + ); + } else { + $oneclickOrderStatus = $this->scopeConfig->getValue( + self::TRANSBANK_ONECLICK_PAYMENT_SUCCESSFUL_STATUS, + ScopeInterface::SCOPE_WEBSITE, + $websiteId + ); } if ($oneclickOrderStatus !== 'processing') { @@ -88,4 +115,3 @@ public function getWebsiteId(): int return $websiteId; } } - diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index d705629..7507c5f 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -22,54 +22,54 @@ Transbank\Webpay\Model\Config\Environment - payment/transbank_webpay/security/environment + payment/transbank_webpay/environment Identificador único del comercio, asegurate de que comience con 5970 - payment/transbank_webpay/security/commerce_code + payment/transbank_webpay/commerce_code Llave secreta utilizada para conectarse a la API ¡asegúrate de no compartir su contenido! - payment/transbank_webpay/security/api_key + payment/transbank_webpay/api_key Transbank\Webpay\Model\Config\OrderStatus - payment/transbank_webpay/general_parameters/payment_successful_status + payment/transbank_webpay/payment_successful_status Transbank\Webpay\Model\Config\OrderStatus - payment/transbank_webpay/general_parameters/payment_error_status + payment/transbank_webpay/payment_error_status Magento\Sales\Model\Config\Source\Order\Status\NewStatus - payment/transbank_webpay/general_parameters/new_order_status + payment/transbank_webpay/new_order_status validate-number Posición en la que aparecerá la opción de pago, debe ser menor a otros medios de pago para que aparezca primero - payment/transbank_webpay/general_parameters/sort_order + payment/transbank_webpay/sort_order Transbank\Webpay\Model\Config\ConfigEmail Al seleccionar 'Default' el correo electrónico se enviará al crear el pedido y no al procesar la compra - payment/transbank_webpay/general_parameters/new_email_order + payment/transbank_webpay/new_email_order @@ -77,7 +77,7 @@ Transbank\Webpay\Model\Config\ConfigInvoice Para modificar esta opción es necesario que el estado de Pago Exitoso sea "Processing" Transbank\Webpay\Helper\Disable - payment/transbank_webpay/general_parameters/invoice_settings + payment/transbank_webpay/invoice_settings @@ -99,21 +99,21 @@ Transbank\Webpay\Model\Config\Environment - payment/transbank_oneclick/security/environment + payment/transbank_oneclick/environment Identificador único del comercio, asegurate de que comience con 5970 - payment/transbank_oneclick/security/commerce_code + payment/transbank_oneclick/commerce_code Identificador único del comercio asignado por Transbank para la tienda perteneciente al mall, asegurate de que comience con 5970 - payment/transbank_oneclick/security/child_commerce_code + payment/transbank_oneclick/child_commerce_code @@ -126,14 +126,14 @@ fraude o contracargo. Independiente del monto que definas en esta configuración, en tu contrato de Oneclick, existe un límite de cantidad de transacciones diarias, un monto máximo por transacción y monto acumulado diario. Si un cliente supera ese límite, su transacción será rechazada. - payment/transbank_oneclick/security/transaction_max_amount + payment/transbank_oneclick/transaction_max_amount Llave secreta utilizada para conectarse a la API ¡asegúrate de no compartir su contenido! - payment/transbank_oneclick/security/api_key + payment/transbank_oneclick/api_key @@ -141,33 +141,33 @@ Transbank\Webpay\Model\Config\OrderStatus Para reversar o anular una transacción el estado de pago exitoso debe de ser Processing. - payment/transbank_oneclick/general_parameters/payment_successful_status + payment/transbank_oneclick/payment_successful_status Transbank\Webpay\Model\Config\OrderStatus - payment/transbank_oneclick/general_parameters/payment_error_status + payment/transbank_oneclick/payment_error_status Magento\Sales\Model\Config\Source\Order\Status\NewStatus - payment/transbank_oneclick/general_parameters/new_order_status + payment/transbank_oneclick/new_order_status validate-number Posición en la que aparecerá la opción de pago, debe ser menor a otros medios de pago para que aparezca primero - payment/transbank_oneclick/general_parameters/sort_order + payment/transbank_oneclick/sort_order Transbank\Webpay\Model\Config\ConfigEmail Al seleccionar 'Default' el correo electrónico se enviará al crear el pedido y no al procesar la compra - payment/transbank_oneclick/general_parameters/new_email_order + payment/transbank_oneclick/new_email_order @@ -175,7 +175,7 @@ Transbank\Webpay\Model\Config\ConfigInvoice Para modificar esta opción es necesario que el estado de Pago Exitoso sea "Processing" Transbank\Webpay\Helper\Disable - payment/transbank_oneclick/general_parameters/invoice_settings + payment/transbank_oneclick/invoice_settings diff --git a/etc/config.xml b/etc/config.xml index 574af18..652b8e1 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -6,39 +6,31 @@ Transbank\Webpay\Model\Webpay Webpay Plus 1 - - complete - canceled - pending - 0 - default - default - - - TEST - 597055555532 - 579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C - + complete + canceled + pending + 0 + default + default + TEST + 597055555532 + 579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C Transbank\Webpay\Model\Oneclick Oneclick 1 - - complete - canceled - pending - 1 - default - default - - - TEST - 597055555541 - 597055555542 - 0 - 579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C - + complete + canceled + pending + 1 + default + default + TEST + 597055555541 + 597055555542 + 0 + 579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C From bca3ac9e5802d24104fb4eb9b51810e414b66e36 Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Fri, 19 Apr 2024 13:37:00 -0400 Subject: [PATCH 15/18] feat: add UpgradeData class to update config data --- Setup/UpgradeData.php | 78 +++++++++++++++++++++++++++++++++++++++++++ etc/module.xml | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 Setup/UpgradeData.php diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php new file mode 100644 index 0000000..873b8ef --- /dev/null +++ b/Setup/UpgradeData.php @@ -0,0 +1,78 @@ +configInterface = $configInterface; + $this->scopeConfigInterface = $scopeConfigInterface; + } + + public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) + { + $setup->startSetup(); + + if (version_compare($context->getVersion(), '2.2.1', '<')) { + $this->updateConfigData(); + } + + $setup->endSetup(); + } + + private function updateConfigData() + { + $newConfigValues = [ + 'payment/transbank_webpay/general_parameters/payment_successful_status' => + 'payment/transbank_webpay/payment_successful_status', + 'payment/transbank_webpay/general_parameters/payment_error_status' => + 'payment/transbank_webpay/payment_error_status', + 'payment/transbank_webpay/general_parameters/new_order_status' => + 'payment/transbank_webpay/new_order_status', + 'payment/transbank_webpay/general_parameters/invoice_settings' => + 'payment/transbank_webpay/invoice_settings', + 'payment/transbank_webpay/general_parameters/sort_order' => 'payment/transbank_webpay/sort_order', + 'payment/transbank_webpay/general_parameters/new_email_order' => + 'payment/transbank_webpay/new_email_order', + 'payment/transbank_webpay/security/environment' => 'payment/transbank_webpay/environment', + 'payment/transbank_webpay/security/commerce_code' => 'payment/transbank_webpay/commerce_code', + 'payment/transbank_webpay/security/api_key' => 'payment/transbank_webpay/api_key', + 'payment/transbank_oneclick/general_parameters/payment_successful_status' => + 'payment/transbank_oneclick/payment_successful_status', + 'payment/transbank_oneclick/general_parameters/payment_error_status' => + 'payment/transbank_oneclick/payment_error_status', + 'payment/transbank_oneclick/general_parameters/invoice_settings' => + 'payment/transbank_oneclick/invoice_settings', + 'payment/transbank_oneclick/general_parameters/new_order_status' => + 'payment/transbank_oneclick/new_order_status', + 'payment/transbank_oneclick/general_parameters/sort_order' => 'payment/transbank_oneclick/sort_order', + 'payment/transbank_oneclick/general_parameters/new_email_order' => + 'payment/transbank_oneclick/new_email_order', + 'payment/transbank_oneclick/security/environment' => 'payment/transbank_oneclick/environment', + 'payment/transbank_oneclick/security/commerce_code' => 'payment/transbank_oneclick/commerce_code', + 'payment/transbank_oneclick/security/child_commerce_code' => + 'payment/transbank_oneclick/child_commerce_code', + 'payment/transbank_oneclick/security/transaction_max_amount' => + 'payment/transbank_oneclick/transaction_max_amount', + 'payment/transbank_oneclick/security/api_key' => 'payment/transbank_oneclick/api_key', + ]; + + foreach ($newConfigValues as $key => $value) { + $currentConfigValue = $this->scopeConfigInterface->getValue($key); + $this->configInterface->deleteConfig($key); + $this->configInterface->saveConfig($value, $currentConfigValue); + } + } +} diff --git a/etc/module.xml b/etc/module.xml index 95469cd..9d5188d 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + From 9ee31fa7714cca24c4bf35f85a55da1dbeec526f Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Fri, 19 Apr 2024 13:45:37 -0400 Subject: [PATCH 16/18] fix: update config path in ConfigProvider class --- Model/Config/ConfigProvider.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Model/Config/ConfigProvider.php b/Model/Config/ConfigProvider.php index 4324c99..8e2e0d5 100644 --- a/Model/Config/ConfigProvider.php +++ b/Model/Config/ConfigProvider.php @@ -4,11 +4,11 @@ class ConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface { - const SECURITY_CONFIGS_ROUTE = 'payment/transbank_webpay/security/'; - const ORDER_CONFIGS_ROUTE = 'payment/transbank_webpay/general_parameters/'; - - const SECURITY_CONFIGS_ROUTE_ONECLICK = 'payment/transbank_oneclick/security/'; - const ORDER_CONFIGS_ROUTE_ONECLICK = 'payment/transbank_oneclick/general_parameters/'; + const SECURITY_CONFIGS_ROUTE = 'payment/transbank_webpay/'; + const ORDER_CONFIGS_ROUTE = 'payment/transbank_webpay/'; + + const SECURITY_CONFIGS_ROUTE_ONECLICK = 'payment/transbank_oneclick/'; + const ORDER_CONFIGS_ROUTE_ONECLICK = 'payment/transbank_oneclick/'; const CC_VAULT_CODE = 'transbank_oneclick_cc_vault'; From 3a79303ff155f6bcb10647b8f05b62bec1ed366e Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Mon, 22 Apr 2024 11:48:52 -0400 Subject: [PATCH 17/18] docs: update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e25892..d8d3b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ Todos los cambios notables a este proyecto serán documentados en este archivo. El formato está basado en [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) y este proyecto adhiere a [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +# [2.2.1] - 2024-04-22 +## Fixed +- Se corrige el valor de path_config para que sea aceptado desde las versiones 2.4.6 en adelante. +- Se corrige el test de conexión en entorno de producción. +- Se corrige el registro de los datos de la transacción en la base de datos para Oneclick. + # [2.2.0] - 2024-04-12 ## Fixed - Se corrige el retorno de una inscripción Oneclick cuando es rechazada por el usuario. From 2bfa5c011ca8b1f6c76b6e83dc2d7cd88fed937f Mon Sep 17 00:00:00 2001 From: Mauricio Astudillo Toledo Date: Mon, 22 Apr 2024 11:50:51 -0400 Subject: [PATCH 18/18] feat: update php max version supported --- Model/HealthCheck.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/HealthCheck.php b/Model/HealthCheck.php index 5947174..62f99f4 100755 --- a/Model/HealthCheck.php +++ b/Model/HealthCheck.php @@ -99,7 +99,7 @@ public function __construct($config) */ private function getValidatePHP() { - if (version_compare(phpversion(), '7.2.1', '<=') && version_compare(phpversion(), '5.5.0', '>=')) { + if (version_compare(phpversion(), '7.4.33', '<=') && version_compare(phpversion(), '5.5.0', '>=')) { $this->versionInfo = [ 'status' => 'OK', 'version' => phpversion(),