Skip to content

Commit

Permalink
Merge pull request #58 from TransbankDevelopers/chore/prepare-release…
Browse files Browse the repository at this point in the history
…-2.1.1

Prepare Release 2.1.1
  • Loading branch information
jgarciajovel authored Jan 30, 2023
2 parents e609d74 + 574756c commit 58d21e0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ 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.1.1] - 2023-01-30
## Added
- Se agrega un servicio para recolectar datos que nos permitira darle mayor seguimiento a las versiones del plugin y las versiones de Magento mas usadas.

# [2.1.0] - 2022-12-14
## Added
- Capacidad para hacer reversas en Oneclick si el **Estado de Pago Exitoso** se cambia a proccesing.
Expand Down
78 changes: 67 additions & 11 deletions Observer/SaveConfigObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Transbank\Webpay\Observer;

use GuzzleHttp\Client;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\App\RequestInterface;
Expand All @@ -25,23 +26,78 @@ public function __construct (

public function execute(EventObserver $observer)
{
$this->_logger->info('Invoice Observer');
try {

$params = $this->request->getParam('groups');
$orderStatus = $params['transbank_webpay']['groups']['general_parameters']['fields']['payment_successful_status']['value'];
$params = $this->request->getParam('groups');
$orderStatus = $params['transbank_webpay']['groups']['general_parameters']['fields']['payment_successful_status']['value'];

if ($orderStatus !== 'processing') {
$value = 'default';
$this->configWriter->save('payment/transbank_webpay/general_parameters/invoice_settings', $value);
$this->sendMetrics($params);

if ($orderStatus !== 'processing') {
$value = 'default';
$this->configWriter->save('payment/transbank_webpay/general_parameters/invoice_settings', $value);
}

$oneclickOrderStatus = isset($params['transbank_oneclick']['groups']['general_parameters']['fields']['payment_successful_status']['value']) ? : 0;

if ($oneclickOrderStatus !== 'processing') {
$value = 'default';
$this->configWriter->save('payment/transbank_oneclick/general_parameters/invoice_settings', $value);
}

return $this;
} catch (\ErrorException $e) {
$this->_logger->critical($e);
}
}

public function sendMetrics($params) {
try {
$this->_logger->info('Sending Metric');

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface');
$moduleInfo = $objectManager->get('Magento\Framework\Module\ModuleList')->getOne('Transbank_Webpay'); // SR_Learning is module name
$pluginVersion = $moduleInfo['setup_version'];

$webpayEnviroment = $params['transbank_webpay']['groups']['security']['fields']['environment']['value'];
$webpayCommerceCode = $params['transbank_webpay']['groups']['security']['fields']['commerce_code']['value'];

$oneclickEnviroment = $params['transbank_oneclick']['groups']['security']['fields']['environment']['value'];
$oneclickCommerceCode = $params['transbank_oneclick']['groups']['security']['fields']['commerce_code']['value'];

$webpayPayload = [
'commerceCode' => 1,
'plugin' => 'magento',
'environment' => $webpayEnviroment,
'product' => 'webpay',
'pluginVersion' => $pluginVersion,
'commerceCode' => $webpayCommerceCode,
'phpVersion' => phpversion(),
'metadata' => json_encode(['magentoVersion' => $productMetadata->getVersion()]),
];

$oneclickPayload = [
'commerceCode' => 1,
'plugin' => 'magento',
'environment' => $oneclickEnviroment,
'product' => 'oneclick',
'pluginVersion' => $pluginVersion,
'commerceCode' => $oneclickCommerceCode,
'phpVersion' => phpversion(),
'metadata' => json_encode(['magentoVersion' => $productMetadata->getVersion()]),
];

$client = new Client();

$oneclickOrderStatus = $params['transbank_oneclick']['groups']['general_parameters']['fields']['payment_successful_status']['value'];
$client->request('POST', 'https://tbk-app-y8unz.ondigitalocean.app/records/newRecord', ['form_params' => $webpayPayload]);

$client->request('POST', 'https://tbk-app-y8unz.ondigitalocean.app/records/newRecord', ['form_params' => $oneclickPayload]);

if ($oneclickOrderStatus !== 'processing') {
$value = 'default';
$this->configWriter->save('payment/transbank_oneclick/general_parameters/invoice_settings', $value);
$this->_logger->info('Saved');
} catch (\ErrorException $e) {
$this->_logger->critical($e);
}

return $this;
}
}
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Transbank_Webpay" setup_version="2.1.0">
<module name="Transbank_Webpay" setup_version="2.1.1">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down

0 comments on commit 58d21e0

Please sign in to comment.