Skip to content

Commit

Permalink
v3.1.2: new version commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Resende | Gerencianet committed Jun 11, 2019
1 parent 6ea3d06 commit 7182800
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 56 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# v3.1.2

* Fix: Realiza verificação da versão do TLS do servidor.

# v3.1.1

* Fix: Atualização no link do boleto gerado, agora o link encaminha para um PDF.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Módulo de Integração Gerencianet para OpenCart-3.x - Versão 3.1.1 (BETA) #
# Módulo de Integração Gerencianet para OpenCart-3.x - Versão 3.1.2 (BETA) #

:warning: **Este módulo é compatível apenas com as versões do OpenCart superior a 3.0.2.0. Caso você tenha uma versão inferior do Opencart, verifique a versão correta do módulo a ser baixado na sessão [Versões](#versões)**

Expand Down
Binary file modified auto/gerencianet.ocmod.zip
Binary file not shown.
133 changes: 99 additions & 34 deletions manual/upload/admin/controller/extension/payment/gerencianet.php
Original file line number Diff line number Diff line change
@@ -1,65 +1,67 @@
<?php
class ControllerExtensionPaymentGerencianet extends Controller {
class ControllerExtensionPaymentGerencianet extends Controller
{
private $error = array();

public function index() {

public function index()
{
$this->load->language('extension/payment/gerencianet');
$this->document->setTitle('Gerencianet');
$this->load->model('setting/setting');
$gerencianetModuleVersion = "v3.1.1";
$gerencianetModuleVersion = "v3.1.2";

if (($this->request->server['REQUEST_METHOD'] == 'POST')) {

$incorrectsFields = "";
if ($this->request->post['payment_gerencianet_status']=="0") {
if ($this->request->post['payment_gerencianet_status'] == "0") {
$incorrectsFields .= $this->language->get('gn_entry_incorrect_field_status');
}

if ($this->request->post['payment_gerencianet_client_id_development']=="" || $this->request->post['payment_gerencianet_client_secret_development']=="") {
if ($incorrectsFields!="") {
if ($this->request->post['payment_gerencianet_client_id_development'] == "" || $this->request->post['payment_gerencianet_client_secret_development'] == "") {
if ($incorrectsFields != "") {
$incorrectsFields .= "; ";
}
$incorrectsFields .= $this->language->get('gn_entry_incorrect_field_development_keys');
}

if ($this->request->post['payment_gerencianet_client_id_production']=="" || $this->request->post['payment_gerencianet_client_secret_production']=="") {
if ($incorrectsFields!="") {
if ($this->request->post['payment_gerencianet_client_id_production'] == "" || $this->request->post['payment_gerencianet_client_secret_production'] == "") {
if ($incorrectsFields != "") {
$incorrectsFields .= "; ";
}
$incorrectsFields .= $this->language->get('gn_entry_incorrect_field_production_keys');
}

if ($this->request->post['payment_gerencianet_payee_code']=="") {
if ($incorrectsFields!="") {
if ($this->request->post['payment_gerencianet_payee_code'] == "") {
if ($incorrectsFields != "") {
$incorrectsFields .= "; ";
}
$incorrectsFields .= $this->language->get('gn_entry_incorrect_field_payee_code');
}

$payment_option = false;
if (isset($this->request->post['payment_gerencianet_payment_option_card'])) {
if ($this->request->post['payment_gerencianet_payment_option_card']=="1" ) {
$payment_option=true;
if ($this->request->post['payment_gerencianet_payment_option_card'] == "1") {
$payment_option = true;
}
} else {
$this->request->post['payment_gerencianet_payment_option_card'] = "0";
}
if (isset($this->request->post['payment_gerencianet_payment_option_billet'])) {
if ($this->request->post['payment_gerencianet_payment_option_billet']=="1" ) {
$payment_option=true;
if ($this->request->post['payment_gerencianet_payment_option_billet'] == "1") {
$payment_option = true;
}
} else {
$this->request->post['payment_gerencianet_payment_option_billet'] = "0";
}
if (!$payment_option) {
if ($incorrectsFields!="") {
if ($incorrectsFields != "") {
$incorrectsFields .= "; ";
}
$incorrectsFields .= $this->language->get('gn_entry_no_payment_selected');
}

if (isset($this->request->post['payment_gerencianet_osc'])) {
if ($this->request->post['payment_gerencianet_osc']!="1" ) {
if ($this->request->post['payment_gerencianet_osc'] != "1") {
$this->request->post['payment_gerencianet_osc'] = "0";
}
} else {
Expand All @@ -71,20 +73,83 @@ public function index() {
$this->request->post['payment_gerencianet_billet_instruction_line_3'] = substr($this->request->post['payment_gerencianet_billet_instruction_line_3'], 0, 90);
$this->request->post['payment_gerencianet_billet_instruction_line_4'] = substr($this->request->post['payment_gerencianet_billet_instruction_line_4'], 0, 90);

if ($incorrectsFields=="") {
if ($incorrectsFields == "") {
$this->session->data['success'] = $this->language->get('gn_config_saved');
} else {
$this->session->data['success'] = $this->language->get('gn_config_saved_not_on')."<b>".$incorrectsFields."</b>";
$this->session->data['success'] = $this->language->get('gn_config_saved_not_on') . "<b>" . $incorrectsFields . "</b>";
$this->request->post['payment_gerencianet_status'] = "0";
}

$this->model_setting_setting->editSetting('payment_gerencianet', $this->request->post);
$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true));
}

$this->document->addScript('../catalog/view/javascript/jquery/jquery.mask.min.js');
$this->document->addStyle('../catalog/view/javascript/gerencianet/style.css');


$ch = curl_init();
$options = array(
CURLOPT_URL => "https://tls.testegerencianet.com.br",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => false, // don't return headers
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 5, // time-out on connect
CURLOPT_TIMEOUT => 5, // time-out on response
);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$info = curl_getinfo($ch);

if (($info['http_code'] !== 200) && ($content !== 'Gerencianet_Connection_TLS1.2_OK!')) {
$this->tlsOk = false;
$this->error['warning'] = $this->language->get('gn_config_check_tls');
} else {
$this->tlsOk = true;
if (isset($_COOKIE["gnTestTlsLog"])) {
setcookie("gnTestTlsLog", false, time() - 1);
}
}
curl_close($ch);

if (!$this->tlsOk && !isset($_COOKIE["gnTestTlsLog"])) {
setcookie("gnTestTlsLog", true);
// register log
$account = $this->config->get('payment_gerencianet_payee_code');
$ip = $_SERVER['SERVER_ADDR'];
$modulo = 'opencart';
$control = md5($account . $ip . 'modulologs-tls');
$dataPost = array(
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
'modulo' => $modulo,
);
$post = array(
'control' => $control,
'account' => $account,
'ip' => $ip,
'origin' => 'modulo',
'data' => json_encode($dataPost)
);
$ch1 = curl_init();
$options1 = array(
CURLOPT_URL => "https://fortunus.gerencianet.com.br/logs/tls",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => true, // don't return headers
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 5, // time-out on connect
CURLOPT_TIMEOUT => 5, // time-out on response
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($post),
);
curl_setopt_array($ch1, $options1);
$content1 = curl_exec($ch1);
$info1 = curl_getinfo($ch1);
curl_close($ch1);
}

if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
Expand All @@ -105,9 +170,9 @@ public function index() {
);

$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_payment'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)
);
'text' => $this->language->get('text_payment'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)
);

$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
Expand All @@ -123,7 +188,7 @@ public function index() {
} else {
$data['payment_gerencianet_sandbox'] = $this->config->get('payment_gerencianet_sandbox');
}

if (isset($this->request->post['payment_gerencianet_payment_options'])) {
$data['payment_gerencianet_payment_options'] = $this->request->post['payment_gerencianet_payment_options'];
} else {
Expand All @@ -133,7 +198,7 @@ public function index() {
if (isset($this->request->post['payment_gerencianet_billet_days_to_expire'])) {
$data['payment_gerencianet_billet_days_to_expire'] = $this->request->post['payment_gerencianet_billet_days_to_expire'];
} else {
if (intval($this->config->get('payment_gerencianet_billet_days_to_expire'))=="") {
if (intval($this->config->get('payment_gerencianet_billet_days_to_expire')) == "") {
$data['payment_gerencianet_billet_days_to_expire'] = "5";
} else {
$data['payment_gerencianet_billet_days_to_expire'] = $this->config->get('payment_gerencianet_billet_days_to_expire');
Expand All @@ -145,7 +210,7 @@ public function index() {
} else {
$data['payment_gerencianet_client_id_development'] = $this->config->get('payment_gerencianet_client_id_development');
}

if (isset($this->request->post['payment_gerencianet_client_secret_development'])) {
$data['payment_gerencianet_client_secret_development'] = $this->request->post['payment_gerencianet_client_secret_development'];
} else {
Expand All @@ -157,7 +222,7 @@ public function index() {
} else {
$data['payment_gerencianet_client_id_production'] = $this->config->get('payment_gerencianet_client_id_production');
}

if (isset($this->request->post['payment_gerencianet_client_secret_production'])) {
$data['payment_gerencianet_client_secret_production'] = $this->request->post['payment_gerencianet_client_secret_production'];
} else {
Expand All @@ -181,7 +246,7 @@ public function index() {
} else {
$data['payment_gerencianet_new_status_id'] = $this->config->get('payment_gerencianet_new_status_id');
}

if (isset($this->request->post['payment_gerencianet_waiting_status_id'])) {
$data['payment_gerencianet_waiting_status_id'] = $this->request->post['payment_gerencianet_waiting_status_id'];
} else {
Expand Down Expand Up @@ -231,12 +296,12 @@ public function index() {
}

if (isset($this->request->post['payment_gerencianet_discount_billet_value'])) {
$data['payment_gerencianet_discount_billet_value'] = str_replace(",",".",$this->request->post['payment_gerencianet_discount_billet_value']);
$data['payment_gerencianet_discount_billet_value'] = str_replace(",", ".", $this->request->post['payment_gerencianet_discount_billet_value']);
} else {
if ($this->config->get('payment_gerencianet_discount_billet_value')=="") {
if ($this->config->get('payment_gerencianet_discount_billet_value') == "") {
$data['payment_gerencianet_discount_billet_value'] = "";
} else {
$data['payment_gerencianet_discount_billet_value'] = preg_replace( '/[^0-9]/', '', $this->config->get('payment_gerencianet_discount_billet_value')) . '%';
$data['payment_gerencianet_discount_billet_value'] = preg_replace('/[^0-9]/', '', $this->config->get('payment_gerencianet_discount_billet_value')) . '%';
}
}

Expand Down Expand Up @@ -281,7 +346,7 @@ public function index() {
} else {
$data['payment_gerencianet_osc'] = $this->config->get('payment_gerencianet_osc');
}

$this->load->model('localisation/order_status');
$data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();

Expand All @@ -291,4 +356,4 @@ public function index() {
$data['isValidaPHPVersion'] = version_compare(phpversion(), '5.4.0', '>=');
$this->response->setOutput($this->load->view('extension/payment/gerencianet', $data));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$_['gn_config_credentials'] = 'Credenciais';

$_['gn_config_saved'] = 'Suas configurações foram salvas com sucesso. Agora você já pode receber pela Gerencianet!';
$_['gn_config_check_tls'] = 'Identificamos que a sua hospedagem não suporta uma versão segura do TLS(Transport Layer Security) para se comunicar com a Gerencianet. Para conseguir gerar transações, será necessário que contate o administrador do seu servidor e solicite que a hospedagem seja atualizada para suportar co municações por meio do TLS na versão mínima 1.2. Em caso de dúvidas e para maiores informações, contat e a Equi pe Técnica da Gerencia net at ravés do suporte da empresa.';
$_['gn_config_saved_not_on'] = 'Suas configurações foram salvas com sucesso, mas seu módulo ainda não está ativo. Verifique se todos os campos obrigatórios foram preenchidos corretamente:<br>';

$_['gn_entry_sandbox'] = 'Modo';
Expand Down Expand Up @@ -100,5 +101,3 @@
$_['gn_entry_keys_development_help'] = 'Onde eu encontro as chaves de desenvolvimento?';
$_['gn_entry_payee_code_help'] = 'Onde encontrar?';
$_['gn_entry_close'] = 'Fechar';

?>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>
{% endif %}
{% if error_warning %}
<div class="alert alert-danger">
<i class="fa fa-exclamation-circle"></i> {{ error_warning }}
</div>
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> {{ gn_edit_config }}</h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ public function send($method, $route, $body)
$this->auth->authorize();
}

$composerData = json_decode(file_get_contents(__DIR__.'/../../composer.json'), true);
$partner_token = isset($this->options['partner_token'])? $this->options['partner_token'] : "";
$composerData = json_decode(file_get_contents(__DIR__ . '/../../composer.json'), true);
$partner_token = isset($this->options['partner_token']) ? $this->options['partner_token'] : "";

try {
return $this->request->send($method, $route, ['json' => $body,
'headers' => ['Authorization' => 'Bearer '.$this->auth->accessToken, 'api-sdk' => 'opencart-3.1.1', 'partner-token' => $partner_token]]);
return $this->request->send($method, $route, [
'json' => $body,
'headers' => ['Authorization' => 'Bearer ' . $this->auth->accessToken, 'api-sdk' => 'opencart-3.1.2', 'partner-token' => $partner_token]
]);
} catch (AuthorizationException $e) {
$this->auth->authorize();

return $this->request->send($method, $route, ['json' => $body,
'headers' => ['Authorization' => 'Bearer '.$this->auth->accessToken, 'api-sdk' => 'opencart-3.1.1', 'partner-token' => $partner_token]]);
return $this->request->send($method, $route, [
'json' => $body,
'headers' => ['Authorization' => 'Bearer ' . $this->auth->accessToken, 'api-sdk' => 'opencart-3.1.2', 'partner-token' => $partner_token]
]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ class Request
public function __construct(array $options = null)
{
$this->config = Config::options($options);
$composerData = json_decode(file_get_contents(__DIR__.'/../../composer.json'), true);
$partner_token = isset($options['partner_token'])? $options['partner_token'] : "";
$composerData = json_decode(file_get_contents(__DIR__ . '/../../composer.json'), true);
$partner_token = isset($options['partner_token']) ? $options['partner_token'] : "";
$this->client = new Client([
'debug' => $this->config['debug'],
'base_url' => $this->config['baseUri'],
'headers' => [
'Content-Type' => 'application/json',
'api-sdk' => 'opencart-3.1.1',
'partner-token' => $partner_token
],
]);
'debug' => $this->config['debug'],
'base_url' => $this->config['baseUri'],
'headers' => [
'Content-Type' => 'application/json',
'api-sdk' => 'opencart-3.1.2',
'partner-token' => $partner_token
],
]);
}

public function send($method, $route, $requestOptions)
Expand All @@ -41,9 +41,11 @@ public function send($method, $route, $requestOptions)

return json_decode($response->getBody(), true);
} catch (ClientException $e) {
throw new AuthorizationException($e->getResponse()->getStatusCode(),
$e->getResponse()->getReasonPhrase(),
$e->getResponse()->getBody());
throw new AuthorizationException(
$e->getResponse()->getStatusCode(),
$e->getResponse()->getReasonPhrase(),
$e->getResponse()->getBody()
);
} catch (ServerException $se) {
throw new GerencianetException($se->getResponse()->getBody());
}
Expand Down

0 comments on commit 7182800

Please sign in to comment.