master
lucas.taia 2023-02-22 20:04:15 -03:00
parent b24418b6a6
commit adfe63ed56
2 changed files with 76 additions and 175 deletions

View File

@ -33,8 +33,6 @@ import java.util.regex.Pattern;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
import org.apache.http.entity.ContentType;
import org.apache.log4j.Logger;
import org.brazilutils.br.cpfcnpj.Cnpj;
import org.brazilutils.br.cpfcnpj.Cpf;
@ -68,7 +66,6 @@ import org.zkoss.zul.Tab;
import org.zkoss.zul.Tabbox;
import org.zkoss.zul.Textbox;
import com.google.gson.Gson;
import com.rjconsultores.ventaboletos.constantes.ConstantesFuncionSistema;
import com.rjconsultores.ventaboletos.entidad.Categoria;
import com.rjconsultores.ventaboletos.entidad.Ciudad;
@ -95,11 +92,9 @@ import com.rjconsultores.ventaboletos.entidad.Parada;
import com.rjconsultores.ventaboletos.entidad.TipoEventoExtra;
import com.rjconsultores.ventaboletos.enums.TipoCstGratuidade;
import com.rjconsultores.ventaboletos.enums.TipoEmail;
import com.rjconsultores.ventaboletos.enums.TipoEnvioRest;
import com.rjconsultores.ventaboletos.enums.TipoOperacaoECommerce;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.rest.generic.GenericRest;
import com.rjconsultores.ventaboletos.rest.generic.RetornoGenericRest;
import com.rjconsultores.ventaboletos.rest.MercadoPagoService;
import com.rjconsultores.ventaboletos.service.CategoriaService;
import com.rjconsultores.ventaboletos.service.CiudadService;
import com.rjconsultores.ventaboletos.service.EmpresaAdyenConfigService;
@ -122,11 +117,9 @@ import com.rjconsultores.ventaboletos.utilerias.RegistroConDependenciaException;
import com.rjconsultores.ventaboletos.utilerias.SendMail.AuthType;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import com.rjconsultores.ventaboletos.vo.mercadopago.PosVO;
import com.rjconsultores.ventaboletos.vo.mercadopago.RetornoErro;
import com.rjconsultores.ventaboletos.vo.mercadopago.RetornoPosVO;
import com.rjconsultores.ventaboletos.vo.mercadopago.RetornoStoreVO;
import com.rjconsultores.ventaboletos.vo.mercadopago.StoreVO;
import com.rjconsultores.ventaboletos.vo.mercadopago.StoreVO.Location;
import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar;
import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxParada;
import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
@ -1834,10 +1827,26 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
}
public void onClick$btnCadastrarStoreMercadoPago(Event ev) throws InterruptedException {
Object storeVO = cadastrarStoreMercadoPago();
if (storeVO != null && storeVO instanceof StoreVO ) {
RetornoStoreVO retornoStoreVO = retornarStoreMercadoPago();
Object storeVO = MercadoPagoService.getInstance().cadastrarStoreMercadoPago(empresa, txtNomeStore.getValue(),
txtIdStoreMercadoPago.getValue(), txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(),
txtTokenMercadoPago.getValue());
if (storeVO != null && storeVO instanceof StoreVO) {
RetornoStoreVO retornoStoreVO = MercadoPagoService.getInstance().retornarStoreMercadoPago(
txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
boolean processing = true;
while (processing) {
for (StoreVO vo : retornoStoreVO.getResults()) {
if (storeVO.toString().equals(vo.toString())) {
processing = false;
break;
}
}
retornoStoreVO = MercadoPagoService.getInstance().retornarStoreMercadoPago(
txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(),
txtTokenMercadoPago.getValue());
}
lsStoreMercadoPago.clear();
for (StoreVO vo : retornoStoreVO.getResults()) {
lsStoreMercadoPago.add(vo);
@ -1845,7 +1854,10 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
BindingListModel listModel = new BindingListModelList(lsStoreMercadoPago, true);
cmbStoreMercadoPago.setModel(listModel);
cmbStoreCadastroMercadoPago.setModel(listModel);
if (this.storeVO != null) {
cmbStoreMercadoPago.setSelectedIndex(lsStoreMercadoPago.indexOf(this.storeVO));
}
Messagebox.show("Store cadastrada com sucesso", Labels.getLabel("editarEmpresaController.window.title"),
Messagebox.OK, Messagebox.INFORMATION);
} else {
@ -1856,16 +1868,40 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
}
public void onClick$btnCadastrarPOSMercadoPago(Event ev) throws InterruptedException {
Object posVO = cadastrarPOSMercadoPago();
Object posVO = MercadoPagoService.getInstance().cadastrarPOSMercadoPago(txtNomePOS.getValue(),
cmbStoreCadastroMercadoPago.getSelectedItem() != null
? (StoreVO) cmbStoreCadastroMercadoPago.getSelectedItem().getValue()
: null,
txtIdPOSMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
if (posVO != null && posVO instanceof PosVO) {
RetornoPosVO retornoPosVO = retornarPosMercadoPago();
RetornoPosVO retornoPosVO = MercadoPagoService.getInstance()
.retornarPosMercadoPago(txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
boolean processing = true;
while (processing) {
for (PosVO vo : retornoPosVO.getResults()) {
if (posVO.toString().equals(vo.toString())) {
processing = false;
break;
}
}
retornoPosVO = MercadoPagoService.getInstance().retornarPosMercadoPago(txtUrlApiMercadoPago.getValue(),
txtTokenMercadoPago.getValue());
}
lsPosMercadoPago.clear();
for (PosVO vo : retornoPosVO.getResults()) {
lsPosMercadoPago.add(vo);
}
BindingListModel listModel = new BindingListModelList(lsPosMercadoPago, true);
cmbPOSMercadoPago.setModel(listModel);
if (this.posVO != null) {
cmbPOSMercadoPago.setSelectedIndex(lsPosMercadoPago.indexOf(this.posVO));
}
Messagebox.show("POS cadastrado com sucesso", Labels.getLabel("editarEmpresaController.window.title"),
Messagebox.OK, Messagebox.INFORMATION);
} else {
@ -1881,16 +1917,18 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
lsStoreMercadoPago = new ArrayList<StoreVO>();
lsPosMercadoPago = new ArrayList<PosVO>();
RetornoStoreVO retornoStoreVO = retornarStoreMercadoPago();
RetornoStoreVO retornoStoreVO = MercadoPagoService.getInstance().retornarStoreMercadoPago(
txtUserIdMercadoPago.getValue(), txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
for (StoreVO vo : retornoStoreVO.getResults()) {
if ( store != null && vo.toString().equals(store)) {
if (store != null && vo.toString().equals(store)) {
this.storeVO = vo;
}
lsStoreMercadoPago.add(vo);
}
RetornoPosVO retornoPosVO = retornarPosMercadoPago();
RetornoPosVO retornoPosVO = MercadoPagoService.getInstance()
.retornarPosMercadoPago(txtUrlApiMercadoPago.getValue(), txtTokenMercadoPago.getValue());
for (PosVO vo : retornoPosVO.getResults()) {
if (pos != null && vo.toString().equals(pos)) {
this.posVO = vo;
@ -1899,146 +1937,6 @@ public void onClick$btnTestEmailFlexBus(Event ev) throws InterruptedException {
}
}
private Object cadastrarStoreMercadoPago() {
try {
StoreVO consulta = new StoreVO();
consulta.setName(txtNomeStore.getValue());
consulta.setExternal_id(txtIdStoreMercadoPago.getValue());
Location item = new Location();
item.setStreet_number(empresa.getNumero());
item.setStreet_name(empresa.getLogradouro());
item.setCity_name(StringUtils.capitalize(empresa.getCidade().getNombciudad().toLowerCase()));
item.setState_name(StringUtils.capitalize(empresa.getCidade().getEstado().getNombestado().toLowerCase()) );
item.setLatitude(empresa.getLatitude());
item.setLongitude(empresa.getLongitude());
item.setReference(empresa.getComplemento());
consulta.setLocation(item);
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization",
"Bearer " + txtTokenMercadoPago.getValue());
headers.put("Accept", "application/json");
String userId = txtUserIdMercadoPago.getValue();
RetornoGenericRest<?> resposta = GenericRest.getInstance().fazerChamada(
txtUrlApiMercadoPago.getValue() + "/users/" + userId + "/stores",
TipoEnvioRest.POST, new Gson().toJson(consulta).toString(), ContentType.APPLICATION_JSON,
headers, StoreVO.class, Object.class);
if (resposta != null && (resposta.getStatusResposta().equals(HttpStatus.SC_OK)
|| resposta.getStatusResposta().equals(HttpStatus.SC_CREATED))) {
return (StoreVO) resposta.getConteudo();
} else {
return resposta.getConteudoErro();
}
} catch (Exception e) {
log.error("erro ao enviar requisicao ", e);
}
return null;
}
private Object cadastrarPOSMercadoPago() {
try {
PosVO consulta = new PosVO();
consulta.setName(txtNomePOS.getValue());
consulta.setFixed_amount(false);
if (cmbStoreCadastroMercadoPago.getSelectedItem() != null) {
StoreVO storeVO = (StoreVO) cmbStoreCadastroMercadoPago.getSelectedItem().getValue();
consulta.setStore_id(storeVO.getId());
consulta.setExternal_store_id(storeVO.getExternal_id());
}
consulta.setExternal_id(txtIdPOSMercadoPago.getValue());
consulta.setCategory(5611203);
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization",
"Bearer " + txtTokenMercadoPago.getValue());
headers.put("Accept", "application/json");
RetornoGenericRest<?> resposta = GenericRest.getInstance().fazerChamada(
txtUrlApiMercadoPago.getValue() + "/pos",
TipoEnvioRest.POST, new Gson().toJson(consulta).toString(), ContentType.APPLICATION_JSON,
headers, PosVO.class, RetornoErro.class);
if (resposta != null && (resposta.getStatusResposta().equals(HttpStatus.SC_OK)
|| resposta.getStatusResposta().equals(HttpStatus.SC_CREATED))) {
return (PosVO) resposta.getConteudo();
} else {
return resposta.getConteudoErro();
}
} catch (Exception e) {
log.error("erro ao enviar requisicao ", e);
}
return null;
}
private RetornoStoreVO retornarStoreMercadoPago() {
try {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization",
"Bearer " + txtTokenMercadoPago.getValue());
headers.put("Accept", "application/json");
String userId = txtUserIdMercadoPago.getValue();
RetornoGenericRest<?> resposta = GenericRest.getInstance().fazerChamada(
txtUrlApiMercadoPago.getValue() + "/users/" + userId + "/stores/search",
TipoEnvioRest.GET, null, ContentType.APPLICATION_JSON,
headers, RetornoStoreVO.class, RetornoErro.class);
if (resposta != null && (resposta.getStatusResposta().equals(HttpStatus.SC_OK)
|| resposta.getStatusResposta().equals(HttpStatus.SC_CREATED))) {
return (RetornoStoreVO) resposta.getConteudo();
}
} catch (Exception e) {
log.error("erro ao enviar requisicao ", e);
}
return null;
}
private RetornoPosVO retornarPosMercadoPago() {
try {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization",
"Bearer " + txtTokenMercadoPago.getValue());
headers.put("Accept", "application/json");
RetornoGenericRest<?> resposta = GenericRest.getInstance().fazerChamada(
txtUrlApiMercadoPago.getValue() + "/pos",
TipoEnvioRest.GET, null, ContentType.APPLICATION_JSON,
headers, RetornoPosVO.class, RetornoErro.class);
if (resposta != null && (resposta.getStatusResposta().equals(HttpStatus.SC_OK)
|| resposta.getStatusResposta().equals(HttpStatus.SC_CREATED))) {
return (RetornoPosVO) resposta.getConteudo();
}
} catch (Exception e) {
log.error("erro ao enviar requisicao ", e);
}
return null;
}
public Combobox getCmbEstadoInscEstadual() {
return cmbEstadoInscEstadual;
}

View File

@ -63,7 +63,7 @@
<tab id="tabAdyen"
label="${c:l('editarEmpresaController.lblAdyen.value')}" />
<tab id="tabMercadoPago"
label="Mercado Pago" />
label="${c:l('editarEmpresaController.lblMercadoPago.value')}" />
</tabs>
@ -2270,8 +2270,8 @@
<tabbox>
<tabs>
<tab label="Geral" />
<tab label="Cadastro" />
<tab label="${c:l('editarEmpresaController.lblTabGeralMercadoPago.value')}" />
<tab label="${c:l('editarEmpresaController.lblTabCadastroMercadoPago.value')}" />
</tabs>
<tabpanels>
@ -2286,28 +2286,28 @@
<row>
<label
value="User ID" />
value="${c:l('editarEmpresaController.lblUserIdMercadoPago.value')}" />
<textbox id="txtUserIdMercadoPago" width="80%" maxlength="255"
value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.userId}" />
</row>
<row>
<label
value="Token" />
value="${c:l('editarEmpresaController.lblUserIdMercadoPago.value')}" />
<textbox id="txtTokenMercadoPago" width="80%" maxlength="255"
value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.token}" />
</row>
<row>
<label
value="Url API" />
value="${c:l('editarEmpresaController.lblUrlApiMercadoPago.value')}" />
<textbox id="txtUrlApiMercadoPago" width="80%" maxlength="255"
value="@{winEditarEmpresa$composer.empresaMercadoPagoConfig.urlApi}" />
</row>
<row>
<label
value="Store" />
value="${c:l('editarEmpresaController.lblStoreMercadoPago.value')}" />
<combobox id="cmbStoreMercadoPago"
width="90%" mold="rounded"
buttonVisible="true"
@ -2318,7 +2318,7 @@
<row>
<label
value="POS" />
value="${c:l('editarEmpresaController.lblPOSMercadoPago.value')}" />
<combobox id="cmbPOSMercadoPago"
width="90%" mold="rounded"
buttonVisible="true"
@ -2348,19 +2348,20 @@
<row>
<label
value="Nome" />
value="${c:l('editarEmpresaController.lblStoreNomeMercadoPago.value')}" />
<textbox id="txtNomeStore" width="80%" maxlength="255" />
</row>
<row>
<label
value="ID Externo" />
value="${c:l('editarEmpresaController.lblIdExternoMercadoPago.value')}" />
<textbox id="txtIdStoreMercadoPago" width="80%" maxlength="255" />
</row>
</rows>
</grid>
<button id="btnCadastrarStoreMercadoPago" height="20" label="Cadastrar Store" />
<button id="btnCadastrarStoreMercadoPago" height="20"
label="${c:l('editarEmpresaController.lblBtnCadastrarStoreMercadoPago.value')}" />
<toolbar>
<separator bar="true"/>
POS
@ -2375,27 +2376,29 @@
<row>
<label
value="Nome" />
value="${c:l('editarEmpresaController.lblPOSNomeMercadoPago.value')}" />
<textbox id="txtNomePOS" width="80%" maxlength="255" />
</row>
<row>
<label
value="ID Externo" />
value="${c:l('editarEmpresaController.lblIdExternoMercadoPago.value')}" />
<textbox id="txtIdPOSMercadoPago" width="80%" maxlength="255" />
</row>
<row>
<label
value="Store" />
value="${c:l('editarEmpresaController.lblStoreMercadoPago.value')}" />
<combobox id="cmbStoreCadastroMercadoPago"
width="90%" mold="rounded"
buttonVisible="true"
use="com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar"/>
use="com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEstandar"
model="@{winEditarEmpresa$composer.lsStoreMercadoPago}"/>
</row>
</rows>
</grid>
<button id="btnCadastrarPOSMercadoPago" height="20" label="Cadastrar POS" />
<button id="btnCadastrarPOSMercadoPago" height="20"
label="${c:l('editarEmpresaController.lblBtnCadastrarPOSMercadoPago.value')}" />
</tabpanel>
</tabpanels>
</tabbox>