Skip to content

Commit

Permalink
Merge pull request #100 from TransbankDevelopers/chore/prepare-releas…
Browse files Browse the repository at this point in the history
…e-2.2.1

chore: prepare release 2.2.1
  • Loading branch information
mastudillot authored Apr 22, 2024
2 parents 5555c83 + 2bfa5c0 commit eb7b835
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 142 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
131 changes: 64 additions & 67 deletions Controller/Transaction/AuthorizeOneclick.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

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 Transbank\Webpay\Helper\PluginLogger;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Json;
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\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;

Expand All @@ -22,58 +36,54 @@ class AuthorizeOneclick extends \Magento\Framework\App\Action\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 $oneclickInscriptionDataFactory;
private $log;
private $webpayOrderDataFactory;
protected $messageManager;
private $oneclickConfig;

/**
* 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 ConfigProvider $configProvider
* @param OneclickInscriptionDataFactory $oneclickInscriptionDataFactory
* @param WebpayOrderDataFactory $webpayOrderDataFactory
* @param ManagerInterface $messageManager
*/
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,
ConfigProvider $configProvider,
OneclickInscriptionDataFactory $oneclickInscriptionDataFactory,
WebpayOrderDataFactory $webpayOrderDataFactory,
ManagerInterface $messageManager
) {
parent::__construct($context);

$this->cart = $cart;
$this->checkoutSession = $checkoutSession;
$this->resultJsonFactory = $resultJsonFactory;
$this->quoteManagement = $quoteManagement;
$this->storeManager = $storeManager;
$this->configProvider = $configProvider;
$this->messageManager = $messageManager;
$this->oneclickInscriptionDataFactory = $oneclickInscriptionDataFactory;
$this->webpayOrderDataFactory = $webpayOrderDataFactory;
$this->log = new PluginLogger();
$this->oneclickConfig = $configProvider->getPluginConfigOneclick();
}

/**
* @throws \Exception
*
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface
* @return ResponseInterface|Json|ResultInterface
*/
public function execute()
{
Expand All @@ -91,9 +101,9 @@ public function execute()
return $resultJson->setData(['status' => 'error', 'message' => 'Error autorizando transacción', 'flag' => 0]);
}

list($username, $tbkUser) = $this->getOneclickInscriptionData($inscriptionId);

$config = $this->configProvider->getPluginConfigOneclick();
$inscription = $this->getOneclickInscriptionData($inscriptionId);
$username = $inscription->getUsername();
$tbkUser = $inscription->getTbkUser();

$this->checkoutSession->restoreQuote();

Expand All @@ -109,20 +119,14 @@ 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($orderId);
$this->log->logError($grandTotal);

$buyOrder = "100000".$orderId;
$childBuyOrder = "200000".$orderId;
$buyOrder = "100000" . $orderId;
$childBuyOrder = "200000" . $orderId;

$details = [
[
"commerce_code" => $config['CHILD_COMMERCE_CODE'],
"commerce_code" => $this->oneclickConfig['CHILD_COMMERCE_CODE'],
"buy_order" => $childBuyOrder,
"amount" => $grandTotal,
"installments_number" => 1
Expand Down Expand Up @@ -152,12 +156,12 @@ public function execute()
$this->checkoutSession->getQuote()->setIsActive(true)->save();
$this->cart->getQuote()->setIsActive(true)->save();

$orderLogs = '<h3>Pago autorizado exitosamente con '.$oneclickTitle.'</h3><br>'.json_encode($dataLog);
$orderLogs = '<h3>Pago autorizado exitosamente con ' . $oneclickTitle . '</h3><br>' . json_encode($dataLog);
$payment = $order->getPayment();

$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);
Expand All @@ -172,20 +176,18 @@ public function execute()
'message' => $message
]
);

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,
$quoteId,
);

$order->setStatus($orderStatusCanceled);
$message = '<h3>Error en Inscripción con Oneclick</h3><br>'.json_encode($response);
$message = '<h3>Error en Inscripción con Oneclick</h3><br>' . json_encode($response);

$order->addStatusToHistory($order->getStatus(), $message);
$order->cancel();
Expand All @@ -199,9 +201,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];
Expand All @@ -216,7 +217,6 @@ public function execute()
$this->messageManager->addErrorMessage($e->getMessage());
return $resultJson->setData(['status' => 'error', 'response' => $response, 'flag' => 2]);
}

}

/**
Expand All @@ -230,10 +230,9 @@ 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) {
return null;
}
Expand All @@ -246,14 +245,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');
}

/**
Expand Down Expand Up @@ -282,13 +277,15 @@ 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,
'quote_id' => $quote_id,
'amount' => $amount,
'metadata' => json_encode($authorizeResponse),
'environment' => $this->oneclickConfig['ENVIRONMENT'],
'product' => Oneclick::PRODUCT_NAME
]);
$webpayOrderData->save();

Expand Down Expand Up @@ -327,10 +324,10 @@ protected function getSuccessMessage($transactionResult, $oneclickTitle)
• Order de Compra: <b>{$transactionResult->details[0]->buyOrder}</b>
</div>
<div>
• Fecha de la Transacci&oacute;n: <b>".date('d-m-Y', strtotime($transactionResult->transactionDate)).'</b>
• Fecha de la Transacci&oacute;n: <b>" . date('d-m-Y', strtotime($transactionResult->transactionDate)) . '</b>
</div>
<div>
• Hora de la Transacci&oacute;n: <b>'.date('H:i:s', strtotime($transactionResult->transactionDate))."</b>
• Hora de la Transacci&oacute;n: <b>' . date('H:i:s', strtotime($transactionResult->transactionDate)) . "</b>
</div>
<div>
• Tarjeta: <b>**** **** **** {$transactionResult->cardNumber}</b>
Expand All @@ -355,8 +352,8 @@ protected function getRejectMessage($transactionResult, $oneclickTitle)
<b>Respuesta de la Transacci&oacute;n: </b>{$this->responseCodeArray[$transactionResult->details[0]->responseCode]}<br>
<b>Monto:</b> $ {$transactionResult->details[0]->amount}<br>
<b>Order de Compra: </b> {$transactionResult->details[0]->buyOrder}<br>
<b>Fecha de la Transacci&oacute;n: </b>".date('d-m-Y', strtotime($transactionResult->transactionDate)).'<br>
<b>Hora de la Transacci&oacute;n: </b>'.date('H:i:s', strtotime($transactionResult->transactionDate))."<br>
<b>Fecha de la Transacci&oacute;n: </b>" . date('d-m-Y', strtotime($transactionResult->transactionDate)) . '<br>
<b>Hora de la Transacci&oacute;n: </b>' . date('H:i:s', strtotime($transactionResult->transactionDate)) . "<br>
<b>Tarjeta: </b>**** **** **** {$transactionResult->cardNumber}<br>
</p>";

Expand Down
10 changes: 5 additions & 5 deletions Model/Config/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion Model/HealthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions Model/Oneclick.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class Oneclick extends \Magento\Payment\Model\Method\AbstractMethod
{
const CODE = 'transbank_oneclick';
const PRODUCT_NAME = 'webpay_oneclick';

/**
* Payment code.
Expand Down
Loading

0 comments on commit eb7b835

Please sign in to comment.